From b7aafa203619e575106efca21ff451f7de791a8f Mon Sep 17 00:00:00 2001 From: cgohlke Date: Sun, 29 Dec 2013 20:05:55 -0800 Subject: [PATCH] Add assert_almost_equal() for testing float numbers --- Tests/tester.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/tester.py b/Tests/tester.py index 5f322cc20..7252b5b47 100644 --- a/Tests/tester.py +++ b/Tests/tester.py @@ -67,6 +67,12 @@ def assert_equal(a, b, msg=None): else: failure(msg or "got %r, expected %r" % (a, b)) +def assert_almost_equal(a, b, msg=None, eps=1e-6): + if abs(a-b) < eps: + success() + else: + failure(msg or "got %r, expected %r" % (a, b)) + def assert_deep_equal(a, b, msg=None): try: if len(a) == len(b):