From 4a76a629f67b600abd3ffb569cbe1237df41122c Mon Sep 17 00:00:00 2001 From: Adam Palay Date: Wed, 28 Jan 2015 10:21:01 -0500 Subject: [PATCH] Revert "Fix tolerance broken" This reverts commit 66b949b745b45b3a25ff32fdd23423ecaaff712c. --- common/lib/capa/capa/tests/test_util.py | 9 --------- common/lib/capa/capa/util.py | 17 +---------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/common/lib/capa/capa/tests/test_util.py b/common/lib/capa/capa/tests/test_util.py index ecb6ea02c9..f6b76e1c9e 100644 --- a/common/lib/capa/capa/tests/test_util.py +++ b/common/lib/capa/capa/tests/test_util.py @@ -81,15 +81,6 @@ class UtilTest(unittest.TestCase): self.assertFalse(result) result = compare_with_tolerance(infinity, infinity, '1.0', False) self.assertTrue(result) - # Test absolute tolerance for smaller values - result = compare_with_tolerance(100.01, 100.0, 0.01, False) - self.assertTrue(result) - result = compare_with_tolerance(100.001, 100.0, 0.001, False) - self.assertTrue(result) - result = compare_with_tolerance(100.01, 100.0, '0.01%', False) - self.assertTrue(result) - result = compare_with_tolerance(100.002, 100.0, 0.001, False) - self.assertFalse(result) def test_sanitize_html(self): """ diff --git a/common/lib/capa/capa/util.py b/common/lib/capa/capa/util.py index ccbebd2a4b..e9197ad19e 100644 --- a/common/lib/capa/capa/util.py +++ b/common/lib/capa/capa/util.py @@ -5,7 +5,6 @@ import bleach from calc import evaluator from cmath import isinf -from decimal import Decimal #----------------------------------------------------------------------------- # # Utility functions used in CAPA responsetypes @@ -68,21 +67,7 @@ def compare_with_tolerance(student_complex, instructor_complex, tolerance=defaul else: # v1 and v2 are, in general, complex numbers: # there are some notes about backward compatibility issue: see responsetypes.get_staff_ans()). - decimal_places = None - # count the "decimal_places" for "student_complex". e.g, for - # "student_complex" value "152.3667" the "decimal_places" will be - # 4 as there are 4 digits "3667" after decimal - if isinstance(student_complex, float): - decimal_places = Decimal(str(student_complex)).as_tuple().exponent * -1 # pylint: disable=E1103 - - abs_value = abs(student_complex - instructor_complex) - - # decimal_places could be NaN in some cases - if decimal_places and isinstance(decimal_places, int): - # abs_value contains 17 digits exponent value so - # round it up to "decimal_places" - abs_value = round(abs_value, decimal_places) - return abs_value <= tolerance + return abs(student_complex - instructor_complex) <= tolerance def contextualize_text(text, context): # private