Beispiel #1
0
    def test_read_priority_of_operations(self):
        ast = self.parse('4a^2')

        self.assertEqual(
            ast,
            Multiplication(Constant('4'),
                           Exponentiation(Variable('a'), Constant('2'))))
Beispiel #2
0
 def test_read_sqrt(self):
     ast = self.parse('\\sqrt{2x + 3}')
     self.assertEqual(
         ast,
         Function(
             Func.SQRT,
             Addition(Multiplication(Constant('2'), Variable('x')),
                      Constant('3'))))
Beispiel #3
0
 def test_read_atom_without_times(self):
     ast = self.parse(r'3! (2 + 1) 4^n')
     self.assertEqual(
         ast,
         Multiplication(
             Multiplication(Function(Func.FACTORIAL, Constant('3')),
                            Addition(Constant('2'), Constant('1'))),
             Exponentiation(Constant('4'), Variable('n'))))
Beispiel #4
0
 def test_read_alternative_sin(self):
     ast = self.parse('sin(2x + 3)')
     self.assertEqual(
         ast,
         Function(
             Func.SIN,
             Addition(Multiplication(Constant('2'), Variable('x')),
                      Constant('3'))))
Beispiel #5
0
 def test_read_complex_exponent(self):
     ast = self.parse('x^{2y + 3}')
     self.assertEqual(
         ast,
         Exponentiation(
             Variable('x'),
             Addition(Multiplication(Constant('2'), Variable('y')),
                      Constant('3'))))
Beispiel #6
0
    def test_read_mixed(self):
        ast = self.parse('3x')
        self.assertEqual(ast, Multiplication(Constant('3'), Variable('x')))

        ast = self.parse('3xy')
        self.assertEqual(
            ast,
            Multiplication(Multiplication(Constant('3'), Variable('x')),
                           Variable('y')))
Beispiel #7
0
 def test_read_priority_of_operations_two(self):
     ast = self.parse(r'\frac{1}{1 - 2^{1-s}}')
     one = Constant('1')
     self.assertEqual(
         ast,
         Division(
             one,
             Subtraction(
                 one,
                 Exponentiation(Constant('2'),
                                Subtraction(one, Variable('s'))))))
Beispiel #8
0
    def test_read_factorial(self):
        ast = self.parse('x!')
        self.assertEqual(ast, Function(Func.FACTORIAL, Variable('x')))

        ast = self.parse('3!')
        self.assertEqual(ast, Function(Func.FACTORIAL, Constant('3')))

        ast = self.parse('(2 * x)!')
        self.assertEqual(
            ast,
            Function(Func.FACTORIAL,
                     Multiplication(Constant('2'), Variable('x'))))

        ast = self.parse('4 * x!')
        self.assertEqual(
            ast,
            Multiplication(Constant('4'),
                           Function(Func.FACTORIAL, Variable('x'))))
Beispiel #9
0
 def test_read_mixed_with_frac(self):
     ast = self.parse(r'\frac{1}{2} * \frac{3}{4} * \frac{5}{6}')
     self.assertEqual(
         ast,
         Multiplication(
             Multiplication(Division(Constant('1'), Constant('2')),
                            Division(Constant('3'), Constant('4'))),
             Division(Constant('5'), Constant('6'))))
Beispiel #10
0
 def test_read_addition_of_constants(self):
     ast = self.parse('3 + 2')
     self.assertEqual(ast, Addition(Constant('3'), Constant('2')))
Beispiel #11
0
 def test_read_substraction_of_constant_and_variable(self):
     ast = self.parse('n-1')
     self.assertEqual(ast, Subtraction(Variable('n'), Constant('1')))
Beispiel #12
0
 def test_read_subtraction_of_multiple_constants(self):
     ast = self.parse('3 - 2 - 5')
     self.assertEqual(ast, Subtraction(Subtraction(Constant('3'), Constant('2')), Constant('5')))
Beispiel #13
0
 def test_read_addition_of_constant_and_variable(self):
     ast = self.parse('n+1')
     self.assertEqual(ast, Addition(Variable('n'), Constant('1')))
Beispiel #14
0
    def test_read_addition_of_multiple_constants(self):
        ast = self.parse('3 + 2 + 5')
        self.assertEqual(ast, Addition(Addition(Constant('3'), Constant('2')), Constant('5')))

        ast = self.parse('3+2+5')
        self.assertEqual(ast, Addition(Addition(Constant('3'), Constant('2')), Constant('5')))
Beispiel #15
0
 def test_read_division_of_multiple_constants(self):
     ast = self.parse('3 / 2 / 5')
     self.assertEqual(
         ast, Division(Division(Constant('3'), Constant('2')),
                       Constant('5')))
Beispiel #16
0
 def test_read_mixed_without_times_frac(self):
     ast = self.parse(r'\frac{1}{4} \frac{x}{2}')
     self.assertEqual(
         ast,
         Multiplication(Division(Constant('1'), Constant('4')),
                        Division(Variable('x'), Constant('2'))))
Beispiel #17
0
 def test_read_multiplication_of_constants(self):
     ast = self.parse('3 * 2')
     self.assertEqual(ast, Multiplication(Constant('3'), Constant('2')))
Beispiel #18
0
 def test_read_mixed_operations_of_constants(self):
     ast = self.parse('3 * 2 / 4 * 5')
     self.assertEqual(
         ast,
         Division(Multiplication(Constant('3'), Constant('2')),
                  Multiplication(Constant('4'), Constant('5'))))
Beispiel #19
0
 def test_read_normal_exponent(self):
     ast = self.parse('x^{2}')
     self.assertEqual(ast, Exponentiation(Variable('x'), Constant('2')))
Beispiel #20
0
 def test_read_absolute(self):
     ast = self.parse('|x + 3|')
     self.assertEqual(
         ast, Function(Func.ABS, Addition(Variable('x'), Constant('3'))))