示例#1
0
 def test_expression_parse_implicit_mixed_2(self):
     e = Expression('b1 or b2 and b3 or b4')
     self.assertEqual(
         e,
         Expression(
             Or(Variable('b1'), And(Variable('b2'), Variable('b3')),
                Variable('b4'))))
示例#2
0
 def test_expression_parse_longer_names(self):
     e = Expression('b12345 and bxyz and testtesttest')
     self.assertEqual(
         e,
         Expression(
             And(Variable('b12345'), Variable('bxyz'),
                 Variable('testtesttest'))))
示例#3
0
 def test_expression_parse_parentheses_mixed_1(self):
     e = Expression('(b1 and b2) or (b3 and b4)')
     self.assertEqual(
         e,
         Expression(
             Or(And(Variable('b1'), Variable('b2')),
                And(Variable('b3'), Variable('b4')))))
示例#4
0
 def test_expression_parse_multiple_parenthesis_or(self):
     e = Expression('b1 or (b2 or b3) or b4')
     self.assertEqual(
         e,
         Expression(
             Or(Variable('b1'), Variable('b2'), Variable('b3'),
                Variable('b4'))))
示例#5
0
 def test_expression_parse_parentheses_mixed_2(self):
     e = Expression('(b1 or b2) and (b3 or b4)')
     self.assertEqual(
         e,
         Expression(
             And(Or(Variable('b1'), Variable('b2')),
                 Or(Variable('b3'), Variable('b4')))))
示例#6
0
 def test_expression_parse_multiple_parenthesis_and(self):
     e = Expression('b1 and (b2 and b3) and b4')
     self.assertEqual(
         e,
         Expression(
             And(Variable('b1'), Variable('b2'), Variable('b3'),
                 Variable('b4'))))
示例#7
0
 def test_expression_parse_with_square_mixed_groups(self):
     e = Expression('[(a or b) or (c or d)] or [e or (f and g and h)]')
     self.assertEqual(
         e,
         Expression(
             Or(Variable('a'), Variable('b'), Variable('c'), Variable('d'),
                Variable('e'),
                And(Variable('f'), Variable('g'), Variable('h')))))
示例#8
0
 def test_expression_parse_parentheses_left_nested(self):
     e = Expression('(((b1 or b2) and b3) or b4) and (b5)')
     self.assertEqual(
         e,
         Expression(
             And(
                 Variable('b5'),
                 Or(Variable('b4'),
                    And(Variable('b3'), Or(Variable('b1'),
                                           Variable('b2')))))))
示例#9
0
 def test_expression_parse_parentheses_right_nested(self):
     e = Expression('(b1 or (b2 and (b3 or (b4 and (b5)))))')
     self.assertEqual(
         e,
         Expression(
             Or(
                 Variable('b1'),
                 And(
                     Variable('b2'),
                     Or(Variable('b3'), And(Variable('b4'),
                                            Variable('b5')))))))
示例#10
0
 def test_expression_iter_variables(self):
     e = Expression(
         Or(And(Variable('b1'), Variable('b2')),
            And(Variable('b3'), Variable('b4'))))
     self.assertEqual(
         list(e.variables),
         [Variable('b1'),
          Variable('b2'),
          Variable('b3'),
          Variable('b4')])
示例#11
0
 def test_expression_parse_with_extra_space(self):
     e = Expression('b1    and   b2       and b3')
     self.assertEqual(
         e, Expression(And(Variable('b1'), Variable('b2'), Variable('b3'))))
示例#12
0
 def test_expression_with_variable_to_string(self):
     e = Expression(Variable('a'))
     self.assertEqual(str(e), 'a')
示例#13
0
 def test_expression_parse_name_starting_with_or(self):
     e = Expression('b1 and order')
     self.assertEqual(e, Expression(And(Variable('b1'), Variable('order'))))
示例#14
0
 def test_expression_parse_name_starting_with_and(self):
     e = Expression('b1 or anderson')
     self.assertEqual(e, Expression(Or(Variable('b1'),
                                       Variable('anderson'))))
示例#15
0
 def test_expression_substitute_invalid(self):
     e = Expression('b1 and b2')
     with self.assertRaises(SubstitutionError):
         e.substitute(lambda v: {'b1': 17}.get(v.symbol, v))
示例#16
0
 def test_expression_parse_or(self):
     e = Expression('b1 or b2')
     self.assertEqual(e, Expression(Or(Variable('b1'), Variable('b2'))))
示例#17
0
 def test_expression_substitute_with_short_circuit_or(self):
     e = Expression('(a and b) or c or d')
     e1 = e.substitute(lambda v: {'c': True}.get(v.symbol, v))
     self.assertTrue(e1.has_value())
     self.assertTrue(e1.value)
示例#18
0
 def test_expression_substitute_unknown_to_variable(self):
     e = Expression('b1')
     e1 = e.substitute(lambda v: v)
     self.assertEqual(e1, Expression(Variable('b1')))
