@@ -0,0 +1,2843 @@
+package net.ssehub.kernel_haven.util.logic;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0Aimport net.ssehub.kernel_haven.util.logic.parser.SubFormulaChecker;%0A%0A/**%0A * Tests the %7B@link SubFormulaChecker%7D.%0A * @author El-Sharkawy%0A *%0A */%0Apublic class SubFormulaCheckerTest %7B%0A    %0A    private static final Formula VARIABLE_A = new Variable(%22A%22);%0A    private static final Formula VARIABLE_B = new Variable(%22B%22);%0A    private static final Formula SUB_FORMULA = new Conjunction(VARIABLE_A, VARIABLE_B);%0A    %0A    %0A    /**%0A     * Tests that elements contained in the sub formula are not marked as containing elements.%0A     */%0A    @Test%0A    public void testSubsubelementsNotContained() %7B%0A        assertContainment(VARIABLE_A, false);%0A    %7D%0A    %0A    /**%0A     * Tests that a formula contains itself.%0A     */%0A    @Test%0A    public void testSelfContained() %7B%0A        assertContainment(SUB_FORMULA, true);%0A    %7D%0A    %0A    /**%0A     * Tests if %7B@link SubFormulaChecker%7D detects a sub formula correctly in a more complex formula.%0A     */%0A    @Test%0A    public void testContainedDetection() %7B%0A        Formula formula = new Disjunction(new Variable(%22C%22), new Negation(SUB_FORMULA));%0A        Formula secondFormula = new Conjunction(new Variable(%22E%22), new Variable(%22F%22));%0A        formula = new Conjunction(secondFormula, formula);%0A        %0A        assertContainment(formula, true);%0A    %7D%0A    %0A    /**%0A     * Tests that a very similar with a different semantics does not contain the sub formula.%0A     */%0A    @Test%0A    public void testSameVariablesWithDifferentSemanticsDoesNotContain() %7B%0A        Formula formula = new Conjunction(VARIABLE_A, new Negation(VARIABLE_B));%0A        %0A        assertContainment(formula, false);%0A    %7D%0A    %0A%0A    /**%0A     * Checks if %7B@link #SUB_FORMULA%7D is contained in the given formula.%0A     * @param formula The containing formula to test.%0A     * @param containsSubformula %3Ctt%3Etrue%3C/tt%3E %7B@link #SUB_FORMULA%7D is nested and should be found,%0A     * %3Ctt%3Efalse%3C/tt%3E %7B@link #SUB_FORMULA%7D is not contained and must not be found.%0A     */%0A    private void assertContainment(Formula formula, boolean containsSubformula) %7B%0A        SubFormulaChecker checker = new SubFormulaChecker(SUB_FORMULA);%0A        formula.accept(checker);%0A        String strFormula = formula.toString().replace(%22&&%22, %22%5Cu2227%22).replace(%22%7C%7C%22, %22%5Cu2228%22);%0A        String strSubFormula = SUB_FORMULA.toString().replace(%22&&%22, %22%5Cu2227%22).replace(%22%7C%7C%22, %22%5Cu2228%22);%0A        %0A        if (containsSubformula) %7B%0A            Assert.assertTrue(%22%5C%22%22 + strFormula + %22%5C%22 contains %5C%22%22 + strSubFormula + %22%5C%22,%22%0A                + %22 but the visitor did not recognized that.%22, checker.isNested());%0A        %7D else %7B%0A            Assert.assertFalse(%22%5C%22%22 + strFormula + %22%5C%22 contains not %5C%22%22 + strSubFormula + %22%5C%22,%22%0A                + %22 but the visitor reported that.%22, checker.isNested());%0A        %7D%0A    %7D%0A%0A%7D%0A

test cases for SubFormulaChecker