def check_random_cnf(self, width, numvariables, numclauses): F = RandomKCNF(width, numvariables, numclauses) self.assertListEqual( list(F.variables()), ['x_{0}'.format(i) for i in range(1, numvariables + 1)]) self.assertEqual(len(F), numclauses) self.assertEqual(len(set(frozenset(x) for x in F.clauses())), numclauses)
def test_one(self): ass = [{'x_1': True, 'x_2': False}] F = RandomKCNF(2, 2, 3, planted_assignments=ass) G = CNF([ [(True, 'x_1'), (False, 'x_2')], [(False, 'x_1'), (False, 'x_2')], [(True, 'x_1'), (True, 'x_2')], ]) self.assertCnfEqual(F, G)
def test_all(self): ass = [ {'x_1': False, 'x_2': True}, {'x_1': True, 'x_2': False}, {'x_1': False, 'x_2': False}, {'x_1': True, 'x_2': True}, ] with self.assertRaises(ValueError): RandomKCNF(2, 2, 1, planted_assignments=ass)
def test_most(self): ass = [ {'x_1': True, 'x_2': False}, {'x_1': False, 'x_2': False}, {'x_1': True, 'x_2': True}, ] F = RandomKCNF(2, 2, 1, planted_assignments=ass) G = CNF([[(True, 'x_1'), (False, 'x_2')]]) self.assertCnfEqual(F, G)
def check_random_cnf(self,width,numvariables,numclauses) : F = RandomKCNF(width,numvariables,numclauses) self.assertListEqual(list(F.variables()), ['x_{0}'.format(i) for i in range(1,numvariables+1)]) self.assertEqual(len(F),numclauses) self.assertEqual(len(set(frozenset(x) for x in F)),numclauses)
def test_not_planted(self): F = RandomKCNF(4, 10, 20, 42) G = RandomKCNF(4, 10, 20, 42, []) self.assertCnfEqual(F, G)
def test_negative_clauses(self): with self.assertRaises(ValueError): RandomKCNF(3, 5, -1)
def test_negative_variables(self): with self.assertRaises(ValueError): RandomKCNF(3, -1, 1)
def test_negative_width(self): with self.assertRaises(ValueError): RandomKCNF(-1, 5, 1)
def test_too_wide(self): with self.assertRaises(ValueError): RandomKCNF(10, 5, 1)
def test_too_full(self): with self.assertRaises(ValueError): RandomKCNF(3, 5, 5 * 4 * 3 / (1 * 2 * 3) * 2**5 + 1)