From e858844dcf83d8508ba698f23447fbe11941e1ad Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Tue, 28 Nov 2023 16:18:11 -0500 Subject: [PATCH] Added Conditional Introduction and Biconditional Introduction tests (#693) * Added Conditional Intro files * Create ConditionalIntroductionTest.java * Added Biconditional Introduction tests --- .../rules/BiconditionalIntroductionTest.java | 118 ++++++++++++++++++ .../rules/ConditionalIntroductionTest.java | 110 ++++++++++++++++ .../BiconditionalIntroductionDirectRule/FUF | 14 +++ .../BiconditionalIntroductionDirectRule/FUT | 14 +++ .../BiconditionalIntroductionDirectRule/FUU | 13 ++ .../BiconditionalIntroductionDirectRule/TUF | 14 +++ .../BiconditionalIntroductionDirectRule/TUT | 14 +++ .../BiconditionalIntroductionDirectRule/TUU | 13 ++ .../BiconditionalIntroductionDirectRule/UUF | 13 ++ .../BiconditionalIntroductionDirectRule/UUT | 13 ++ .../BiconditionalIntroductionDirectRule/UUU | 12 ++ .../ConditionalIntroductionDirectRule/FUF | 14 +++ .../ConditionalIntroductionDirectRule/FUT | 14 +++ .../ConditionalIntroductionDirectRule/FUU | 13 ++ .../ConditionalIntroductionDirectRule/TUF | 14 +++ .../ConditionalIntroductionDirectRule/TUT | 14 +++ .../ConditionalIntroductionDirectRule/TUU | 13 ++ .../ConditionalIntroductionDirectRule/UUF | 13 ++ .../ConditionalIntroductionDirectRule/UUT | 13 ++ .../ConditionalIntroductionDirectRule/UUU | 12 ++ 20 files changed, 468 insertions(+) create mode 100644 src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java create mode 100644 src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUU diff --git a/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java new file mode 100644 index 000000000..fe2574b5e --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/BiconditionalIntroductionTest.java @@ -0,0 +1,118 @@ +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.introduction.DirectRuleBiconditionalIntroduction; +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 BiconditionalIntroductionTest { + private static final DirectRuleBiconditionalIntroduction RULE = new DirectRuleBiconditionalIntroduction(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given a statement: A <-> B + * + * Asserts that if setting <-> to false is a valid application of this rule if and + * only if A and B do not match. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseConditionalTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/"; + + String[] letters = {"T", "F", "U"}; + for (String a : letters) { + for (String b : letters) { + System.out.println(a + b); + falseConditionalHelper(path + a + "U" + b); + } + } + } + + private void falseConditionalHelper(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 conditional = board.getCell(1, 0); + + conditional.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(conditional); + + ShortTruthTableCell a = board.getCell(0, 0); + ShortTruthTableCell b = board.getCell(2, 0); + if (a.getType() != b.getType()) { + // Not valid if they don't match but at least one of the values of A or B is unknown + if (a.getType() == ShortTruthTableCellType.UNKNOWN || b.getType() == ShortTruthTableCellType.UNKNOWN) { + Assert.assertNotNull(RULE.checkRule(transition)); + } + else { + Assert.assertNull(RULE.checkRule(transition)); + } + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + + /** + * Given a statement: A <-> B + * + * Asserts that if setting <-> to true is a valid application of this rule if and + * only if A and B match. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueConditionalTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/"; + + String[] letters = {"T", "F", "U"}; + for (String a : letters) { + for (String b : letters) { + System.out.println(a + b); + trueConditionalHelper(path + a + "U" + b); + } + } + } + + private void trueConditionalHelper(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 conditional = board.getCell(1, 0); + + conditional.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(conditional); + + ShortTruthTableCell a = board.getCell(0, 0); + ShortTruthTableCell b = board.getCell(2, 0); + if (a.getType() == b.getType() && a.getType() != ShortTruthTableCellType.UNKNOWN) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java new file mode 100644 index 000000000..c1507eab1 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/ConditionalIntroductionTest.java @@ -0,0 +1,110 @@ +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.introduction.DirectRuleConditionalIntroduction; +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 ConditionalIntroductionTest { + private static final DirectRuleConditionalIntroduction RULE = new DirectRuleConditionalIntroduction(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given a statement: A -> B + * + * Asserts that if setting -> to false is a valid application of this rule if and + * only if A is true and B is false. + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseConditionalTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/"; + + String[] letters = {"T", "F", "U"}; + for (String a : letters) { + for (String b : letters) { + falseConditionalHelper(path + a + "U" + b); + } + } + } + + private void falseConditionalHelper(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 conditional = board.getCell(1, 0); + + conditional.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(conditional); + + ShortTruthTableCell a = board.getCell(0, 0); + ShortTruthTableCell b = board.getCell(2, 0); + if (a.getType() == ShortTruthTableCellType.TRUE && b.getType() == ShortTruthTableCellType.FALSE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + + /** + * Given a statement: A -> B + * + * Asserts that if setting -> to true is a valid application of this rule if and + * only if A is false or B is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueConditionalTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/"; + + String[] letters = {"T", "F", "U"}; + for (String a : letters) { + for (String b : letters) { + trueConditionalTestHelper(path + a + "U" + b); + } + } + } + + private void trueConditionalTestHelper(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 conditional = board.getCell(1, 0); + + conditional.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(conditional); + + ShortTruthTableCell a = board.getCell(0, 0); + ShortTruthTableCell b = board.getCell(2, 0); + if (a.getType() == ShortTruthTableCellType.FALSE || b.getType() == ShortTruthTableCellType.TRUE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } +} \ No newline at end of file diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUF b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUF new file mode 100644 index 000000000..817025f78 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUT b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUT new file mode 100644 index 000000000..4bb3cb635 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUU b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUU new file mode 100644 index 000000000..7ddeeb5c8 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/FUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUF b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUF new file mode 100644 index 000000000..fb40ff4d4 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUT b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUT new file mode 100644 index 000000000..6ce5ab64c --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUU b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUU new file mode 100644 index 000000000..9307de3ad --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/TUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUF b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUF new file mode 100644 index 000000000..c61474b96 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUF @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUT b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUT new file mode 100644 index 000000000..2dead7328 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUT @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUU b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUU new file mode 100644 index 000000000..04596d449 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/BiconditionalIntroductionDirectRule/UUU @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUF b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUF new file mode 100644 index 000000000..a2adf2297 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUT b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUT new file mode 100644 index 000000000..5b849c7ac --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUU b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUU new file mode 100644 index 000000000..48d5fd7c6 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/FUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUF b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUF new file mode 100644 index 000000000..480a409ef --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUT b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUT new file mode 100644 index 000000000..862ee1628 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUU b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUU new file mode 100644 index 000000000..79b97ba46 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/TUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUF b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUF new file mode 100644 index 000000000..e5c9c4c0d --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUF @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUT b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUT new file mode 100644 index 000000000..efe86b390 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUT @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUU b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUU new file mode 100644 index 000000000..b0aa8ba00 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/ConditionalIntroductionDirectRule/UUU @@ -0,0 +1,12 @@ + + + + + + + + + + + +