Esempio n. 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))])
Esempio n. 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))])
Esempio n. 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))])
Esempio n. 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))
        ])
Esempio n. 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))])
Esempio n. 6
0
 def test_match_reduce_sqrt_constant(self):
     root = tree('sqrt(4)')
     self.assertEqualPos(match_reduce_sqrt(root),
             [P(root, constant_sqrt, (2,))])
Esempio n. 7
0
 def test_match_reduce_sqrt_quadrant(self):
     root = tree('sqrt(a ^ 2)')
     self.assertEqualPos(match_reduce_sqrt(root), [P(root, quadrant_sqrt)])
Esempio n. 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), [])
Esempio n. 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))
     ])
Esempio n. 10
0
 def test_match_reduce_sqrt_constant(self):
     root = tree('sqrt(4)')
     self.assertEqualPos(match_reduce_sqrt(root),
                         [P(root, constant_sqrt, (2, ))])
Esempio n. 11
0
 def test_match_reduce_sqrt_quadrant(self):
     root = tree('sqrt(a ^ 2)')
     self.assertEqualPos(match_reduce_sqrt(root), [P(root, quadrant_sqrt)])
Esempio n. 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), [])