def test_03(self): with self.assertRaises(Exception): self.assertEqual(evaluate(parse("True True"))) with self.assertRaises(Exception): self.assertEqual(evaluate(parse("True False"))) with self.assertRaises(Exception): self.assertEqual(evaluate(parse("False True"))) with self.assertRaises(Exception): self.assertEqual(evaluate(parse("False False")))
def test_three_tokens_eval(self): t = Token() t.id = "*" t.first = Token() t.first.id = Types.NUMBER t.first.value = 21 t.second = Token() t.second.id = Types.NUMBER t.second.value = 2 self.assertEqual(evaluate(t), 42)
def test_three_tokens_eval(self): t = Token() t.id = "+" t.first = Token() t.first.id = Types.NUMBER t.first.value = 10 t.second = Token() t.second.id = "*" t.second.first = Token() t.second.first.id = Types.NUMBER t.second.first.value = 5 t.second.second = Token() t.second.second.id = Types.NUMBER t.second.second.value = 4 self.assertEqual(evaluate(t), 30)
def test_empty_program(self): with self.assertRaises(Exception): t = Token() evaluate(t)
def test_06(self): self.assertEqual(evaluate(parse("True or True")), True) self.assertEqual(evaluate(parse("True or False")), True) self.assertEqual(evaluate(parse("False or True")), True) self.assertEqual(evaluate(parse("False or False")), False)
def test_05(self): self.assertEqual(evaluate(parse("True and True")), True) self.assertEqual(evaluate(parse("True and False")), False) self.assertEqual(evaluate(parse("False and True")), False) self.assertEqual(evaluate(parse("False and False")), False)
def test_04(self): self.assertEqual(evaluate(parse("not True")), False) self.assertEqual(evaluate(parse("not False")), True)
def test_02(self): self.assertEqual(evaluate(parse("False")), False)
def test_01(self): self.assertEqual(evaluate(parse("True")), True)
def test_03(self): with self.assertRaises(Exception): self.assertEqual(evaluate(parse("b")))
def test_02(self): self.assertEqual(evaluate(parse("5 -> 6")), 6)
def test_01(self): evaluate(parse("5 * 6 -> a")) self.assertEqual(evaluate(parse("a")), 30)
def test_error_str05(self): with self.assertRaises(Exception): evaluate(parse("2 /"))