示例#19
0
 def test_expression_with_bool_to_string(self):
     e = Expression(False)
     self.assertEqual(str(e), 'False')
示例#20
0
 def test_expression_substitute_with_short_circuit_or(self):
     e = Expression('(a and b) or c or d')
     e1 = e.substitute(lambda v: {'c': True}.get(v.symbol, v))
     self.assertTrue(e1.has_value())
     self.assertTrue(e1.value)
示例#21
0
 def test_expression_parse_parenthesis_with_space_left(self):
     e = Expression('( b1 and b2)')
     self.assertEqual(e, Expression(And(Variable('b1'), Variable('b2'))))
示例#22
0
 def test_expression_parse_uppercase_operators(self):
     e = Expression('(b1 AND b2) OR b3')
     self.assertEqual(
         e,
         Expression(Or(Variable('b3'), And(Variable('b1'),
                                           Variable('b2')))))
示例#23
0
 def test_expression_parse_and(self):
     e = Expression('b1 and b2')
     self.assertEqual(e, Expression(And(Variable('b1'), Variable('b2'))))
示例#24
0
 def test_expression_parse_with_square_groups_unmatched(self):
     with self.assertRaises(ParseError):
         e = Expression('[(a or b) or (c or d])')
示例#25
0
 def test_expression_to_string(self):
     e = Expression('(a and b) or (c and d)')
     self.assertEqual(str(e), '(a and b) or (c and d)')
示例#26
0
 def test_expression_substitute_existing_false(self):
     e = Expression('b1')
     e1 = e.substitute(lambda v: {'b1': False}.get(v.symbol, v))
     self.assertTrue(e1.has_value())
     self.assertFalse(e1.value)
示例#27
0
 def test_expression_substitute_unknown_to_expression(self):
     e = Expression('b1 and b2')
     e1 = e.substitute(lambda v: v)
     self.assertEqual(e1, Expression('b1 and b2'))
示例#28
0
 def test_expression_substitute_unknown_to_expression(self):
     e = Expression('b1 and b2')
     e1 = e.substitute(lambda v: v)
     self.assertEqual(e1, Expression('b1 and b2'))
 def test_expression_substitute_existing_false(self):
     e = Expression('b1')
     self.assertFalse(e.substitute(lambda v: {'b1': False}.get(v.symbol, v)))
示例#30
0
 def test_expression_substitute_with_short_circuit_and(self):
     e = Expression('a and (b or c) and d')
     e1 = e.substitute(lambda v: {'a': False}.get(v.symbol, v))
     self.assertTrue(e1.has_value())
     self.assertFalse(e1.value)
示例#31
0
 def test_expression_parse_multiple_with_duplicates(self):
     e = Expression('b1 and b2 and b1 and b4')
     self.assertEqual(
         e, Expression(And(Variable('b1'), Variable('b2'), Variable('b4'))))
示例#32
0
 def test_expression_substitute_with_short_circuit_and(self):
     e = Expression('a and (b or c) and d')
     e1 = e.substitute(lambda v: {'a': False}.get(v.symbol, v))
     self.assertTrue(e1.has_value())
     self.assertFalse(e1.value)
示例#33
0
 def test_expression_substitute_evaluate_all_and_terms_to_true(self):
     e = Expression('a and b')
     e1 = e.substitute(lambda v: True)
     self.assertEqual(e1, Expression(True))
示例#34
0
 def test_expression_substitute_remove_terms_from_or(self):
     e = Expression('a or b')
     e1 = e.substitute(lambda v: {'a': False}.get(v.symbol, v))
     self.assertEqual(e1, Expression(Variable('b')))
示例#35
0
 def test_expression_substitute_existing_false(self):
     e = Expression('b1')
     e1 = e.substitute(lambda v: {'b1': False}.get(v.symbol, v))
     self.assertTrue(e1.has_value())
     self.assertFalse(e1.value)
示例#36
0
 def test_expression_substitute_evaluate_all_or_terms_to_false(self):
     e = Expression('a or b')
     e1 = e.substitute(lambda v: False)
     self.assertEqual(e1, Expression(False))
示例#37
0
 def test_expression_parse_with_missing_variable(self):
     with self.assertRaises(ParseError):
         e = Expression('b1 and and b3')
示例#38
0
 def test_expression_substitute_unknown_to_variable(self):
     e = Expression('b1')
     e1 = e.substitute(lambda v: v)
     self.assertEqual(e1, Expression(Variable('b1')))
示例#39
0
 def test_expression_parse_with_missing_end_parenthesis(self):
     with self.assertRaises(ParseError):
         e = Expression('b1 and (b2 or b3')
示例#40
0
 def test_expression_substitute_invalid(self):
     e = Expression('b1 and b2')
     with self.assertRaises(SubstitutionError):
         e.substitute(lambda v: {'b1': 17}.get(v.symbol, v))
 def test_expression_substitute_existing(self):
     e = Expression('b1')
     self.assertTrue(e.substitute(lambda v: {'b1': True}.get(v.symbol, v)))