package hu.webarticum.jsatbuilder.builder.common;

import static org.junit.Assert.*;

import org.junit.Test;

import hu.webarticum.jsatbuilder.builder.core.ConstraintSetSolverFiller;
import hu.webarticum.jsatbuilder.builder.core.Variable;
import hu.webarticum.jsatbuilder.solver.core.Solver;


public class CommonTest {

    @Test
    public void test() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        ConstraintSetSolverFiller constraints = new ConstraintSetSolverFiller(true);

        Variable v1_1 = new Variable("1.1");
        Variable v1_2 = new Variable("1.2");
        Variable v1_3 = new Variable("1.3");
        Variable v2_1 = new Variable("2.1");
        Variable v2_2 = new Variable("2.2");

        constraints.add(new OneConstraint(v1_1, v1_2, v1_3));
        constraints.add(new OneConstraint(v2_1, v2_2));
        constraints.add(new OneConstraint(v1_1, v2_1));
        constraints.add(new OrConstraint(v1_2, v1_3));
        constraints.add(new OrConstraint(v1_2, v2_2));
        
        Solver solver = (Solver)Class.forName("hu.webarticum.jsatbuilder.solver.sat4j.LightSat4jSolver").newInstance();
        constraints.fillSolver(solver);
        
        if (!solver.run()) {
            fail("Solution not found!");
        }
        
        Solver.Model model = solver.getModel();
        
        if (model.get(v1_1)) {
            fail("Wrong solution (1.1 must be false)");
        }

        if (!model.get(v1_2)) {
            fail("Wrong solution (1.2 must be true)");
        }

        if (model.get(v1_3)) {
            fail("Wrong solution (1.3 must be false)");
        }

        if (!model.get(v2_1)) {
            fail("Wrong solution (2.1 must be true)");
        }

        if (model.get(v2_2)) {
            fail("Wrong solution (2.2 must be false)");
        }
    }

}

@@ -344,16 +344,17 @@
 oid test
+1
 () throw
@@ -359,69 +359,8 @@
 ows 
-InstantiationException, IllegalAccessException, ClassNotFound
 Exce
@@ -1000,141 +1000,36 @@
 r = 
-(Solver)Class.forName(%22hu.webarticum.jsatbuilder.solver.sat4j.LightSat4jSolver%22).newInstance();%0A        constraints.fillSolver(solver
+createSolverWith(constraints
 );%0A 
@@ -1678,10 +1678,1688 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void test2AIsTrue() throws Exception %7B%0A        doSimpleTest(true);%0A    %7D%0A%0A    @Test%0A    public void test2AIsFalse() throws Exception %7B%0A        doSimpleTest(false);%0A    %7D%0A    %0A    private void doSimpleTest(boolean aIsTrue) throws Exception %7B%0A        Variable a = new Variable(%22a%22);%0A        Variable b = new Variable(%22b%22);%0A        Variable c = new Variable(%22c%22);%0A        Variable d = new Variable(%22d%22);%0A        %0A        ConstraintSetSolverFiller constraints = new ConstraintSetSolverFiller();%0A        constraints.add(new OrConstraint(a, b));%0A        constraints.add(new EqualConstraint(%0A            new DefinitionLiteral(c, true),%0A            new DefinitionLiteral(d, false))%0A        );%0A        constraints.add(new EqualConstraint(a, c));%0A        constraints.add(new EqualConstraint(b, d));%0A        constraints.add(new GeneralClauseSetConstraint(new DefinitionLiteral%5B%5D%5B%5D %7B%0A            %7B new DefinitionLiteral(a, aIsTrue) %7D%0A        %7D));%0A%0A        Solver solver = createSolverWith(constraints);%0A        %0A        if (!solver.run()) %7B%0A            fail(%22Model was not found%22);%0A        %7D%0A        %0A        Solver.Model model = solver.getModel();%0A%0A        assertEquals(aIsTrue, model.get(a));%0A        assertEquals(!aIsTrue, model.get(b));%0A        assertEquals(aIsTrue, model.get(c));%0A        assertEquals(!aIsTrue, model.get(d));%0A    %7D%0A    %0A    private Solver createSolverWith(ConstraintSetSolverFiller constraints) throws Exception %7B%0A        String className = %22hu.webarticum.jsatbuilder.solver.sat4j.LightSat4jSolver%22;%0A        Solver solver = (Solver)Class.forName(className).newInstance();%0A        constraints.fillSolver(solver);%0A        return solver;%0A    %7D%0A    %0A
 %7D%0A

Extend CommonTest