Exemplo n.º 1
0
def test_unsat():
    cnf = read_dimacs("""
    p cnf 1 2 
    1 0
    -1 0
    """)
    with pytest.raises(Unsatisfiable):
        cdcl(cnf)
Exemplo n.º 2
0
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)
    ]
Exemplo n.º 4
0
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)]
Exemplo n.º 7
0
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, []))
Exemplo n.º 8
0
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, []) == []