Skip to content

Commit

Permalink
Finishing Short Truth Table Contradiction Rule tests (#713)
Browse files Browse the repository at this point in the history
* Created Or Contradiction test files

* Added false or test

* Fixed false or test and added unknown or test

* Methods should start with lowercase

* Added true or test and removed useless lines

* Added Not Contradiction test

* Remove useless print statement

* Added And Contradiction tests

* Removed useless imports

* Fixed bug with test

* Added conditional test cases

* Create ConditionalContradictionRuleTest.java

Added Conditional Contradiction Rule tests

* Added biconditional test files

* Fixed typo

* Create BiconditionalContradictionRuleTest.java

Added biconditional contradiction rule tests

* Added single test file

* Added remaining test files

* Added JUnit test

* Removed unused tests

Removed deprecated importer and statement tests

---------

Co-authored-by: Chase Grajeda <[email protected]>
Co-authored-by: Chase-Grajeda <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent 6054db7 commit 5452703
Show file tree
Hide file tree
Showing 98 changed files with 1,956 additions and 25 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package puzzles.shorttruthtable.rules;

import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType;
import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAnd;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class AndContradictionRuleTest {

private static final ContradictionRuleAnd RULE = new ContradictionRuleAnd();
private static ShortTruthTable stt;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given a statement: A ^ B where ^ is true
*
* Asserts that this is a valid application of the rule if
* and only if A or B are set to false.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void trueAndTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
trueAndTestHelper(path + first + "T" + second);
}
}
}

private void trueAndTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

if (a.getType() == ShortTruthTableCellType.FALSE || b.getType() == ShortTruthTableCellType.FALSE) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}

/**
* Given a statement: A ^ B where ^ is false
*
* Asserts that this is a valid application of the rule if
* and only if A or B (or both) are set to true.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void falseAndTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AndContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
falseAndTestHelper(path + first + "F" + second);
}
}
}

private void falseAndTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.TRUE) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}

/**
* Given a statement: A ^ B where ^ is unknown
*
* Asserts that this is not a valid application of this rule.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void unknownAndTest() throws InvalidFileFormatException {
// Getting the files that have or set to unknown from And Introduction
String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
unknownAndTestHelper(path + first + "U" + second);
}
}
}

private void unknownAndTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package puzzles.shorttruthtable.rules;

import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType;
import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleAtomic;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class AtomicContradictionRuleTest {

private static final ContradictionRuleAtomic RULE = new ContradictionRuleAtomic();
private static ShortTruthTable stt;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given two statements: A, A
*
* Asserts that this is a valid application of the rule if
* and only if both A and B are not unknown and different.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void mismatchTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/AtomicContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
mismatchHelper(path + first + second);
}
}
}

private void mismatchHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(0, 2);

if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() != b.getType()) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package puzzles.shorttruthtable.rules;

import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTable;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableBoard;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCell;
import edu.rpi.legup.puzzle.shorttruthtable.ShortTruthTableCellType;
import edu.rpi.legup.puzzle.shorttruthtable.rules.contradiction.ContradictionRuleBiconditional;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class BiconditionalContradictionRuleTest {

private static final ContradictionRuleBiconditional RULE = new ContradictionRuleBiconditional();
private static ShortTruthTable stt;

@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
stt = new ShortTruthTable();
}

/**
* Given a statement: A <-> B where <-> is true
*
* Asserts that this is a valid application of the rule if
* and only if A and B are not unknown and A does not equal B
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void trueBiconditionalTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/BiconditionalContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
trueBiconditionalTestHelper(path + first + "T" + second);
}
}
}

private void trueBiconditionalTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() != b.getType()) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}

/**
* Given a statement: A <-> B where <-> is false
*
* Asserts that this is a valid application of the rule if
* and only if A and B are not unknown and A equals B
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void falseConditionalTest() throws InvalidFileFormatException {
String path = "puzzles/shorttruthtable/rules/BiconditionalContradictionRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
falseBiconditionalTestHelper(path + first + "F" + second);
}
}
}

private void falseBiconditionalTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard();
ShortTruthTableCell a = board.getCell(0, 0);
ShortTruthTableCell b = board.getCell(2, 0);

if (a.getType() != ShortTruthTableCellType.UNKNOWN && b.getType() != ShortTruthTableCellType.UNKNOWN && a.getType() == b.getType()) {
Assert.assertNull(RULE.checkContradiction(transition.getBoard()));
}
else {
Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}

/**
* Given a statement: A <-> B where <-> is unknown
*
* Asserts that this is not a valid application of this rule.
*
* @param filePath The file path for test board setup.
* @throws InvalidFileFormatException
*/
@Test
public void unknownBiconditionalTest() throws InvalidFileFormatException {
// Getting the files that have or set to unknown from Biconditional Introduction
String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/";
String[] letters = {"T", "F", "U"};
for (String first : letters) {
for (String second : letters) {
unknownBiconditionalTestHelper(path + first + "U" + second);
}
}
}

private void unknownBiconditionalTestHelper(String filePath) throws InvalidFileFormatException {
TestUtilities.importTestBoard(filePath, stt);
TreeNode rootNode = stt.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

Assert.assertNotNull(RULE.checkContradiction(transition.getBoard()));
}
}
Loading

0 comments on commit 5452703

Please sign in to comment.