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