Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
c3f78902
Commit
c3f78902
authored
Jan 13, 2015
by
Shrhawk
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6285 from Shrhawk/shr/bug/TNL-904-tolerance-is-broken
Fix tolerance broken
parents
e57f3e3b
66b949b7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletions
+25
-1
common/lib/capa/capa/tests/test_util.py
+9
-0
common/lib/capa/capa/util.py
+16
-1
No files found.
common/lib/capa/capa/tests/test_util.py
View file @
c3f78902
...
...
@@ -81,6 +81,15 @@ 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
):
"""
...
...
common/lib/capa/capa/util.py
View file @
c3f78902
...
...
@@ -5,6 +5,7 @@ import bleach
from
calc
import
evaluator
from
cmath
import
isinf
from
decimal
import
Decimal
#-----------------------------------------------------------------------------
#
# Utility functions used in CAPA responsetypes
...
...
@@ -67,7 +68,21 @@ 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()).
return
abs
(
student_complex
-
instructor_complex
)
<=
tolerance
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
def
contextualize_text
(
text
,
context
):
# private
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment