I have the following assert_equal in my unit test: assert_equal 65000.0, do_calc And get this Failure message back: <65000.0> expected but was <65000.0>. How can that be ??? Has anybody seen this before? Thanks Joerg -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
if do_calc does floating-point math, there''s a chance that you have floating-point errors. its neither your code nor ruby, but a problem with floating points and binary representation in general, since there are some numbers that cant be presented in binary, they are just rounded to be approx. the right value. for more info on that, google is your friend, since i dont really know how to explain that in english :) 2006/9/12, Joerg Diekmann <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > I have the following assert_equal in my unit test: > > assert_equal 65000.0, do_calc > > And get this Failure message back: > > <65000.0> expected but was > <65000.0>. > > > How can that be ??? Has anybody seen this before? > > Thanks > Joerg > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Michael Siebert <info-norLuBQQNv0t+8dGM1inlw@public.gmane.org> www.siebert-wd.de - Gedanken lesen www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 12 Sep 2006, at 11:21, Joerg Diekmann wrote:> > I have the following assert_equal in my unit test: > > assert_equal 65000.0, do_calc > > And get this Failure message back: > > <65000.0> expected but was > <65000.0>. > > > How can that be ??? Has anybody seen this before?You''re working with floats, which you can''t reliably compare with ==. Check out assert_in_delta instead. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---