This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with

?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you so much, you've been so helpful, I really appreciate it.
-Dan
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic