Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

<NaN> returned for my Junit test case

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the complete code for my class and my test class. I've highlighted the problem areas and described the problem below.



Start of test class:


I'm working on a lab for school but blueJ is telling me that my surrenderValue is returning "NaN" (which I know is Not a Number). I believe the issue is with the objects I am trying to use in the calculation in my WholeLifePolicy class's surrenderVal method. Any help asap would be greatly appreciated.


 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this constructor:



What you want to do is put the values of the parameters into the member variables. Is that what those three assignments are doing? Or are they maybe doing exactly the opposite?

Or to put it another way, dividing by 0 gives a NaN. If policyYrs were to remain zero after this constructor, then the value you're testing would be NaN. Are you sure policyYrs is not zero?
 
Stephen Shaw
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!

You were right, I had them reversed. I would have never noticed if it wasn't for you, thanks. I'll be keeping this place bookmarked from now on. I can see how much you guys will help my learning.
 
Marshal
Posts: 69847
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

More precisely, you get NaN if you divide 0 by 0, but it only works in floating-point arithmetic. In floating point, if you divide anything else by 0 you get (±)∞, and in integer arithmetic you get an Exception if you divide by 0.
    Bookmark Topic Watch Topic
  • New Topic