From: Farrel Lifson Date: 2008-08-27T18:03:45+09:00 Subject: Re: unit testing with class and floats 2008/8/27 Adam Akhtar : > sorry a (simplified) example > > def simpleclass > attr_accessor :big_num #its a float!!! > end > > expected = simpleclass.new(105.234) > > assert_equal(expected, somefunction(blahblah)) > > i expect somefunction to return a class with 105.234 > > in the summary it shows that the function does in fact do that but it > still fails it. When comparing floats there is a chance that although the floats might be represented the same on screen there might be differences in their storage. For instance 1.0 and 1.0000001 might look the same on the screen but will not be the same if compared with ==. You should rather use assert_in_delta when comparing two floats. Farrel -- Aimred - Ruby Development and Consulting http://www.aimred.com