File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes <NaN> returned for my Junit test case Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "<NaN> returned for my Junit test case" Watch "<NaN> returned for my Junit test case" New topic
Author

<NaN> returned for my Junit test case

Stephen Shaw
Greenhorn

Joined: Oct 24, 2010
Posts: 2
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.


Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24040
    
  13

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?


[Jess in Action][AskingGoodQuestions]
Stephen Shaw
Greenhorn

Joined: Oct 24, 2010
Posts: 2
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: <NaN> returned for my Junit test case
 
Similar Threads
having trouble with a fraction program
Reverse Int, char, double
Javaprepare Question
Help with error in running program
JUnit Test Cases