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