def test_simple_iter_clauses(self): """Test basic expression iter_clauses functionality.""" # ensure defaults to CNF b = BooleanExpression('A or B or C or D') self.assertTrue(b.is_cnf) self.assertTrue(b.is_dnf) clauses = b.iter_clauses() self.assertEqual( repr(next(clauses)), '<BooleanExpression "A or B or C or D">') with self.assertRaises(StopIteration): next(clauses) # ensure falls back to DNF b = BooleanExpression('(A and B and C) or (D and E and F)') self.assertFalse(b.is_cnf) self.assertTrue(b.is_dnf) clauses = b.iter_clauses() self.assertEqual( repr(next(clauses)), '<BooleanExpression "A and B and C">') self.assertEqual( repr(next(clauses)), '<BooleanExpression "D and E and F">') with self.assertRaises(StopIteration): next(clauses)
def test_iter_clauses_not_normal_form(self): """Test attempting iter_clauses when not in normal form.""" b = BooleanExpression('A nand B') self.assertFalse(b.is_cnf) self.assertFalse(b.is_dnf) with self.assertRaises(RequiresNormalFormError): for clause in b.iter_clauses(): pass