• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assertEquals(double expected,double actual,double delta)

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you understand what the third parameter is doing?
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess is suposed to control precision - decimal roundups, and similar
[ January 21, 2005: Message edited by: miguel lisboa ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic