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())
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)
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)