Test Failure: <0.01> expected but was <0.01>

I have two database fields, and then I have a method which shows the
difference. It’s simply

def ev_diff
ev_push - ev_fold
end

The value of ev_push is 0.26, value of ev_fold is 0.05, so the diff is
obviously 0.01. I have an assertion written as:

assert_equal 0.01, stats.ev_diff

Which fails…but I have no clue why. The failure message follow:

  1. Failure:
    test_calc_stats(HandStatsTest) [test/unit/hand_stats_test.rb:54]:
    <0.01> expected but was
    <0.01>.

That makes absolutely no sense to me. It expects 0.01 and gets 0.01,
but somehow fails? What’s up with that?

Pat

Hi,

To assert float values, you should use:

assert_in_delta expected_float, actual_float, delta

Look at Test::Unit rdocumentation for details. Hope this helps.

Simon

Pat M. wrote:

assert_equal 0.01, stats.ev_diff

Pat


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Simon PASQUIER
Quiconnect http://www.quiconnect.com
Tel: +33 4 56 58 61 02
Skype Name: simonpasquier
This message may contain privileged or confidential information

2006/3/22, Pat M. [email protected]:

Which fails…but I have no clue why. The failure message follow:

  1. Failure:
    test_calc_stats(HandStatsTest) [test/unit/hand_stats_test.rb:54]:
    <0.01> expected but was
    <0.01>.

That makes absolutely no sense to me. It expects 0.01 and gets 0.01,
but somehow fails? What’s up with that?

Another option is to test the String value of each:

assert_equal ‘0.01’, stats.ev_diff.to_s

Hope that helps !