def test_unsat(): cnf = read_dimacs(""" p cnf 1 2 1 0 -1 0 """) with pytest.raises(Unsatisfiable): cdcl(cnf)
def test_sat(): cnf = read_dimacs(""" p cnf 3 3 -1 -2 3 0 -1 2 0 1 0 """) assert cdcl(cnf) == {1: True, 2: True, 3: True}
def test_with_state(): cnf = read_dimacs(""" p cnf 2 1 1 2 0 """) assert unit_resolution_once(cnf, [Var(name=1, val=False)]) == [ Var(name=1, val=False), Var(name=2, val=True) ]
def test_sat(): cnf = read_dimacs(""" p cnf 3 3 -1 -2 3 0 -1 2 0 1 0 """) assert unit_resolution(cnf, []) == [Var(1, True), Var(2, True), Var(3, True)]
def test_unsat_with_state(): cnf = read_dimacs(""" p cnf 2 1 1 2 0 """) with pytest.raises(Unsatisfiable): unit_resolution_once(cnf, [Var(name=1, val=False), Var(name=2, val=False)])
def test_only_single_variable(): cnf = read_dimacs(""" p cnf 1 1 1 0 """) assert unit_resolution_once(cnf, []) == [Var(name=1, val=True)] cnf = read_dimacs(""" p cnf 1 1 -1 0 """) assert unit_resolution_once(cnf, []) == [Var(name=1, val=False)] cnf = read_dimacs(""" p cnf 1 1 1 0 """) assert unit_resolution_once(cnf, []) == [Var(name=1, val=True)]
def test_unsat(): cnf = read_dimacs(""" p cnf 2 3 1 -2 0 -1 -2 0 2 0 """) with pytest.raises(Unsatisfiable): print(unit_resolution(cnf, []))
def test_read_dimacs(): # test simplest DIMACS .cnf file dimacs = """p cnf 1 1 1 0""" assert read_dimacs(dimacs) == [ {1: True}, ] # test DIMACS with negation dimacs = """p cnf 1 1 -1 0""" assert read_dimacs(dimacs) == [ {1: False}, ] # test comments dimacs = """ c Just comment p cnf 1 1 -1 0""" assert read_dimacs(dimacs) == [ {1: False}, ] # test complicated CNF dimacs = """ c A sample .cnf file. p cnf 3 2 1 -3 0 2 3 -1 0""" assert read_dimacs(dimacs) == [ {1: True, 3: False}, {2: True, 3: True, 1: False} ] # test basic unsatisfiable cnf dimacs = """ c A sample .cnf file. p cnf 1 1 1 -1 0""" with pytest.raises(Unsatisfiable): read_dimacs(dimacs)
def test_without_single_variable(): cnf = read_dimacs(""" p cnf 2 1 1 2 0 """) assert unit_resolution_once(cnf, []) == []