def test_arbitrary_dimacs_sat_serialize(sentence: nnf.NNF): assert dimacs.loads(dimacs.dumps(sentence)) == sentence # Removing spaces may change the meaning, but shouldn't make it invalid # At least as far as our parser is concerned, a more sophisticated one # could detect variables with too high names serial = dimacs.dumps(sentence).split('\n') serial[1] = serial[1].replace(' ', '') dimacs.loads('\n'.join(serial))
def test_dimacs_cnf_serialize(): sample_input = """c Example CNF format file c p cnf 4 3 1 3 -4 0 4 0 2 -3 """ assert dimacs.loads(sample_input) == And( {Or({Var(1), Var(3), ~Var(4)}), Or({Var(4)}), Or({Var(2), ~Var(3)})})
def test_dimacs_sat_serialize(): # http://www.domagoj-babic.com/uploads/ResearchProjects/Spear/dimacs-cnf.pdf sample_input = """c Sample SAT format c p sat 4 (*(+(1 3 -4) +(4) +(2 3))) """ assert dimacs.loads(sample_input) == And( {Or({Var(1), Var(3), ~Var(4)}), Or({Var(4)}), Or({Var(2), Var(3)})})
def test_arbitrary_dimacs_cnf_serialize(sentence: And[Or[Var]]): reloaded = dimacs.loads(dimacs.dumps(sentence, mode='cnf')) assert reloaded.is_CNF() assert reloaded == sentence
def test_dimacs_rejects_weird_digits(): with pytest.raises(dimacs.DecodeError): dimacs.loads("p cnf 1 1\n¹ 0")
def test_dimacs_sat_weird_input(serialized: str, sentence: nnf.NNF): assert dimacs.loads(serialized) == sentence