def test_add_operator(self): class Power(Operator): sign = '^' def calculate(self, first_number, second_number): return first_number ** second_number parser = Parser() parser.add_operator(Power()) parser.open('2 + 2 - 2 * 2 / 2 ^ 2') parser.read() self.assertEqual(parser.compute(), 4)
def compute_2(self): parser = Parser() parser.open('+ 2.11 - 2.32 * 200') self.assertRaises(AttributeError, parser.read, ())
def compute_1(self): parser = Parser() parser.open('-1111112 + 2.11 - 2.32 * 200') parser.read() self.assertEqual(parser.compute(), -1111573.89)