Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

still new to testing, how do I test this method:

 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys, I have a method that looks like this:


I am trying to figure out the best way to run a test for it, any ideas? I am considering haveing a text file that I read with some strings and doubles in the text, would that be a good way to do it? Any other ways?
Thanks in advance, Dan
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with

?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lasse Koskela:
What's wrong with

?

That is, except that one of the assertions fails
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse, nothing is wrong with that, I was just wondering if there was anything special about testing strings and doubles. Also if I could get a loop in there it would be helpfull too Well I guess there is nothing special about this case then.

I also ran accross another problem I'm sure you can help me with. I can't get assertEquals() to work with doubles that are variable i.e.

how can I get that to work?
Thanks for your help!
[ July 02, 2004: Message edited by: dan maples ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also if I could get a loop in there it would be helpfull too

Sure you can. Using the suite() method:


I can't get assertEquals() to work with doubles that are variable i.e.
how can I get that to work?

There is no assertEquals(double expected, double actual) but there is an assertEquals(double expected, double actual, double delta). See my earlier example of how you typically use it.
[ July 02, 2004: Message edited by: Lasse Koskela ]
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, you've been more than helpfull, but just one last thing I'm a little unsure about is:
assertEquals(double expected, double actual, double delta).

what is delta?
Thanks again-Dan
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"delta" is the acceptable deviation of the actual result from the expected result (double and float are approximations!). Typically the value for delta is something like 0.0000001d or 0.0000000001d or some other very small number...
 
Dan Maples
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much, you've been so helpful, I really appreciate it.
-Dan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic