aspose file tools*
The moose likes Testing and the fly likes assertEquals(double expected,double actual,double delta) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "assertEquals(double expected,double actual,double delta)" Watch "assertEquals(double expected,double actual,double delta)" New topic
Author

assertEquals(double expected,double actual,double delta)

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i read the javadoc but still cant understand the @param order.
inside my jUnit test, i've this:

and tests ok; but if i change param's order, goes ok again:

I just dont get it...
Can someone pls explain me why this looks like beeing the same?
thanks in advance


java amateur
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Do you understand what the third parameter is doing?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i guess is suposed to control precision - decimal roundups, and similar
[ January 21, 2005: Message edited by: miguel lisboa ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Yes.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
ok, but i return to my original Q:
why on earth is it possible that i interchange expected, obtained with DELTA first or at the end and obtain the same result?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
assertEquals proofs that

abs(expected - actual) <= delta

In your example, when

abs(expected - actual) <= 0

it follows that

expected == actual

from that follows that

expected <= actual

and therefore

abs(expected) <= actual

therefore

abs(-expected) <= actual

therefore

abs(0 - expected) <= actual

which is exactly what your latter line of code is asserting. From that follows that when the first line succeeds, the second have to, too.

Notice that the reverse is *not* true - even when the first is failing, the second still can succeed! (Bonus points if you can explain why that is the case, using the above steps... )
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
Notice that the reverse is *not* true - even when the first is failing, the second still can succeed!

whenever expected < actual, with delta = 0
As to the bonus, i think you deserve it for your great explanation
thanks a lot
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by miguel lisboa:
As to the bonus, i think you deserve it for your great explanation


I guess my half-finished mathematics study shows through...

thanks a lot


You're very welcome!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: assertEquals(double expected,double actual,double delta)