예제 #1
0
 def test_reversed_polish_notation(self):
     expect = [
         '3', '5', '2', '2', '^', '*', '3', '1', '-', '/', '+', 'abs', '-2',
         ')', '-', 'pow', '1', '1', '+', ',', '1', '2', '*', '1', '+', ')',
         '+'
     ]
     actual = calc.to_postfix('3+5*2^2/(3-1)-abs(-2)+pow(1+1, 1*2+1)')
     self.assertEqual(expect, actual)
예제 #2
0
 def test_modulo_by_zero(self):
     with self.assertRaises(calc.CalcError):
         calc.calc_iteration(calc.to_postfix('3 % 0'), None)
예제 #3
0
 def test_modulus(self):
     expect = 7
     actual = calc.calc_iteration(calc.to_postfix('29%11'), None)
     self.assertEqual(expect, actual)
예제 #4
0
 def test_division_by_zero(self):
     with self.assertRaises(calc.CalcError):
         calc.calc_iteration(calc.to_postfix('3 / 0'), None)
예제 #5
0
 def test_division(self):
     expect = 6
     actual = calc.calc_iteration(calc.to_postfix('24/4'), None)
     self.assertEqual(expect, actual)
예제 #6
0
 def test_multiplication(self):
     expect = 5
     actual = calc.calc_iteration(calc.to_postfix('2.5*2'), None)
     self.assertEqual(expect, actual)
예제 #7
0
 def test_subtraction(self):
     expect = 3
     actual = calc.calc_iteration(calc.to_postfix('25-22'), None)
     self.assertEqual(expect, actual)
예제 #8
0
 def test_addition(self):
     expect = 8.05
     actual = calc.calc_iteration(calc.to_postfix('3.5+.5+2.75+1.3'), None)
     self.assertEqual(expect, actual)
예제 #9
0
 def test_comparison(self):
     expect = True
     actual = calc.calc_iteration(calc.to_postfix('2+3*5>=10+12/2'), None)
     self.assertEqual(expect, actual)
예제 #10
0
 def test_invalid_input(self):
     with self.assertRaises(calc.CalcError):
         calc.to_postfix('2+3+sin(45)+pov(2, 6)')
         calc.to_postfix('1+2*3-4@')
         calc.to_postfix('1-#/2')
         calc.to_postfix('3*6>>5+7')
         calc.to_postfix('./7+2')
         calc.to_postfix('.7*(sin())')
         calc.to_postfix('23+3+')
         calc.to_postfix('abs(-)')
         calc.correct_expression('')
         calc.correct_expression('-')
예제 #11
0
 def test_invalid_operators(self):
     with self.assertRaises(calc.CalcError):
         calc.to_postfix('1+2-*6-3')
         calc.to_postfix('cos(*+30)/2+3')
예제 #12
0
 def test_invalid_brackets(self):
     with self.assertRaises(calc.CalcError):
         calc.correct_expression('sin()+3')
         calc.to_postfix('sin30(5-1)')
         calc.to_postfix('(')
         calc.to_postfix('1+2/3+5)-6')
예제 #13
0
 def test_abs(self):
     expect = 6
     actual = calc.calc_iteration(calc.to_postfix('abs(-6)'), None)
     self.assertEqual(expect, actual)
예제 #14
0
 def test_round(self):
     expect = 8
     actual = calc.calc_iteration(calc.to_postfix('round(7.51)'), None)
     self.assertEqual(expect, actual)
예제 #15
0
 def test_power(self):
     expect = 8
     actual = calc.calc_iteration(calc.to_postfix('2^3'), None)
     self.assertEqual(expect, actual)
예제 #16
0
 def test_floor_division(self):
     expect = 4
     actual = calc.calc_iteration(calc.to_postfix('9//2'), None)
     self.assertEqual(expect, actual)