Commit 4a76a629 by Adam Palay Committed by AlasdairSwan

Revert "Fix tolerance broken"

This reverts commit 66b949b7.
parent e600d6e3
......@@ -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):
"""
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment