def test_And_clauses(): # XXX: Is this i, j stuff necessary? for i in range(-1, 2, 2): # [-1, 1] for j in range(-1, 2, 2): C = Clauses(2) x = C.And(i*1, j*2) for sol in my_itersolve({(x,)} | C.clauses): f = i*1 in sol g = j*2 in sol assert f and g for sol in my_itersolve({(-x,)} | C.clauses): f = i*1 in sol g = j*2 in sol assert not (f and g) C = Clauses(1) x = C.And(1, -1) assert x == false # x and ~x assert C.clauses == set([]) C = Clauses(1) x = C.And(1, 1) for sol in my_itersolve({(x,)} | C.clauses): f = 1 in sol assert (f and f) for sol in my_itersolve({(-x,)} | C.clauses): f = 1 in sol assert not (f and f)
def test_And_bools(): for f in [true, false]: for g in [true, false]: C = Clauses(2) Cpos = Clauses(2) Cneg = Clauses(2) x = C.And(f, g) xpos = Cpos.And(f, g, polarity=True) xneg = Cneg.And(f, g, polarity=False) assert x == xpos == xneg == (true if (boolize(f) and boolize(g)) else false) assert C.clauses == Cpos.clauses == Cneg.clauses == set([]) C = Clauses(1) Cpos = Clauses(1) Cneg = Clauses(1) x = C.And(f, 1) xpos = Cpos.And(f, 1, polarity=True) xneg = Cneg.And(f, 1, polarity=False) fb = boolize(f) if x in [true, false]: assert C.clauses == Cpos.clauses == Cneg.clauses == set([]) xb = boolize(x) xbpos = boolize(xpos) xbneg = boolize(xneg) assert xb == xbpos == xbneg == (fb and NoBool()) else: for sol in chain(my_itersolve({(x, )} | C.clauses), my_itersolve({(xpos, )} | Cpos.clauses)): a = 1 in sol assert (fb and a) for sol in chain(my_itersolve({(-x, )} | C.clauses), my_itersolve({(-xneg, )} | Cneg.clauses)): a = 1 in sol assert not (fb and a) C = Clauses(1) Cpos = Clauses(1) Cneg = Clauses(1) x = C.And(1, f) xpos = Cpos.And(1, f, polarity=True) xneg = Cneg.And(1, f, polarity=False) if x in [true, false]: assert C.clauses == Cpos.clauses == Cneg.clauses == set([]) xb = boolize(x) xbpos = boolize(xpos) xbneg = boolize(xneg) assert xb == xbpos == xbneg == (fb and NoBool()) else: for sol in chain(my_itersolve({(x, )} | C.clauses), my_itersolve({(xpos, )} | Cpos.clauses)): a = 1 in sol assert (fb and a) for sol in chain(my_itersolve({(-x, )} | C.clauses), my_itersolve({(-xneg, )} | Cneg.clauses)): a = 1 in sol assert not (fb and a)
def test_And_clauses(): # XXX: Is this i, j stuff necessary? for i in range(-1, 2, 2): # [-1, 1] for j in range(-1, 2, 2): C = Clauses(2) Cpos = Clauses(2) Cneg = Clauses(2) x = C.And(i * 1, j * 2) xpos = Cpos.And(i * 1, j * 2, polarity=True) xneg = Cneg.And(i * 1, j * 2, polarity=False) for sol in chain(my_itersolve({(x, )} | C.clauses), my_itersolve({(xpos, )} | Cpos.clauses)): f = i * 1 in sol g = j * 2 in sol assert f and g for sol in chain(my_itersolve({(-x, )} | C.clauses), my_itersolve({(-xneg, )} | Cneg.clauses)): f = i * 1 in sol g = j * 2 in sol assert not (f and g) C = Clauses(1) Cpos = Clauses(1) Cneg = Clauses(1) x = C.And(1, -1) xpos = Cpos.And(1, -1, polarity=True) xneg = Cneg.And(1, -1, polarity=False) assert x == xneg == xpos == false # x and ~x assert C.clauses == Cpos.clauses == Cneg.clauses == set([]) C = Clauses(1) Cpos = Clauses(1) Cneg = Clauses(1) x = C.And(1, 1) xpos = Cpos.And(1, 1, polarity=True) xneg = Cneg.And(1, 1, polarity=False) for sol in chain(my_itersolve({(x, )} | C.clauses), my_itersolve({(xpos, )} | Cpos.clauses)): f = 1 in sol assert (f and f) for sol in chain(my_itersolve({(-x, )} | C.clauses), my_itersolve({(-xneg, )} | Cneg.clauses)): f = 1 in sol assert not (f and f)
def test_And_bools(): for f in [true, false]: for g in [true, false]: C = Clauses(2) x = C.And(f, g) assert x == (true if (boolize(f) and boolize(g)) else false) assert C.clauses == set([]) C = Clauses(1) x = C.And(f, 1) fb = boolize(f) if x in [true, false]: assert C.clauses == set([]) xb = boolize(x) assert xb == (fb and NoBool()) else: for sol in my_itersolve({(x,)} | C.clauses): a = 1 in sol assert (fb and a) for sol in my_itersolve({(-x,)} | C.clauses): a = 1 in sol assert not (fb and a) C = Clauses(1) x = C.And(1, f) if x in [true, false]: assert C.clauses == set([]) xb = boolize(x) assert xb == (fb and NoBool()) else: for sol in my_itersolve({(x,)} | C.clauses): a = 1 in sol assert (fb and a) for sol in my_itersolve({(-x,)} | C.clauses): a = 1 in sol assert not (fb and a)