Пример #1
0
    def test_basic_on_exp(self):
        expressions = [('4', L(4)),
                       ('3+4', L(3) + L(4)), ('3-4', L(3) + -L(4)),
                       ('3/4', L(3) / L(4)), ('-4', -L(4)),
                       ('3^4', N('^', L(3), L(4))), ('(2)', L(2))]

        run_expressions(Parser, expressions)
Пример #2
0
    def test_infinity(self):
        expressions = [('2^3000', N('^', L(2), L(3000))),
                       ('2^-3000', N('^', L(2), -L(3000)))]
        #               ('2^99999999999', None),
        #               ('2^-99999999999', 0.0)]

        run_expressions(Parser, expressions)
Пример #3
0
    def test_infinity(self):
        expressions = [('2^3000',  N('^', L(2), L(3000))),
                       ('2^-3000', N('^', L(2), -L(3000)))]
        #               ('2^99999999999', None),
        #               ('2^-99999999999', 0.0)]

        run_expressions(Parser, expressions)
Пример #4
0
 def test_diagnostic_test_parser(self):
     run_expressions(Parser, [
         ('6*5^2', L(6) * L(5) ** 2),
         ('-5*(-3)^2', -(L(5) * (-L(3)) ** 2)),
         ('7p-3p', L(7) * 'p' + -(L(3) * 'p')),
         ('-5a*-6', -(L(5) * 'a' * -L(6))),
         ('3a-8--5-2a', L(3) * 'a' + -L(8) + --(L(5)) + -(L(2) * 'a')),
         ])
Пример #5
0
 def test_diagnostic_test_parser(self):
     run_expressions(Parser, [
         ('6*5^2', L(6) * L(5)**2),
         ('-5*(-3)^2', -(L(5) * (-L(3))**2)),
         ('7p-3p', L(7) * 'p' + -(L(3) * 'p')),
         ('-5a*-6', -(L(5) * 'a' * -L(6))),
         ('3a-8--5-2a', L(3) * 'a' + -L(8) + --(L(5)) + -(L(2) * 'a')),
     ])
Пример #6
0
    def test_basic_on_exp(self):
        expressions = [('4', L(4)),
                       ('3+4', L(3) + L(4)),
                       ('3-4', L(3) + -L(4)),
                       ('3/4', L(3) / L(4)),
                       ('-4', -L(4)),
                       ('3^4', N('^', L(3), L(4))),
                       ('(2)', L(2))]

        run_expressions(Parser, expressions)
Пример #7
0
    def test_concat_easy(self):
        expressions = [
            ('xy', N('*', L('x'), L('y'))),
            ('2x', N('*', L(2), L('x'))),
            ('x4', N('*', L('x'), L(4))),
            ('3 4', N('*', L(3), L(4))),
            ('(x)4', N('*', L('x'), L(4))),
            ('(3+4)2', N('*', N('+', L(3), L(4)), L(2))),
        ]

        run_expressions(Parser, expressions)
Пример #8
0
    def test_concat_easy(self):
        expressions = [
                       ('xy',     N('*', L('x'), L('y'))),
                       ('2x',     N('*', L(2), L('x'))),
                       ('x4',     N('*', L('x'), L(4))),
                       ('3 4',    N('*', L(3), L(4))),
                       ('(x)4',   N('*', L('x'), L(4))),
                       ('(3+4)2', N('*', N('+', L(3), L(4)), L(2))),
                      ]

        run_expressions(Parser, expressions)
Пример #9
0
    def test_pow_nested(self):
        # a^b^c = a^(b^c) != (a^b)^c

        a, b, c, d, e = L('a'), L('b'), L('c'), L('d'), L('e')

        expressions = [
            ('a^b^c', N('^', a, N('^', b, c))),
            ('-1^b^c', -N('^', L(1), N('^', b, c))),
            ('ab^c', N('*', a, N('^', b, c))),
            ('a(b)^c', N('*', a, N('^', b, c))),
            ('a(b+c)^(d+e)', N('*', a, N('^', N('+', b, c), N('+', d, e)))),
            ('(a(b+c))^(d+e)', N('^', N('*', a, N('+', b, c)), N('+', d, e))),
        ]

        run_expressions(Parser, expressions)
Пример #10
0
    def test_concat_intermediate(self):
        expressions = [
            ('(3+4)(5+7)', N('*', N('+', L(3), L(4)), N('+', L(5), L(7)))),
            ('(a+b)(c+d)',
             N('*', N('+', L('a'), L('b')), N('+', L('c'), L('d')))),
            ('a+b(c+d)', N('+', L('a'), N('*', L('b'), N('+', L('c'),
                                                         L('d'))))),
            ('abcd', N('*', N('*', N('*', L('a'), L('b')), L('c')), L('d'))),
            ('ab(c)d', N('*', N('*', N('*', L('a'), L('b')), L('c')), L('d'))),
            ('ab*(c)*d', N('*', N('*', N('*', L('a'), L('b')), L('c')),
                           L('d'))),
            ('ab*(c)^d', N('*', N('*', L('a'), L('b')), N('^', L('c'),
                                                          L('d')))),
        ]

        run_expressions(Parser, expressions)
