Merge pull request #1558 from MITx/fix/will/symmath_check_unit_tests
Added additional unit tests for symmath library that verify symmath_check for simple symbolic input strings.
This commit is contained in:
@@ -325,53 +325,3 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
|
||||
msg += '<hr>'
|
||||
|
||||
return {'ok': False, 'msg': msg, 'ex': fexpect, 'got': fsym}
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# tests
|
||||
|
||||
|
||||
def sctest1():
|
||||
x = "1/2*(1+(k_e* Q* q)/(m *g *h^2))"
|
||||
y = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mfrac>
|
||||
<mn>1</mn>
|
||||
<mn>2</mn>
|
||||
</mfrac>
|
||||
<mrow>
|
||||
<mo>(</mo>
|
||||
<mn>1</mn>
|
||||
<mo>+</mo>
|
||||
<mfrac>
|
||||
<mrow>
|
||||
<msub>
|
||||
<mi>k</mi>
|
||||
<mi>e</mi>
|
||||
</msub>
|
||||
<mo>⋅</mo>
|
||||
<mi>Q</mi>
|
||||
<mo>⋅</mo>
|
||||
<mi>q</mi>
|
||||
</mrow>
|
||||
<mrow>
|
||||
<mi>m</mi>
|
||||
<mo>⋅</mo>
|
||||
<mrow>
|
||||
<mi>g</mi>
|
||||
<mo>⋅</mo>
|
||||
</mrow>
|
||||
<msup>
|
||||
<mi>h</mi>
|
||||
<mn>2</mn>
|
||||
</msup>
|
||||
</mrow>
|
||||
</mfrac>
|
||||
<mo>)</mo>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>
|
||||
'''.strip()
|
||||
z = "1/2(1+(k_e* Q* q)/(m *g *h^2))"
|
||||
r = sympy_check2(x, z, {'a': z, 'a_fromjs': y}, 'a')
|
||||
return r
|
||||
|
||||
@@ -10,6 +10,64 @@ class SymmathCheckTest(TestCase):
|
||||
number_list = [i + 0.01 for i in range(-100, 100)]
|
||||
self._symmath_check_numbers(number_list)
|
||||
|
||||
def test_symmath_check_same_symbols(self):
|
||||
expected_str = "x+2*y"
|
||||
dynamath = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mn>2</mn>
|
||||
<mo>*</mo>
|
||||
<mi>y</mi>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>'''.strip()
|
||||
|
||||
# Expect that the exact same symbolic string is marked correct
|
||||
result = symmath_check(expected_str, expected_str, dynamath=[dynamath])
|
||||
self.assertTrue('ok' in result and result['ok'])
|
||||
|
||||
def test_symmath_check_equivalent_symbols(self):
|
||||
expected_str = "x+2*y"
|
||||
input_str = "x+y+y"
|
||||
dynamath = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mi>y</mi>
|
||||
<mo>+</mo>
|
||||
<mi>y</mi>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>'''.strip()
|
||||
|
||||
# Expect that equivalent symbolic strings are marked correct
|
||||
result = symmath_check(expected_str, input_str, dynamath=[dynamath])
|
||||
self.assertTrue('ok' in result and result['ok'])
|
||||
|
||||
def test_symmath_check_different_symbols(self):
|
||||
expected_str = "0"
|
||||
input_str = "x+y"
|
||||
dynamath = '''
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML">
|
||||
<mstyle displaystyle="true">
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mi>y</mi>
|
||||
</mrow>
|
||||
</mstyle>
|
||||
</math>'''.strip()
|
||||
|
||||
# Expect that an incorrect response is marked incorrect
|
||||
result = symmath_check(expected_str, input_str, dynamath=[dynamath])
|
||||
self.assertTrue('ok' in result and not result['ok'])
|
||||
self.assertFalse('fail' in result['msg'])
|
||||
|
||||
def _symmath_check_numbers(self, number_list):
|
||||
|
||||
for n in number_list:
|
||||
|
||||
Reference in New Issue
Block a user