From dc241dcc3aca56009a6cec59f21622a94f03050b Mon Sep 17 00:00:00 2001 From: Ben Waugh Date: Wed, 10 Apr 2013 22:19:42 +0100 Subject: [PATCH] Add example floating point testing to cheat sheet. --- testing/cheat-sheet.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 -- 2.26.2