• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Junit assertEquals

 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The assertEquals method that tests the equality of doubles takes a third parameter (double delta). What is this parameter for and is there a specific value that I should use. I had done some testing with the method and been able to make unequal doubles test as equal.
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since rounding errors can accumulate over many calculations, JUnit allows a tolerance factor, or delta. This parameter allows you to control to what degree two doubles can vary but still be considered equal for your application. Experiment with different values for the three parameters to see the effect of changing delta. For example:
assertEquals(1.0, 1.01, 0.0);
assertEquals(1.0, 1.01, 0.01);
...
HTH,
Craig
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Craig. That explains some of the results that I was seeing when I experimented with it.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So how did you choose the Jakarta forum for this question?
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Weitzman:
So how did you choose the Jakarta forum for this question?


Good question. JUnit has been discussed in the forum before. The Other Java Products and Servers forum would probably be a more appropriate place for it so I am going to move it there.
reply
    Bookmark Topic Watch Topic
  • New Topic