Example #1
0
    def test_match_reduce_sqrt_dividers(self):
        root = tree('sqrt(8)')
        self.assertEqualPos(match_reduce_sqrt(root),
                [P(root, split_dividers, (4, 2))])

        root = tree('sqrt(27)')
        self.assertEqualPos(match_reduce_sqrt(root),
                [P(root, split_dividers, (9, 3))])
Example #2
0
    def test_match_reduce_sqrt_dividers(self):
        root = tree('sqrt(8)')
        self.assertEqualPos(match_reduce_sqrt(root),
                            [P(root, split_dividers, (4, 2))])

        root = tree('sqrt(27)')
        self.assertEqualPos(match_reduce_sqrt(root),
                            [P(root, split_dividers, (9, 3))])
Example #3
0
    def test_match_reduce_sqrt_mult(self):
        ((l2, x),) = root = tree('sqrt(2x)')
        self.assertEqualPos(match_reduce_sqrt(root),
                [P(root, extract_sqrt_multiplicant, (Scope(root[0]), l2)),
                 P(root, extract_sqrt_multiplicant, (Scope(root[0]), x))])

        (((l2, x), y),) = root = tree('sqrt(2xy)')
        self.assertEqualPos(match_reduce_sqrt(root),
                [P(root, extract_sqrt_multiplicant, (Scope(root[0]), l2)),
                 P(root, extract_sqrt_multiplicant, (Scope(root[0]), x)),
                 P(root, extract_sqrt_multiplicant, (Scope(root[0]), y))])
Example #4
0
    def test_match_reduce_sqrt_mult(self):
        ((l2, x), ) = root = tree('sqrt(2x)')
        self.assertEqualPos(match_reduce_sqrt(root), [
            P(root, extract_sqrt_multiplicant, (Scope(root[0]), l2)),
            P(root, extract_sqrt_multiplicant, (Scope(root[0]), x))
        ])

        (((l2, x), y), ) = root = tree('sqrt(2xy)')
        self.assertEqualPos(match_reduce_sqrt(root), [
            P(root, extract_sqrt_multiplicant, (Scope(root[0]), l2)),
            P(root, extract_sqrt_multiplicant, (Scope(root[0]), x)),
            P(root, extract_sqrt_multiplicant, (Scope(root[0]), y))
        ])
Example #5
0
 def test_match_reduce_sqrt_mult_priority(self):
     root = tree('sqrt(9 * 3)')
     self.assertEqualPos(match_reduce_sqrt(root),
             [P(root, extract_sqrt_mult_priority, (Scope(root[0]), 9)),
              P(root, extract_sqrt_multiplicant, (Scope(root[0]), 3))])
Example #6
0
 def test_match_reduce_sqrt_constant(self):
     root = tree('sqrt(4)')
     self.assertEqualPos(match_reduce_sqrt(root),
             [P(root, constant_sqrt, (2,))])
Example #7
0
 def test_match_reduce_sqrt_quadrant(self):
     root = tree('sqrt(a ^ 2)')
     self.assertEqualPos(match_reduce_sqrt(root), [P(root, quadrant_sqrt)])
Example #8
0
    def test_match_reduce_sqrt_none(self):
        root = tree('sqrt(a)')
        self.assertEqualPos(match_reduce_sqrt(root), [])

        root = tree('sqrt(-4)')
        self.assertEqualPos(match_reduce_sqrt(root), [])
Example #9
0
 def test_match_reduce_sqrt_mult_priority(self):
     root = tree('sqrt(9 * 3)')
     self.assertEqualPos(match_reduce_sqrt(root), [
         P(root, extract_sqrt_mult_priority, (Scope(root[0]), 9)),
         P(root, extract_sqrt_multiplicant, (Scope(root[0]), 3))
     ])
Example #10
0
 def test_match_reduce_sqrt_constant(self):
     root = tree('sqrt(4)')
     self.assertEqualPos(match_reduce_sqrt(root),
                         [P(root, constant_sqrt, (2, ))])
Example #11
0
 def test_match_reduce_sqrt_quadrant(self):
     root = tree('sqrt(a ^ 2)')
     self.assertEqualPos(match_reduce_sqrt(root), [P(root, quadrant_sqrt)])
Example #12
0
    def test_match_reduce_sqrt_none(self):
        root = tree('sqrt(a)')
        self.assertEqualPos(match_reduce_sqrt(root), [])

        root = tree('sqrt(-4)')
        self.assertEqualPos(match_reduce_sqrt(root), [])