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): ...@@ -93,6 +93,19 @@ class RulesTestCase(unittest.TestCase):
raise 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): def assertValidateSuccess(self, a, b):
self.assertEqual(validate(a, b), VALIDATE_SUCCESS, self.assertEqual(validate(a, b), VALIDATE_SUCCESS,
'Validation failed: %s !=> %s' % (a, b)) 'Validation failed: %s !=> %s' % (a, b))
......
...@@ -66,7 +66,6 @@ class TestLeidenOefenopgave(TestCase): ...@@ -66,7 +66,6 @@ class TestLeidenOefenopgave(TestCase):
]) ])
def test_1_3(self): def test_1_3(self):
# (x+1)^2 -> x^2 + 2x + 1
self.assertRewrite([ self.assertRewrite([
'(x + 1) ^ 2', '(x + 1) ^ 2',
'(x + 1)(x + 1)', '(x + 1)(x + 1)',
...@@ -81,7 +80,6 @@ class TestLeidenOefenopgave(TestCase): ...@@ -81,7 +80,6 @@ class TestLeidenOefenopgave(TestCase):
]) ])
def test_1_4(self): def test_1_4(self):
# (x-1)^2 -> x^2 - 2x + 1
self.assertRewrite([ self.assertRewrite([
'(x - 1) ^ 2', '(x - 1) ^ 2',
'(x - 1)(x - 1)', '(x - 1)(x - 1)',
...@@ -221,8 +219,5 @@ class TestLeidenOefenopgave(TestCase): ...@@ -221,8 +219,5 @@ class TestLeidenOefenopgave(TestCase):
# '21 / x^3', # '21 / x^3',
# ]) # ])
#def test_4_7(self): def test_4_7(self):
# self.assertRewrite([ self.assertEvaluates('1 / x + 2 / (x + 1)', '(3x + 1) / (x(x + 1))')
# '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