コード例 #1
0
ファイル: test_logic.py プロジェクト: PaulGureghian1/Conda
def test_sat():
    C = Clauses()
    C.new_var('x1')
    C.new_var('x2')
    assert C.sat() is not None
    assert C.sat([]) is not None
    assert C.sat([()]) is None
    assert C.sat([(False, )]) is None
    assert C.sat([(True, ), ()]) is None
    assert C.sat([(True, False, -1)]) is not None
    assert C.sat([(+1, False), (+2, ), (True, )], names=True) == {'x1', 'x2'}
    assert C.sat([(-1, False), (True, ), (+2, )], names=True) == {'x2'}
    assert C.sat([(True, ), (-1, ), (-2, False)], names=True) == set()
    assert C.sat([(+1, ), (-1, False)], names=True) is None
    C.unsat = True
    assert C.sat() is None
    assert C.sat([]) is None
    assert C.sat([(True, )]) is None
    assert len(Clauses(10).sat([[1]])) == 10
コード例 #2
0
ファイル: test_logic.py プロジェクト: groutr/conda
def test_sat():
    C = Clauses()
    C.new_var('x1')
    C.new_var('x2')
    assert C.sat() is not None
    assert C.sat([]) is not None
    assert C.sat([()]) is None
    assert C.sat([(False,)]) is None
    assert C.sat([(True,),()]) is None
    assert C.sat([(True,False,-1)]) is not None
    assert C.sat([(+1,False),(+2,),(True,)], names=True) == {'x1','x2'}
    assert C.sat([(-1,False),(True,),(+2,)], names=True) == {'x2'}
    assert C.sat([(True,),(-1,),(-2,False)], names=True) == set()
    assert C.sat([(+1,),(-1,False)], names=True) is None
    C.unsat = True
    assert C.sat() is None
    assert C.sat([]) is None
    assert C.sat([(True,)]) is None
    assert len(Clauses(10).sat([[1]])) == 10
