From 7e2b0c47a4f1c6ef6c647efccf4fed5df7f06799 Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:53:56 -0400 Subject: [PATCH] Merge pull request #672 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Merge branch 'dev' into stt-test-suite * Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG… * 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 * Merge branch 'dev' into stt-test-suite * Merge branch 'stt-test-suite' of https://github.com/charlestian23/LEG… * CHECKSTYLE * Merge branch 'dev' into stt-test-suite * Trying to make CheckStyle happy --- .../rules/AndEliminationDirectRuleTest.java | 204 ++++++++++++++++++ .../rules/AndEliminationDirectRule/FalseAnd | 13 ++ .../FalseAndWithKnownFalse | 14 ++ .../FalseAndWithKnownTrue | 14 ++ .../rules/AndEliminationDirectRule/TrueAnd | 13 ++ 5 files changed, 258 insertions(+) create mode 100644 src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd diff --git a/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java new file mode 100644 index 000000000..0d94eb672 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/AndEliminationDirectRuleTest.java @@ -0,0 +1,204 @@ +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.DirectRuleAndElimination; +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 AndEliminationDirectRuleTest { + private static final DirectRuleAndElimination RULE = new DirectRuleAndElimination(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given one statement: B^C where ^ is true + * + * Checks all possible combinations of true, false, and unknown for B and C + * except for where both B and C are true and asserts that each one of them + * is not a valid application of the rule. + * + * @throws InvalidFileFormatException + */ + @Test + public void trueAndTest1() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", 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) { + if (cellType1 == cellType2 && cellType1 == ShortTruthTableCellType.TRUE) { + continue; + } + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell bonnie = board.getCell(0, 0); + ShortTruthTableCell clyde = board.getCell(2, 0); + + if (cellType1 != ShortTruthTableCellType.UNKNOWN) { + bonnie.setData(cellType1); + board.addModifiedData(bonnie); + } + + if (cellType2 != ShortTruthTableCellType.UNKNOWN) { + clyde.setData(cellType2); + board.addModifiedData(clyde); + } + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + + /** + * Given one statement: B^C where ^ is true + * + * Checks all possible combinations of true and unknown for B and C + * except for where both B and C are unknown and asserts that each one + * of them is a valid application of the rule. + * + * @throws InvalidFileFormatException + */ + @Test + public void trueAndTest2() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableCellType[] cellTypes = {ShortTruthTableCellType.TRUE, ShortTruthTableCellType.UNKNOWN}; + + for (ShortTruthTableCellType cellType1 : cellTypes) { + for (ShortTruthTableCellType cellType2 : cellTypes) { + if (cellType1 == cellType2 && cellType1 == ShortTruthTableCellType.UNKNOWN) { + continue; + } + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell bonnie = board.getCell(0, 0); + ShortTruthTableCell clyde = board.getCell(2, 0); + + if (cellType1 != ShortTruthTableCellType.UNKNOWN) { + bonnie.setData(cellType1); + board.addModifiedData(bonnie); + } + + if (cellType2 != ShortTruthTableCellType.UNKNOWN) { + clyde.setData(cellType2); + board.addModifiedData(clyde); + } + + Assert.assertNull(RULE.checkRule(transition)); + } + } + } + + /** + * Given one statement: B^C where ^ is false + * + * Checks all possible combinations of true, false, and unknown for B and C + * and asserts that each one of them is not a valid application of the rule. + * + * @throws InvalidFileFormatException + */ + @Test + public void falseAndWithUnknownsTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd", 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 bonnie = board.getCell(0, 0); + ShortTruthTableCell clyde = board.getCell(2, 0); + + if (cellType1 != ShortTruthTableCellType.UNKNOWN) { + bonnie.setData(cellType1); + board.addModifiedData(bonnie); + } + + if (cellType2 != ShortTruthTableCellType.UNKNOWN) { + clyde.setData(cellType2); + board.addModifiedData(clyde); + } + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + + /** + * Given one statement: B^C where both B and ^ are false + * + * Asserts that this is not a valid application of the rule if C is set to + * either true or false. + * + * @throws InvalidFileFormatException + */ + @Test + public void falseAndWithKnownFalseTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + + ShortTruthTableCell clyde = board.getCell(2, 0); + clyde.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(clyde); + Assert.assertNotNull(RULE.checkRule(transition)); + + clyde.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(clyde); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given one statement: B^C where B is true and ^ is false + * + * Asserts that this is a valid application of the rule if and only if C is + * set to false. + * + * @throws InvalidFileFormatException + */ + @Test + public void falseAndWithKnownTrueTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + + ShortTruthTableCell clyde = board.getCell(2, 0); + clyde.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(clyde); + Assert.assertNotNull(RULE.checkRule(transition)); + + clyde.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(clyde); + Assert.assertNull(RULE.checkRule(transition)); + } +} \ No newline at end of file diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd new file mode 100644 index 000000000..f6f60abc3 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAnd @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse new file mode 100644 index 000000000..d8edf4a76 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownFalse @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue new file mode 100644 index 000000000..364d8faf6 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/FalseAndWithKnownTrue @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd new file mode 100644 index 000000000..307f6d14a --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndEliminationDirectRule/TrueAnd @@ -0,0 +1,13 @@ + + + + + + + + + + + + +