@Test public void testIsSatisfiedBy_empty() throws ContradictionException, TimeoutException { Formula f = Formula.newInstanceforSAT(new Formula()); // emptyFormula assertTrue(f.getModels().isEmpty()); // emptyFormula formula is not satisfiable - not even by an emptyFormula model assertFalse(f.isSatisfiedBy(new Model(new int[] {}))); }
@Test public void testIsSatisfiedBy() throws ContradictionException, TimeoutException { Var P = new Var("P"); Var Q = new Var("Q"); Var R = new Var("R"); Formula f = Formula.newInstanceforSAT((P.or(Q)).and(P.not().or(R))); // (P or Q) and (~P or R) // Possible assignments // ~P ~Q ~R // ~P ~Q R // ~P Q ~R (solution) // ~P Q R (solution // P ~Q ~R // P ~Q R (solution) // P Q ~R // P Q R (solution) BidiMap map = f.getVariableMap(); assertTrue(map.get(1).equals("P")); assertTrue(map.get(2).equals("Q")); assertTrue(map.get(3).equals("R")); // Only complete models, if solutions, should pass assertFalse(f.isSatisfiedBy(new Model(new int[] {-1, -2, -3}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {-1, -2, 3}))); assertTrue(f.isSatisfiedBy(new Model(new int[] {-1, 2, -3}))); assertTrue(f.isSatisfiedBy(new Model(new int[] {-1, 2, 3}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {1, -2, -3}))); assertTrue(f.isSatisfiedBy(new Model(new int[] {1, -2, 3}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {1, 2, -3}))); assertTrue(f.isSatisfiedBy(new Model(new int[] {1, 2, 3}))); // Partial models, passing isPossiblySatisfiedBy(), should not pass here assertFalse(f.isSatisfiedBy(new Model(new int[] {}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {-1}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {1}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {-1, 2}))); assertFalse(f.isSatisfiedBy(new Model(new int[] {1, 3}))); }