Пример #11
0
    def test_pow_nested(self):
        # a^b^c = a^(b^c) != (a^b)^c

        a, b, c, d, e = L('a'), L('b'), L('c'), L('d'), L('e')

        expressions = [
                       ('a^b^c', N('^', a, N('^', b, c))),
                       ('-1^b^c', -N('^', L(1), N('^', b, c))),
                       ('ab^c', N('*', a, N('^', b, c))),
                       ('a(b)^c', N('*', a, N('^', b, c))),
                       ('a(b+c)^(d+e)', N('*', a, N('^', N('+', b, c),
                                                  N('+', d, e)))),
                       ('(a(b+c))^(d+e)', N('^', N('*', a, N('+', b, c)),
                                            N('+', d, e))),
                      ]

        run_expressions(Parser, expressions)
Пример #12
0
    def test_concat_intermediate(self):
        expressions = [
                       ('(3+4)(5+7)', N('*', N('+', L(3), L(4)),
                                             N('+', L(5), L(7)))),
                       ('(a+b)(c+d)', N('*', N('+', L('a'), L('b')),
                                             N('+', L('c'), L('d')))),
                       ('a+b(c+d)', N('+', L('a'), N('*', L('b'),
                                             N('+', L('c'), L('d'))))),
                       ('abcd', N('*', N('*', N('*', L('a'), L('b')),
                                           L('c')), L('d'))),
                       ('ab(c)d', N('*', N('*', N('*', L('a'), L('b')),
                                           L('c')), L('d'))),
                       ('ab*(c)*d', N('*', N('*', N('*', L('a'), L('b')),
                                           L('c')), L('d'))),
                       ('ab*(c)^d', N('*', N('*', L('a'), L('b')),
                                           N('^', L('c'), L('d')))),
                      ]

        run_expressions(Parser, expressions)
Пример #13
0
 def test_diagnostic_test(self):
     run_expressions(Parser, [
         ('5(a-2b)', L(5) * (L('a') + -(L(2) * 'b'))),
         ('-(3a+6b)', -(L(3) * L('a') + L(6) * 'b')),
         ('18-(a-12)', L(18) + -(L('a') + -L(12))),
         ('-p-q+5(p-q)-3q-2(p-q)',
             -L('p') + -L('q') + L(5) * (L('p') + -L('q')) + -(L(3) * 'q') \
             + -(L(2) * (L('p') + -L('q')))
         ),
         ('(2+3/7)^4',
             N('^', N('+', L(2), N('/', L(3), L(7))), L(4))
         ),
         ('x^3*x^2*x',
             N('*',
               N('*',
                 N('^', L('x'), L(3)),
                 N('^', L('x'), L(2))),
               L('x')
             )
         ),
         ('-x^3*-2x^5',
             -(L('x') ** L(3) * -L(2) * L('x') ** L(5))
         ),
         ('(7x^2y^3)^2/(7x^2y^3)',
             N('/',
               N('^',
                 N('*',
                   N('*', L(7), N('^', L('x'), L(2))),
                   N('^', L('y'), L(3))
                 ),
                 L(2)),
               N('*',
                 N('*', L(7), N('^', L('x'), L(2))),
                 N('^', L('y'), L(3))
               )
             )
         ),
         ])
Пример #14
0
 def test_diagnostic_test(self):
     run_expressions(Parser, [
         ('5(a-2b)', L(5) * (L('a') + -(L(2) * 'b'))),
         ('-(3a+6b)', -(L(3) * L('a') + L(6) * 'b')),
         ('18-(a-12)', L(18) + -(L('a') + -L(12))),
         ('-p-q+5(p-q)-3q-2(p-q)',
             -L('p') + -L('q') + L(5) * (L('p') + -L('q')) + -(L(3) * 'q') \
             + -(L(2) * (L('p') + -L('q')))
         ),
         ('(2+3/7)^4',
             N('^', N('+', L(2), N('/', L(3), L(7))), L(4))
         ),
         ('x^3*x^2*x',
             N('*',
               N('*',
                 N('^', L('x'), L(3)),
                 N('^', L('x'), L(2))),
               L('x')
             )
         ),
         ('-x^3*-2x^5',
             -(L('x') ** L(3) * -L(2) * L('x') ** L(5))
         ),
         ('(7x^2y^3)^2/(7x^2y^3)',
             N('/',
               N('^',
                 N('*',
                   N('*', L(7), N('^', L('x'), L(2))),
                   N('^', L('y'), L(3))
                 ),
                 L(2)),
               N('*',
                 N('*', L(7), N('^', L('x'), L(2))),
                 N('^', L('y'), L(3))
               )
             )
         ),
         ])
Пример #15
0
 def test_negation(self):
     run_expressions(Parser, [
         ('-9', -L(9)),
         ('--9', --L(9)),
         ('a--9', L('a') + -(-L(9))),
     ])
Пример #16
0
 def test_negation(self):
     run_expressions(Parser, [
         ('-9', -L(9)),
         ('--9', --L(9)),
         ('a--9', L('a') + -(-L(9))),
         ])
Пример #17
0
 def test_identifiers(self):
     run_expressions(Parser, [('a', Leaf('a'))])