Exemplo n.º 1
0
 def test_UDV(self):
     """
     Don't allow silly UDV input
     :return:
     """
     with self.assertRaises(UserWarning):
         calc.handle_user_defined_input("2 = 8")
Exemplo n.º 2
0
 def test_UDV(self):
     """
     Don't allow silly UDV input
     :return:
     """
     with self.assertRaises(UserWarning):
         calc.handle_user_defined_input("2 = 8")
Exemplo n.º 3
0
 def test_UDF(self):
     """
     Make sure errors are handled in UDF
     :return:
     """
     with self.assertRaises(SyntaxWarning):
         calc.handle_user_defined_input("bob = 4")
         calc.calculate("bob2 + 4")
Exemplo n.º 4
0
 def test_UDF(self):
     """
     Make sure errors are handled in UDF
     :return:
     """
     with self.assertRaises(SyntaxWarning):
         calc.handle_user_defined_input("bob = 4")
         calc.calculate("bob2 + 4")
Exemplo n.º 5
0
 def test_operator_errors(self):
     """
     More operator errors
     :return:
     """
     with self.assertRaises(SyntaxWarning):
         calc.calculate("2 + * 4")
         calc.calculate("2 ! 4")
         calc.handle_user_defined_input("matt = 4 = 5")
Exemplo n.º 6
0
 def test_operator_errors(self):
     """
     More operator errors
     :return:
     """
     with self.assertRaises(SyntaxWarning):
         calc.calculate("2 + * 4")
         calc.calculate("2 ! 4")
         calc.handle_user_defined_input("matt = 4 = 5")
Exemplo n.º 7
0
 def test_math(self):
     """
     Simple unit tests
     :return:
     """
     self.assertAlmostEqual(calc.calculate("4 * 10 / 15 + ( 6 - 2 * 3 )"), 2.6666666, 3)
     self.assertEqual(calc.calculate("2 +5/1 + (2* 5)/2"), 12)
     self.assertAlmostEqual(calc.calculate("7^2+16 / (4^4)"), 49.0625, 3)
     self.assertEqual(calc.calculate("(1+2)+(2+3)"), 8)
     self.assertEqual(calc.calculate("1+ ( ( ( 3 + 2) * 2) - 4)"), 7)
     self.assertAlmostEqual(calc.calculate("pi*2"), 6.2831, 3)
     self.assertEqual(calc.calculate("(2*.5)^3"), 1)
     calc.handle_user_defined_input("Matt = 20")
     self.assertAlmostEqual(calc.calculate("Matt * pi"), 62.8318, 3)
Exemplo n.º 8
0
 def test_math(self):
     """
     Simple unit tests
     :return:
     """
     self.assertAlmostEqual(calc.calculate("4 * 10 / 15 + ( 6 - 2 * 3 )"),
                            2.6666666, 3)
     self.assertEqual(calc.calculate("2 +5/1 + (2* 5)/2"), 12)
     self.assertAlmostEqual(calc.calculate("7^2+16 / (4^4)"), 49.0625, 3)
     self.assertEqual(calc.calculate("(1+2)+(2+3)"), 8)
     self.assertEqual(calc.calculate("1+ ( ( ( 3 + 2) * 2) - 4)"), 7)
     self.assertAlmostEqual(calc.calculate("pi*2"), 6.2831, 3)
     self.assertEqual(calc.calculate("(2*.5)^3"), 1)
     calc.handle_user_defined_input("Matt = 20")
     self.assertAlmostEqual(calc.calculate("Matt * pi"), 62.8318, 3)
Exemplo n.º 9
0
def take_input():
    '''
    Grabs user input split into a list
    :return: List if ready for math or None to skip math
    '''
    equation = ""
    while not equation.strip():
        equation = input()
    if equation.lower() == "done":
        exit(0)
    elif "=" in equation: #Handle User defined variables (and possibly functions) separately
        print(calc.handle_user_defined_input(equation))
        return None
    return equation
Exemplo n.º 10
0
def take_input():
    '''
    Grabs user input split into a list
    :return: List if ready for math or None to skip math
    '''
    equation = ""
    while not equation.strip():
        equation = input()
    if equation.lower() == "done":
        exit(0)
    elif "=" in equation:  #Handle User defined variables (and possibly functions) separately
        print(calc.handle_user_defined_input(equation))
        return None
    return equation