Ejemplo n.º 1
0
 def test_complex_operator(self):
     self.assertEqual(['5', 'neg', 'x', '*', 'sin'],
                      get_infix_notation('sin(-5x)'))
     self.assertEqual(['x', '3', '^', 'arctan'],
                      get_infix_notation('arctan(x^3)'))
     self.assertEqual(['10', 'lg', '3', 'neg', '^', 'ln'],
                      get_infix_notation('ln(lg(10)^(-3))'))
Ejemplo n.º 2
0
 def test_binary_operators(self):
     self.assertEqual(['3', '5', '+'], get_infix_notation('3+5'))
     self.assertEqual(['343', '53', '^'], get_infix_notation('343^53'))
     self.assertEqual(['45', '3', '2', '^', '^'],
                      get_infix_notation('45^3^2'))
     self.assertEqual(
         ['x', 'y', '*', 'z', '*', '45', 'y', '2', '^', '*', 'z', '*', '+'],
         get_infix_notation('xyz+45y2z'))
Ejemplo n.º 3
0
 def test_operations_with_constants(self):
     self.assertEqual(['pi', 'x', '*'], get_infix_notation('pix'))
     self.assertEqual(['1', 'pi', '3', '*', '+'],
                      get_infix_notation('1+pi*3'))
     self.assertEqual(['pi', 'neg', 't', '*', 'y', '*'],
                      get_infix_notation('-pity'))
     self.assertEqual(['pi', 'pi', '1', '+', '^', '44', 'pi', '*', '-'],
                      get_infix_notation('pi^(pi+1)-44pi'))
     self.assertEqual(['pi', 'pi', '*', 'i', '*', 'p', '*'],
                      get_infix_notation('pipiip'))
Ejemplo n.º 4
0
 def test_unary_operators_error(self):
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('-')
     with self.assertRaises(TwoOperatorsAtTimeError):
         get_infix_notation('--2')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('arcsin')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('sin')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('cos')
Ejemplo n.º 5
0
 def test_unary_operators(self):
     self.assertEqual(['5'], get_infix_notation('5'))
     self.assertEqual(['5'], get_infix_notation('((5))'))
     self.assertEqual(['5', 'neg'], get_infix_notation('-5'))
     self.assertEqual(['5', 'pos'], get_infix_notation('+5'))
     self.assertEqual(['x', 'ln'], get_infix_notation('ln(x)'))
     self.assertEqual(['x', 'lg'], get_infix_notation('lg(x)'))
     self.assertEqual(['x', 'cos'], get_infix_notation('cos(x)'))
     self.assertEqual(['x', 'arctan'], get_infix_notation('arctan(x)'))
     self.assertEqual(['x', 'sin'], get_infix_notation('sin(x)'))
Ejemplo n.º 6
0
 def test_complex_operator_errors(self):
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('arcsin(-)')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('sin(sin())')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('x+()')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('cos(x/(()))+5')
Ejemplo n.º 7
0
 def test_combined_operators(self):
     self.assertEqual(['5', 'neg', '32', '3', '^', '*'],
                      get_infix_notation('-5*32^3'))
     self.assertEqual(['5', '2', '^', 'x', '+', 'ln', 'y', 'sin', '*'],
                      get_infix_notation('ln(5^2+x)sin(y)'))
     self.assertEqual(
         ['1', 'x', '20', '^', '20', 'x', '6', '^', '*', '-', '/', 'lg'],
         get_infix_notation('lg(1/(x^20-20x^6))'))
     self.assertEqual(
         ['x', 'y', '3', '^', '*', '6', '+', 'tan', 'neg', 'sin', 'neg'],
         get_infix_notation('-sin(-tan(xy3+6))'))
     self.assertEqual(['x', 'y', '+', 'z', '*', '32', '*'],
                      get_infix_notation('(x+y)z(32)'))
     self.assertEqual(['z', '3', '+', 'sin'],
                      get_infix_notation('sin(((z)+3))'))
     self.assertEqual(['x', 'neg', 'sin'],
                      get_infix_notation('sin(-((x)))'))
Ejemplo n.º 8
0
 def test_binary_operators_error(self):
     with self.assertRaises(TwoOperatorsAtTimeError):
         get_infix_notation('23--2')
     with self.assertRaises(TwoOperatorsAtTimeError):
         get_infix_notation('123*-3')
     with self.assertRaises(ExtraBracketsError):
         get_infix_notation('(3+5))')
     with self.assertRaises(ExtraBracketsError):
         get_infix_notation('3*((2/2)')
     with self.assertRaises(ExtraBracketsError):
         get_infix_notation('sin(x')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('x+')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('/5')
     with self.assertRaises(NotEnoughArgumentsError):
         get_infix_notation('x*3+')
Ejemplo n.º 9
0
 def test_irrelevant_symbol_error(self):
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('3+5=')
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('3/7*(3~4)')
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('4!')
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('4^[2+3]')
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('1 3x')
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('1 +  3.  2x')
     with self.assertRaises(IrrelevantSymbolError):
         get_infix_notation('132 123')