Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finishing Short Truth Table Contradiction Rule tests #713

Merged
merged 22 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading