From: Alex Chaffee Date: 2012-01-25T04:05:47+09:00 Subject: Re: Microrant on Ruy's Math Skills --20cf3056427d99047204b74ad591 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable "Standard is better than better." -Anon. Also, you don't need a "to_f" to reproduce this -- just enter "0.5 - 0.4 - 0.1" into any Ruby, Python or JavaScript interpreter -- or a C or Java program, for that matter -- to get a perfectly consistent, and consistently surprising, very very small negative number that is not *quite* zero. So how to test around this in unit tests? In RSpec, use be_within (n=E9e be_close) [1]; in Wrong (which works inside many test frameworks), use close_to? [2] - A [1] https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/t= emperature/temperature_spec.rb [2] https://github.com/sconover/wrong/blob/master/lib/wrong/close_to.rb -- Alex Chaffee - alex@stinky.com http://alexchaffee.com http://twitter.com/alexch --20cf3056427d99047204b74ad591--