コード例 #3
0
ファイル: test_logic.py プロジェクト: njalerikson/conda
def my_TEST(Mfunc, Cfunc, mmin, mmax, is_iter):
    for m in range(mmin, mmax + 1):
        if m == 0:
            ijprod = [()]
        else:
            ijprod = (TRUE, FALSE) + sum(
                ((k, my_NOT(k)) for k in range(1, m + 1)), ())
            ijprod = product(ijprod, repeat=m)
        for ij in ijprod:
            C = Clauses()
            Cpos = Clauses()
            Cneg = Clauses()
            for k in range(1, m + 1):
                nm = 'x%d' % k
                C.new_var(nm)
                Cpos.new_var(nm)
                Cneg.new_var(nm)
            ij2 = tuple(
                C.from_index(k)
                if isinstance(k, int) and k not in {TRUE, FALSE} else k
                for k in ij)
            if is_iter:
                x = Cfunc.__get__(C, Clauses)(ij2)
                Cpos.Require(Cfunc.__get__(Cpos, Clauses), ij)
                Cneg.Prevent(Cfunc.__get__(Cneg, Clauses), ij)
            else:
                x = Cfunc.__get__(C, Clauses)(*ij2)
                Cpos.Require(Cfunc.__get__(Cpos, Clauses), *ij)
                Cneg.Prevent(Cfunc.__get__(Cneg, Clauses), *ij)
            tsol = Mfunc(*ij)
            if tsol in {TRUE, FALSE}:
                assert x == tsol, (ij2, Cfunc.__name__, C.as_list())
                assert Cpos.unsat == (tsol != TRUE) and not Cpos.as_list(), (
                    ij, 'Require(%s)')
                assert Cneg.unsat == (tsol == TRUE) and not Cneg.as_list(), (
                    ij, 'Prevent(%s)')
                continue
            for sol in C.itersolve([(x, )]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol == TRUE, (ij2, sol, Cfunc.__name__, C.as_list())
            for sol in Cpos.itersolve([]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol == TRUE, (ij, sol, 'Require(%s)' % Cfunc.__name__,
                                      Cpos.as_list())
            for sol in C.itersolve([(C.Not(x), )]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol == FALSE, (ij2, sol, Cfunc.__name__, C.as_list())
            for sol in Cneg.itersolve([]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol == FALSE, (ij, sol, 'Prevent(%s)' % Cfunc.__name__,
                                       Cneg.as_list())
コード例 #4
0
ファイル: test_logic.py プロジェクト: SubhamRajgaria/conda-1
def my_TEST(Mfunc, Cfunc, mmin, mmax, is_iter):
    for m in range(mmin, mmax + 1):
        if m == 0:
            ijprod = [()]
        else:
            ijprod = (True, False) + sum(
                ((k, my_NOT(k)) for k in range(1, m + 1)), ())
            ijprod = product(ijprod, repeat=m)
        for ij in ijprod:
            C = Clauses()
            Cpos = Clauses()
            Cneg = Clauses()
            for k in range(1, m + 1):
                nm = 'x%d' % k
                C.new_var(nm)
                Cpos.new_var(nm)
                Cneg.new_var(nm)
            ij2 = tuple(C.from_index(k) if type(k) is int else k for k in ij)
            if is_iter:
                x = Cfunc.__get__(C, Clauses)(ij2)
                Cpos.Require(Cfunc.__get__(Cpos, Clauses), ij)
                Cneg.Prevent(Cfunc.__get__(Cneg, Clauses), ij)
            else:
                x = Cfunc.__get__(C, Clauses)(*ij2)
                Cpos.Require(Cfunc.__get__(Cpos, Clauses), *ij)
                Cneg.Prevent(Cfunc.__get__(Cneg, Clauses), *ij)
            tsol = Mfunc(*ij)
            if type(tsol) is bool:
                assert x is tsol, (ij2, Cfunc.__name__, C.clauses)
                assert Cpos.unsat == (not tsol) and not Cpos.clauses, (
                    ij, 'Require(%s)')
                assert Cneg.unsat == tsol and not Cneg.clauses, (ij,
                                                                 'Prevent(%s)')
                continue
            for sol in C.itersolve([(x, )]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol is True, (ij2, sol, Cfunc.__name__, C.clauses)
            for sol in Cpos.itersolve([]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol is True, (ij, sol, 'Require(%s)' % Cfunc.__name__,
                                      Cpos.clauses)
            for sol in C.itersolve([(C.Not(x), )]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol is False, (ij2, sol, Cfunc.__name__, C.clauses)
            for sol in Cneg.itersolve([]):
                qsol = Mfunc(*my_SOL(ij, sol))
                assert qsol is False, (ij, sol, 'Prevent(%s)' % Cfunc.__name__,
                                       Cneg.clauses)
コード例 #5
0
ファイル: test_logic.py プロジェクト: groutr/conda
def my_TEST(Mfunc, Cfunc, mmin, mmax, is_iter):
    for m in range(mmin,mmax+1):
        if m == 0:
            ijprod = [()]
        else:
            ijprod = (True,False)+sum(((k,my_NOT(k)) for k in range(1,m+1)),())
            ijprod = product(ijprod, repeat=m)
        for ij in ijprod:
            C = Clauses()
            Cpos = Clauses()
            Cneg = Clauses()
            for k in range(1,m+1):
                nm = 'x%d' % k
                C.new_var(nm)
                Cpos.new_var(nm)
                Cneg.new_var(nm)
            ij2 = tuple(C.from_index(k) if type(k) is int else k for k in ij)
            if is_iter:
                x = Cfunc.__get__(C,Clauses)(ij2)
                Cpos.Require(Cfunc.__get__(Cpos,Clauses), ij)
                Cneg.Prevent(Cfunc.__get__(Cneg,Clauses), ij)
            else:
                x = Cfunc.__get__(C,Clauses)(*ij2)
                Cpos.Require(Cfunc.__get__(Cpos,Clauses), *ij)
                Cneg.Prevent(Cfunc.__get__(Cneg,Clauses), *ij)
            tsol = Mfunc(*ij)
            if type(tsol) is bool:
                assert x is tsol, (ij2, Cfunc.__name__, C.clauses)
                assert Cpos.unsat == (not tsol) and not Cpos.clauses, (ij, 'Require(%s)')
                assert Cneg.unsat == tsol and not Cneg.clauses, (ij, 'Prevent(%s)')
                continue
            for sol in C.itersolve([(x,)]):
                qsol = Mfunc(*my_SOL(ij,sol))
                assert qsol is True, (ij2, sol, Cfunc.__name__, C.clauses)
            for sol in Cpos.itersolve([]):
                qsol = Mfunc(*my_SOL(ij,sol))
                assert qsol is True, (ij, sol,'Require(%s)' % Cfunc.__name__, Cpos.clauses)
            for sol in C.itersolve([(C.Not(x),)]):
                qsol = Mfunc(*my_SOL(ij,sol))
                assert qsol is False, (ij2, sol, Cfunc.__name__, C.clauses)
            for sol in Cneg.itersolve([]):
                qsol = Mfunc(*my_SOL(ij,sol))
                assert qsol is False, (ij, sol,'Prevent(%s)' % Cfunc.__name__, Cneg.clauses)