def test_tseitin_rep_or(): from sweetpea.logic import __tseitin_rep, _Cache clauses = [] cache = _Cache(4) # Make sure return is correct, and value was cached. assert __tseitin_rep(Or([1, 2, 3]), clauses, cache) == 4 assert cache.get(str(Or([1, 2, 3]))) == 4 # Make sure equivalence clauses were added. assert Or([Not(1), 4]) in clauses assert Or([Not(2), 4]) in clauses assert Or([Not(3), 4]) in clauses assert Or([1, 2, 3, Not(4)]) in clauses # Don't duplicate clauses when the cache was already populated clauses = [] cache = _Cache(4) # Prewarm the cache assert cache.get(str(Or([1, 2, 3]))) == 4 assert __tseitin_rep(Or([1, 2, 3]), clauses, cache) == 4 # Make sure no clauses were added assert clauses == []
def test_tseitin_rep_iff(): from sweetpea.logic import __tseitin_rep, _Cache clauses = [] cache = _Cache(3) # Make sure return is correct and value was cached. assert __tseitin_rep(Iff(1, 2), clauses, cache) == 3 assert cache.get(str(Iff(1, 2))) == 3 # Make sure equivalence clauses were added. assert Or([ 1, 2, 3 ]) in clauses assert Or([Not(1), Not(2), 3 ]) in clauses assert Or([ 1, Not(2), Not(3)]) in clauses assert Or([Not(1), 2, Not(3)]) in clauses # Don't duplicate clauses when the cache was already populated. clauses = [] cache = _Cache(3) # Prewarm the cache. assert cache.get(str(Iff(1, 2))) == 3 assert __tseitin_rep(Iff(1, 2), clauses, cache) == 3 # Make sure no clauses were added. assert clauses == []
def test_tseitin_rep_variables(): from sweetpea.logic import __tseitin_rep, _Cache clauses = [] cache = _Cache(2) assert __tseitin_rep(1, clauses, cache) == 1 assert clauses == [] assert cache.get_next_variable() == 2
def test_tseitin_cache(): from sweetpea.logic import _Cache c = _Cache(5) assert c.get('x') == 5 assert c.get('x') == 5 assert c.get('y') == 6 assert c.get('z') == 7 assert c.get('x') == 5 assert c.get_next_variable() == 8
def test_tseitin_rep_not(): from sweetpea.logic import __tseitin_rep, _Cache # Should replace Not(var) with another variable clauses = [] cache = _Cache(2) assert __tseitin_rep(Not(1), clauses, cache) == 2 # Make sure that Not(1) was cached. assert cache.get(str(Not(1))) == 2 # Make sure that the correct implication clauses were added. assert Or([ 1, 2 ]) in clauses assert Or([Not(1), Not(2)]) in clauses # No clauses should be added if the value was already cached. clauses = [] cache = _Cache(2) assert cache.get(str(Not(1))) == 2 # Prewarm the cache. assert __tseitin_rep(Not(1), clauses, cache) == 2 assert clauses == []