Commit 015cd97f authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added 'assertEvaluates' method for unit testing.

parent fa97ae38
......@@ -93,6 +93,19 @@ class RulesTestCase(unittest.TestCase):
raise
def assertEvaluates(self, exp, result):
node = tree(exp)
while node:
s = str(node)
if s == result:
return True
node = rewrite(s)
raise AssertionError('`%s` does not rewrite to `%s`' % (exp, result))
def assertValidateSuccess(self, a, b):
self.assertEqual(validate(a, b), VALIDATE_SUCCESS,
'Validation failed: %s !=> %s' % (a, b))
......
......@@ -66,7 +66,6 @@ class TestLeidenOefenopgave(TestCase):
])
def test_1_3(self):
# (x+1)^2 -> x^2 + 2x + 1
self.assertRewrite([
'(x + 1) ^ 2',
'(x + 1)(x + 1)',
......@@ -81,7 +80,6 @@ class TestLeidenOefenopgave(TestCase):
])
def test_1_4(self):
# (x-1)^2 -> x^2 - 2x + 1
self.assertRewrite([
'(x - 1) ^ 2',
'(x - 1)(x - 1)',
......@@ -221,8 +219,5 @@ class TestLeidenOefenopgave(TestCase):
# '21 / x^3',
# ])
#def test_4_7(self):
# self.assertRewrite([
# '1 / x + 2 / (x + 1)',
# '(3x + 1) / (x * (x + 1))',
# ])
def test_4_7(self):
self.assertEvaluates('1 / x + 2 / (x + 1)', '(3x + 1) / (x(x + 1))')
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