Exemplo n.º 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'))))
Exemplo n.º 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'))))
Exemplo n.º 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')))))
Exemplo n.º 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'))))
Exemplo n.º 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')))))
Exemplo n.º 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'))))
Exemplo n.º 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')))))
Exemplo n.º 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')))))))
Exemplo n.º 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')))))))
Exemplo n.º 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')])
Exemplo n.º 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'))))
Exemplo n.º 12
0
 def test_expression_with_variable_to_string(self):
     e = Expression(Variable('a'))
     self.assertEqual(str(e), 'a')
Exemplo n.º 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'))))
Exemplo n.º 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'))))
Exemplo n.º 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))
Exemplo n.º 16
0
 def test_expression_parse_or(self):
     e = Expression('b1 or b2')
     self.assertEqual(e, Expression(Or(Variable('b1'), Variable('b2'))))
Exemplo n.º 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)
Exemplo n.º 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')))
Exemplo n.º 19
0
 def test_expression_with_bool_to_string(self):
     e = Expression(False)
     self.assertEqual(str(e), 'False')
Exemplo n.º 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)
Exemplo n.º 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'))))
Exemplo n.º 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')))))
Exemplo n.º 23
0
 def test_expression_parse_and(self):
     e = Expression('b1 and b2')
     self.assertEqual(e, Expression(And(Variable('b1'), Variable('b2'))))
Exemplo n.º 24
0
 def test_expression_parse_with_square_groups_unmatched(self):
     with self.assertRaises(ParseError):
         e = Expression('[(a or b) or (c or d])')
Exemplo n.º 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)')
Exemplo n.º 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)
Exemplo n.º 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'))
Exemplo n.º 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'))
Exemplo n.º 29
0
 def test_expression_substitute_existing_false(self):
     e = Expression('b1')
     self.assertFalse(e.substitute(lambda v: {'b1': False}.get(v.symbol, v)))
Exemplo n.º 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)
Exemplo n.º 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'))))
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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')))
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 37
0
 def test_expression_parse_with_missing_variable(self):
     with self.assertRaises(ParseError):
         e = Expression('b1 and and b3')
Exemplo n.º 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')))
Exemplo n.º 39
0
 def test_expression_parse_with_missing_end_parenthesis(self):
     with self.assertRaises(ParseError):
         e = Expression('b1 and (b2 or b3')
Exemplo n.º 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))
Exemplo n.º 41
0
 def test_expression_substitute_existing(self):
     e = Expression('b1')
     self.assertTrue(e.substitute(lambda v: {'b1': True}.get(v.symbol, v)))