From: Ben Waugh Date: Wed, 10 Apr 2013 21:19:42 +0000 (+0100) Subject: Add example floating point testing to cheat sheet. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dc241dcc3aca56009a6cec59f21622a94f03050b;p=swc-testing-nose.git Add example floating point testing to cheat sheet. --- diff --git a/testing/cheat-sheet.md b/testing/cheat-sheet.md index 3047fca..f792447 100644 --- a/testing/cheat-sheet.md +++ b/testing/cheat-sheet.md @@ -72,7 +72,17 @@ Nose provides a range of assertions that can be used when a test is not just che ### Floating point tests -* assert_almost_equal... +When comparing floating-point numbers for equality, allow some tolerance for small differences due to +the way values are represented and rounded. + + from nose.tools import assert_almost_equal + + from mycode import hypotenuse + + def test_hypotenuse_345(): + observed = hypotenuse(3.0, 4.0) + expected = 5.0 + assert_almost_equal(observed, expected) ### Fixtures