Beispiel #1
0
 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")))
Beispiel #2
0
 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)
Beispiel #3
0
 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)
Beispiel #4
0
 def test_empty_program(self):
     with self.assertRaises(Exception):
         t = Token()
         evaluate(t)
Beispiel #5
0
 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)
Beispiel #6
0
 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)
Beispiel #7
0
 def test_04(self):
     self.assertEqual(evaluate(parse("not True")), False)
     self.assertEqual(evaluate(parse("not False")), True)
Beispiel #8
0
 def test_02(self):
     self.assertEqual(evaluate(parse("False")), False)
Beispiel #9
0
 def test_01(self):
     self.assertEqual(evaluate(parse("True")), True)
Beispiel #10
0
 def test_03(self):
     with self.assertRaises(Exception):
         self.assertEqual(evaluate(parse("b")))
Beispiel #11
0
 def test_02(self):
     self.assertEqual(evaluate(parse("5 -> 6")), 6)
Beispiel #12
0
 def test_01(self):
     evaluate(parse("5 * 6 -> a"))
     self.assertEqual(evaluate(parse("a")), 30)
Beispiel #13
0
 def test_error_str05(self):
     with self.assertRaises(Exception):
         evaluate(parse("2 /"))