From 3ea1346ab167dc641e9d1ea9c60ab147ba1a3551 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Tue, 7 Nov 2023 17:26:11 -0500 Subject: [PATCH] Added more Short Truth Table tests (#675) * Initial setup * Working initial test * Added another test * Added more tests * Added another test * Added comments, removed useless imports, added 1 more test * Reformatting * Removed useless import * Added initial and elimination test * Comments and spacing * Another test * Updated comments and wrote new test * Created two new test files * Renamed test to be more descriptive * Added another test * Rewrote test to be more comprehensive * More tests :)))) * Fixed test name and file * Fixed test * Fixed broken tests * Shouldn't have touched these files * CHECKSTYLE * Trying to make CheckStyle happy * Initial commit for more tests * Finished a test * Another test done * More tests * Added cannot set both at once test * Conditional files * Some tests done * More tests * Even more tests * Fixed comments to use biconditional symbol * Added tests for false conditional Now tests only setting the A value and only setting the B value * Fixed some broken biconditional files and added new ones * Added more tests for B and fixed some descriptions * Checkstyle fix * Added tests for Not Elimination One of the tests failed, but I tested that and that seems to be the case. It should be failing. * Temporarily commenting out broken test --------- Co-authored-by: Ivan Ho <41582274+Corppet@users.noreply.github.com> --- .../rules/BiconditionalEliminationTest.java | 373 ++++++++++++++++++ .../rules/ConditionalEliminationTest.java | 233 +++++++++++ .../rules/NotEliminationTest.java | 124 ++++++ .../FalseBiconditional | 13 + .../FalseBiconditionalWithFalseA | 14 + .../FalseBiconditionalWithFalseB | 14 + .../FalseBiconditionalWithTrueA | 14 + .../FalseBiconditionalWithTrueB | 14 + .../TrueBiconditional | 13 + .../TrueBiconditionalWithFalseA | 14 + .../TrueBiconditionalWithFalseB | 14 + .../TrueBiconditionalWithTrueA | 14 + .../TrueBiconditionalWithTrueB | 14 + .../FalseConditional | 13 + .../TrueConditional | 13 + .../TrueConditionalWithFalseB | 14 + .../TrueConditionalWithTrueA | 14 + .../TrueConditionalWithTrueB | 14 + .../rules/NotEliminationDirectRule/BlankNot | 12 + .../rules/NotEliminationDirectRule/FalseNot | 13 + .../rules/NotEliminationDirectRule/TrueNot | 13 + 21 files changed, 974 insertions(+) create mode 100644 src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java create mode 100644 src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java create mode 100644 src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditional create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot diff --git a/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java new file mode 100644 index 000000000..05faf87bb --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalEliminationTest.java @@ -0,0 +1,373 @@ +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.basic.elimination.DirectRuleBiconditionalElimination; +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 BiconditionalEliminationTest { + private static final DirectRuleBiconditionalElimination RULE = new DirectRuleBiconditionalElimination(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given one statement: A <-> B where both A and <-> are true + * + * Asserts that this is a valid application of the rule if and only if B is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueBiconditionalWithTrueATest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell morty = board.getCell(2, 0); + + // Asserts that this is not a valid application of the rule when B is unknown + morty.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when B is true + morty.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(morty); + Assert.assertNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when B is false + morty.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where both B and <-> are true + * + * Asserts that this is a valid application of the rule if and only if A is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueBiconditionalWithTrueBTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell rick = board.getCell(0, 0); + + // Asserts that this is a valid application of the rule when A is true + rick.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(rick); + Assert.assertNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when A is unknown + rick.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when A is false + rick.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + + /** + * Given one statement: A <-> B where A is false and <-> is true + * + * Asserts that this is a valid application of the rule if and only if B is false. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueBiconditionalWithFalseATest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell morty = board.getCell(2, 0); + + // Asserts that this is not a valid application of the rule when B is unknown + morty.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when B is true + morty.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when B is false + morty.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(morty); + Assert.assertNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where B is false and <-> is true + * + * Asserts that this is a valid application of the rule if and only if A is false. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueBiconditionalWithFalseBTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell rick = board.getCell(0, 0); + + // Asserts that this is not a valid application of the rule when A is unknown + rick.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when A is true + rick.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when A is false + rick.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(rick); + Assert.assertNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where A is true and <-> is false + * + * Asserts that this is a valid application of the rule if and only if B is false. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseBiconditionalWithTrueATest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell morty = board.getCell(2, 0); + + // Asserts that this is not a valid application of the rule when B is unknown + morty.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when B is true + morty.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when B is false + morty.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(morty); + Assert.assertNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where B is true and <-> is false + * + * Asserts that this is a valid application of the rule if and only if A is false. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseBiconditionalWithTrueBTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell rick = board.getCell(0, 0); + + // Asserts that this is not a valid application of the rule when A is unknown + rick.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when A is true + rick.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when A is false + rick.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(rick); + Assert.assertNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where A and <-> are false + * + * Asserts that this is a valid application of the rule if and only if B is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseBiconditionalWithFalseATest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell morty = board.getCell(2, 0); + + // Asserts that this is not a valid application of the rule when B is unknown + morty.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when B is true + morty.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(morty); + Assert.assertNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when B is false + morty.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(morty); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where B and <-> are false + * + * Asserts that this is a valid application of the rule if and only if A is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseBiconditionalWithFalseBTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell rick = board.getCell(0, 0); + + // Asserts that this is not a valid application of the rule when A is unknown + rick.setData(ShortTruthTableCellType.UNKNOWN); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is not a valid application of the rule when A is false + rick.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(rick); + Assert.assertNotNull(RULE.checkRule(transition)); + + // Asserts that this is a valid application of the rule when A is true + rick.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(rick); + Assert.assertNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A <-> B where <-> is true + * + * Asserts that setting any combination of A and B at the same time is not a valid + * application of this rule + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueBiconditionalSetBothAtOnceTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType1 : cellTypes) { + for (ShortTruthTableCellType cellType2 : cellTypes) { + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell rick = board.getCell(0, 0); + ShortTruthTableCell morty = board.getCell(2, 0); + + rick.setData(cellType1); + morty.setData(cellType2); + + board.addModifiedData(rick); + board.addModifiedData(morty); + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + + /** + * Asserts that setting any combination of A and B at the same time is not a valid + * application of this rule. This is tested on multiple files. + * + * @throws InvalidFileFormatException + */ + @Test + public void CannotSetBothAandBAtOnceTest() throws InvalidFileFormatException { + String directory = "puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/"; + setAandBBothAtOnceTest(directory + "FalseBiconditional"); + setAandBBothAtOnceTest(directory + "TrueBiconditional"); + setAandBBothAtOnceTest(directory + "FalseBiconditionalWithFalseA"); + setAandBBothAtOnceTest(directory + "TrueBiconditionalWithFalseA"); + setAandBBothAtOnceTest(directory + "FalseBiconditionalWithTrueA"); + setAandBBothAtOnceTest(directory + "TrueBiconditionalWithTrueA"); + } + + /** + * Helper function to test biconditional elimination rule with given file path. + * + * @param filePath The file path for test board setup. + * @throws InvalidFileFormatException + */ + private void setAandBBothAtOnceTest(String filePath) throws InvalidFileFormatException { + TestUtilities.importTestBoard(filePath, stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType1 : cellTypes) { + for (ShortTruthTableCellType cellType2 : cellTypes) { + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell rick = board.getCell(0, 0); + ShortTruthTableCell morty = board.getCell(2, 0); + + rick.setData(cellType1); + morty.setData(cellType2); + + board.addModifiedData(rick); + board.addModifiedData(morty); + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java new file mode 100644 index 000000000..8d0bb4e1a --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/ConditionalEliminationTest.java @@ -0,0 +1,233 @@ +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.basic.elimination.DirectRuleConditionalElimination; +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 ConditionalEliminationTest { + private static final DirectRuleConditionalElimination RULE = new DirectRuleConditionalElimination(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given one statement: A -> B where -> is false + * + * Asserts that the only valid combination of A and B that is a valid application + * of this rule is when A is true and B is false + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseConditionalTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType1 : cellTypes) { + for (ShortTruthTableCellType cellType2 : cellTypes) { + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell aubergine = board.getCell(0, 0); + ShortTruthTableCell boniato = board.getCell(2, 0); + + aubergine.setData(cellType1); + boniato.setData(cellType2); + + board.addModifiedData(aubergine); + board.addModifiedData(boniato); + + if (cellType1 == ShortTruthTableCellType.TRUE && cellType2 == ShortTruthTableCellType.FALSE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + } + + /** + * Given one statement: A -> B where -> is false + * + * Asserts that this is a valid application of the rule if and only if A + * is set to true. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseConditionalTrueATest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell aubergine = board.getCell(0, 0); + + aubergine.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(aubergine); + Assert.assertNull(RULE.checkRule(transition)); + + aubergine.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(aubergine); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A -> B where -> is false + * + * Asserts that this is a valid application of the rule if and only if B is + * set to false. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseConditionalFalseBTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell boniato = board.getCell(2, 0); + + boniato.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(boniato); + Assert.assertNull(RULE.checkRule(transition)); + + boniato.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(boniato); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A -> B where -> is true + * + * Asserts that you cannot set any combination of both A and B at the same time. + * + * @throws InvalidFileFormatException + */ + @Test + public void CannotSetBothAandBTrueConditionalTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType1 : cellTypes) { + for (ShortTruthTableCellType cellType2 : cellTypes) { + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell aubergine = board.getCell(0, 0); + ShortTruthTableCell boniato = board.getCell(2, 0); + + aubergine.setData(cellType1); + boniato.setData(cellType2); + + board.addModifiedData(aubergine); + board.addModifiedData(boniato); + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + + /** + * Given one statement: A -> B where A and -> are true + * + * Asserts that this is a valid application of this rule if and only if B + * is set to true. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueAMeansTrueBTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell boniato = board.getCell(2, 0); + + boniato.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(boniato); + Assert.assertNull(RULE.checkRule(transition)); + + boniato.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(boniato); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A -> B where B is false and -> is true + * + * Asserts that this is a valid application of this rule if and only if A + * is set to false. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseBMeansFalseATest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell aubergine = board.getCell(0, 0); + + aubergine.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(aubergine); + Assert.assertNull(RULE.checkRule(transition)); + + aubergine.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(aubergine); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: A -> B where B and -> are true + * + * Asserts that this is not a valid application of this rule no matter what + * A is set to. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueBCannotDetermineA() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell boniato = board.getCell(2, 0); + + boniato.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(boniato); + Assert.assertNotNull(RULE.checkRule(transition)); + + boniato.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(boniato); + Assert.assertNotNull(RULE.checkRule(transition)); + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java new file mode 100644 index 000000000..6dbbf141c --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/NotEliminationTest.java @@ -0,0 +1,124 @@ +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.basic.elimination.DirectRuleNotElimination; +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 NotEliminationTest { + private static final DirectRuleNotElimination RULE = new DirectRuleNotElimination(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given one statement: ¬A where ¬ is false + * + * Asserts that this is a valid application of this rule if and only if A is true + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseNot() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType : cellTypes) { + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell a = board.getCell(1, 0); + a.setData(cellType); + board.addModifiedData(a); + + if (cellType == ShortTruthTableCellType.TRUE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + + /** + * Given one statement: ¬A where ¬ is true + * + * Asserts that this is a valid application of this rule if and only if A is false + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueNot() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType : cellTypes) { + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell a = board.getCell(1, 0); + a.setData(cellType); + board.addModifiedData(a); + + if (cellType == ShortTruthTableCellType.FALSE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + +// /** +// * Given one statement: ¬A +// * +// * Asserts that setting both ¬ and A to any values would not be a valid +// * application of this rule +// * +// * @throws InvalidFileFormatException +// */ +// @Test +// public void CannotSetBothAtOnceTest() throws InvalidFileFormatException { +// TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot", stt); +// TreeNode rootNode = stt.getTree().getRootNode(); +// TreeTransition transition = rootNode.getChildren().get(0); +// transition.setRule(RULE); +// +// ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.FALSE, ShortTruthTableCellType.UNKNOWN}; +// +// for (ShortTruthTableCellType cellType1 : cellTypes) { +// for (ShortTruthTableCellType cellType2 : cellTypes) { +// ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); +// ShortTruthTableCell not = board.getCell(0, 0); +// ShortTruthTableCell a = board.getCell(1, 0); +// +// not.setData(cellType1); +// a.setData(cellType2); +// +// board.addModifiedData(not); +// board.addModifiedData(a); +// +// System.out.println("TYPE1:" + cellType1); +// System.out.println("TYPE2:" + cellType2); +// Assert.assertNotNull(RULE.checkRule(transition)); +// } +// } +// } +} \ No newline at end of file diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditional b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditional new file mode 100644 index 000000000..5ea1c8a63 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditional @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA new file mode 100644 index 000000000..1f956a743 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseA @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB new file mode 100644 index 000000000..49fd4f49f --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithFalseB @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA new file mode 100644 index 000000000..000a07d91 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueA @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB new file mode 100644 index 000000000..18cbd4156 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/FalseBiconditionalWithTrueB @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional new file mode 100644 index 000000000..cbf64468f --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditional @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA new file mode 100644 index 000000000..9655bc7ae --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseA @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB new file mode 100644 index 000000000..032fc23df --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithFalseB @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA new file mode 100644 index 000000000..44381c235 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueA @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB new file mode 100644 index 000000000..8e42c0032 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalEliminationDirectRule/TrueBiconditionalWithTrueB @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional new file mode 100644 index 000000000..2da458f51 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/FalseConditional @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional new file mode 100644 index 000000000..829861f75 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditional @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB new file mode 100644 index 000000000..85e42664a --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithFalseB @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA new file mode 100644 index 000000000..d77a27502 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueA @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB new file mode 100644 index 000000000..86b10a7cc --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalEliminationDirectRule/TrueConditionalWithTrueB @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot b/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot new file mode 100644 index 000000000..e7bf96e4a --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/BlankNot @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot b/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot new file mode 100644 index 000000000..2e9ac998d --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/FalseNot @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot b/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot new file mode 100644 index 000000000..6f19fc871 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/NotEliminationDirectRule/TrueNot @@ -0,0 +1,13 @@ + + + + + + + + + + + + +