|
|
@@ -21,21 +21,17 @@ class TestRulesNumerics(RulesTestCase):
|
|
|
[P(root, add_numerics, (Scope(root), l1, l2))])
|
|
|
|
|
|
def test_add_numerics(self):
|
|
|
- l0, a, l1 = tree('1,a,2')
|
|
|
+ l1, l2 = root = tree('1 + 2')
|
|
|
+ self.assertEqual(add_numerics(root, (Scope(root), l1, l2)), 3)
|
|
|
|
|
|
- root = l0 + l1
|
|
|
- self.assertEqual(add_numerics(root, (Scope(root), l0, l1)), 3)
|
|
|
- root = l0 + a + l1
|
|
|
- self.assertEqual(add_numerics(root, (Scope(root), l0, l1)), L(3) + a)
|
|
|
+ (l1, a), l2 = root = tree('1 + a + 2')
|
|
|
+ self.assertEqual(add_numerics(root, (Scope(root), l1, l2)), L(3) + a)
|
|
|
|
|
|
def test_add_numerics_negations(self):
|
|
|
- l1, a, l2 = tree('1,a,2')
|
|
|
- ml1, ml2 = -l1, -l2
|
|
|
-
|
|
|
- r = ml1 + l2
|
|
|
- self.assertEqual(add_numerics(r, (Scope(r), ml1, l2)), 1)
|
|
|
- r = l1 + ml2
|
|
|
- self.assertEqual(add_numerics(r, (Scope(r), l1, ml2)), -1)
|
|
|
+ ml1, l2 = root = tree('-1 + 2')
|
|
|
+ self.assertEqual(add_numerics(root, (Scope(root), ml1, l2)), 1)
|
|
|
+ l1, ml2 = root = tree('1 - 2')
|
|
|
+ self.assertEqual(add_numerics(root, (Scope(root), l1, ml2)), -1)
|
|
|
|
|
|
def test_match_divide_numerics(self):
|
|
|
a, b, i2, i3, i4, i6, f1, f2, f3 = tree('a,b,2,3,4,6,1.0,2.0,3.0')
|
|
|
@@ -127,16 +123,16 @@ class TestRulesNumerics(RulesTestCase):
|
|
|
def test_multiply_numerics(self):
|
|
|
a, b, i2, i3, i6, f2, f3, f6 = tree('a,b,2,3,6,2.0,3.0,6.0')
|
|
|
|
|
|
- root = i3 * i2
|
|
|
+ i3, i2 = root = tree('3 * 2')
|
|
|
self.assertEqual(multiply_numerics(root, (Scope(root), i3, i2)), 6)
|
|
|
- root = f3 * i2
|
|
|
+ f3, i2 = root = tree('3.0 * 2')
|
|
|
self.assertEqual(multiply_numerics(root, (Scope(root), f3, i2)), 6.0)
|
|
|
- root = i3 * f2
|
|
|
+ i3, f2 = root = tree('3 * 2.0')
|
|
|
self.assertEqual(multiply_numerics(root, (Scope(root), i3, f2)), 6.0)
|
|
|
- root = f3 * f2
|
|
|
+ f3, f2 = root = tree('3.0 * 2.0')
|
|
|
self.assertEqual(multiply_numerics(root, (Scope(root), f3, f2)), 6.0)
|
|
|
|
|
|
- root = a * i3 * i2 * b
|
|
|
+ ((a, i3), i2), b = root = tree('a * 3 * 2 * b')
|
|
|
self.assertEqualNodes(multiply_numerics(root,
|
|
|
(Scope(root), i3, i2)), a * 6 * b)
|
|
|
|