Forum: Ruby on Rails Test Failure: <0.01> expected but was <0.01>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pat M. (Guest)
on 2006-03-22 09:53
(Received via mailing list)
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
Simon P. (Guest)
on 2006-03-22 10:06
(Received via mailing list)
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
> removed_email_address@domain.invalid
> 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
François B. (Guest)
on 2006-03-22 15:34
(Received via mailing list)
2006/3/22, Pat M. <removed_email_address@domain.invalid>:
> 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 !
This topic is locked and can not be replied to.