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