From 8b69f1b3fedfab8453be59a6a1278f4f37ab629a Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Fri, 29 Sep 2023 22:04:48 -0400 Subject: [PATCH 01/12] New Nurikabe unit test Wrote a new unit test for the Nurikabe black square contradiction rule. --- .idea/codeStyles/codeStyleConfig.xml | 2 +- .../CannotFillMiddle | 0 .../LightInHorizontalPath | 18 +++++----- .../LightInVerticalPath | 18 +++++----- .../CannotFillCorners | 13 ------- .../CannotFillMiddle | 11 ------ .../BlockEnclosed | 13 ------- .../CompleteBoardBlockEnclosed | 15 -------- .../CornerBlockEnclosed | 11 ------ .../ManyBlocksEnclosed | 17 ---------- .../BlockEnclosed | 13 ------- .../CompleteBoardBlockEnclosed | 15 -------- .../CornerBlockEnclosed | 11 ------ .../ManyBlocksEnclosed | 17 ---------- .../BlackSquareContradictionRuleTest.java | 34 +++++++++++++++++++ .../CornerBlackSquare | 12 +++++++ 16 files changed, 65 insertions(+), 155 deletions(-) delete mode 100644 build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/CannotFillMiddle delete mode 100644 build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillCorners delete mode 100644 build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillMiddle delete mode 100644 build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/BlockEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CompleteBoardBlockEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CornerBlockEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/ManyBlocksEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed delete mode 100644 build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed create mode 100644 src/test/resources/puzzles/nurikabe/rules/BlackSquareContradictionRule/CornerBlackSquare diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index a55e7a179..f23d52492 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,5 @@ - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/CannotFillMiddle b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/CannotFillMiddle deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath index 633ccc80b..1b4926106 100644 --- a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath +++ b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath @@ -1,10 +1,10 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath index 70419c40c..48aa7010c 100644 --- a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath +++ b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath @@ -1,10 +1,10 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillCorners b/build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillCorners deleted file mode 100644 index 38b52f04d..000000000 --- a/build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillCorners +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillMiddle b/build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillMiddle deleted file mode 100644 index 44086f145..000000000 --- a/build/resources/test/puzzles/lightup/rules/CannotLightACellContradictionRule/CannotFillMiddle +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/BlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/BlockEnclosed deleted file mode 100644 index a57a2473e..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/BlockEnclosed +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CompleteBoardBlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CompleteBoardBlockEnclosed deleted file mode 100644 index f48d240f0..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CompleteBoardBlockEnclosed +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CornerBlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CornerBlockEnclosed deleted file mode 100644 index 1a9cd60d9..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/CornerBlockEnclosed +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/ManyBlocksEnclosed b/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/ManyBlocksEnclosed deleted file mode 100644 index 32200d831..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooFewBulbsContradictionRule/ManyBlocksEnclosed +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed deleted file mode 100644 index c5760aede..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/BlockEnclosed +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed deleted file mode 100644 index 88fb0a8f1..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CompleteBoardBlockEnclosed +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed deleted file mode 100644 index a9a8dc5a0..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/CornerBlockEnclosed +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed b/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed deleted file mode 100644 index e743862eb..000000000 --- a/build/resources/test/puzzles/lightup/rules/TooManyBulbsContradictionRule/ManyBlocksEnclosed +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java index 7c0a00dd5..5e1cb659c 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java @@ -25,6 +25,7 @@ public static void setUp() { nurikabe = new Nurikabe(); } + @Test public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/SimpleBlackSquare", nurikabe); @@ -53,4 +54,37 @@ public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFi } } } + + @Test + public void BlackSquareContradictionRule_CornerSquareTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/CornerBlackSquare",nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + System.out.println(transition.getRule().getRuleType()); + System.out.println(transition.getRule().getRuleID()); + + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeCell cell1 = board.getCell(0,0); + NurikabeCell cell2 = board.getCell(0,1); + NurikabeCell cell3 = board.getCell(1,0); + NurikabeCell cell4 = board.getCell(1,1); + + Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); + for(int i=0; i + + + + + + + + + + + \ No newline at end of file From 18d1ab64cd223aacab4ec583c9d447f49656182c Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Thu, 5 Oct 2023 11:03:46 -0400 Subject: [PATCH 02/12] Added test cases for Black Bottleneck rule Added two new test cases for the Black Bottleneck direct rule. The first test case checks whether bottlenecks can be successfully detected in a corner The second test case intuitively looks like a bottleneck, but is not actually a bottleneck. This is to avoid false positives. --- .../rules/BlackBottleNeckDirectRuleTest.java | 51 +++++++++++++++++++ .../CornerBottleNeck | 11 ++++ .../BlackBottleNeckDirectRule/FalseBottleNeck | 11 ++++ 3 files changed, 73 insertions(+) create mode 100644 src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck create mode 100644 src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java index 91dcec802..8ce3db968 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java @@ -54,4 +54,55 @@ public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileF } } } + @Test + public void BlackBottleNeckDirectRule_CornerBottleneck() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeCell cell = board.getCell(0,1); + cell.setData(NurikabeType.BLACK.toValue()); + + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++){ + for(int k = 0; k < board.getWidth(); k++){ + Point point = new Point(k, i); + if(point.equals(cell.getLocation())){ + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + @Test + public void BlackBottleNeckDirectRule_FalseBottleneck() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeCell cell = board.getCell(0,1); + cell.setData(NurikabeType.BLACK.toValue()); + + board.addModifiedData(cell); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for(int i = 0; i < board.getHeight(); i++){ + for(int k = 0; k < board.getWidth(); k++){ + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } } + + diff --git a/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck b/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck new file mode 100644 index 000000000..a9065ea9d --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck b/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck new file mode 100644 index 000000000..3e3d7610a --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From f05479d3d4ee89e01fa35d2f840ae80789acb6d2 Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Thu, 5 Oct 2023 11:40:00 -0400 Subject: [PATCH 03/12] Added comments and fixed black square corner test case Added comments to the various test cases, and fixed the corner test for the black square contradiction rule. --- .../rules/BlackBottleNeckDirectRuleTest.java | 12 ++++++++++++ .../BlackSquareContradictionRuleTest.java | 19 ++++++++++--------- .../CornerBlackSquare | 8 ++++---- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java index 8ce3db968..3fe58d164 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBottleNeckDirectRuleTest.java @@ -27,6 +27,9 @@ public static void setUp() { nurikabe = new Nurikabe(); } + /** + * Tests the Black BottleNeck direct rule for a bottleneck in the center of the board + */ @Test public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck", nurikabe); @@ -54,6 +57,11 @@ public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileF } } } + + + /** + * Tests the Black BottleNeck direct rule for a bottleneck in the corner of the board + */ @Test public void BlackBottleNeckDirectRule_CornerBottleneck() throws InvalidFileFormatException{ TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck", nurikabe); @@ -82,6 +90,10 @@ public void BlackBottleNeckDirectRule_CornerBottleneck() throws InvalidFileForma } } + + /** + * Tests the Black BottleNeck direct rule for a false bottleneck + */ @Test public void BlackBottleNeckDirectRule_FalseBottleneck() throws InvalidFileFormatException{ TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck", nurikabe); diff --git a/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java index 5e1cb659c..f688918e8 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackSquareContradictionRuleTest.java @@ -25,7 +25,9 @@ public static void setUp() { nurikabe = new Nurikabe(); } - + /** + * Tests the Black Square contradiction rule for a black square in the middle of the board + */ @Test public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/SimpleBlackSquare", nurikabe); @@ -55,29 +57,28 @@ public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFi } } + /** + * Tests the Black Square contradiction rule for a square in the corner of the board + */ @Test public void BlackSquareContradictionRule_CornerSquareTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/CornerBlackSquare",nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - System.out.println(transition.getRule().getRuleType()); - System.out.println(transition.getRule().getRuleID()); NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - NurikabeCell cell1 = board.getCell(0,0); - NurikabeCell cell2 = board.getCell(0,1); - NurikabeCell cell3 = board.getCell(1,0); - NurikabeCell cell4 = board.getCell(1,1); + NurikabeCell cell1 = board.getCell(2,2); + NurikabeCell cell2 = board.getCell(2,3); + NurikabeCell cell3 = board.getCell(3,2); + NurikabeCell cell4 = board.getCell(3,3); Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); for(int i=0; i - - - - + + + + From e8fce28332c5cc3da49a9c67d75dc3f4b7c793fe Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Fri, 13 Oct 2023 16:37:57 -0400 Subject: [PATCH 04/12] remainder of the tests for the nurikabe contradiction rules This commit contains the remainder of the unit tests for the Nurikabe contradiction rules, with the corresponding board files and appropriate comments --- .../IsolateBlackContradictionRuleTest.java | 75 +++++++++++++----- .../MultipleNumbersContradictionRuleTest.java | 24 ++++++ .../rules/NoNumbersContradictionRuleTest.java | 7 +- .../TooFewSpacesContradictionRuleTest.java | 34 ++++++++ .../TooManySpacesContradictionRuleTest.java | 24 ++++++ ...achableWhiteCellContradictionRuleTest.java | 79 +++++++++++++++++++ .../DiagonalIsolateBlack | 15 ++++ .../FalseContradiction | 16 ++++ .../InsufficientSpace | 17 ++++ .../ExtraDiagonalSpace | 14 ++++ .../AllCellsReachable | 13 +++ .../SimpleUnreachableTest | 10 +++ 12 files changed, 309 insertions(+), 19 deletions(-) create mode 100644 src/test/java/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRuleTest.java create mode 100644 src/test/resources/puzzles/nurikabe/rules/IsolateBlackContradictionRule/DiagonalIsolateBlack create mode 100644 src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/FalseContradiction create mode 100644 src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/InsufficientSpace create mode 100644 src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/ExtraDiagonalSpace create mode 100644 src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/AllCellsReachable create mode 100644 src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/SimpleUnreachableTest diff --git a/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java index 11a5e8f7d..ce578d853 100644 --- a/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/IsolateBlackContradictionRuleTest.java @@ -1,6 +1,7 @@ package puzzles.nurikabe.rules; import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; import legup.MockGameBoardFacade; import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; @@ -25,25 +26,63 @@ public static void setUp() { nurikabe = new Nurikabe(); } + /** + * Tests the Isolate Black contradiction rule for a black squares in the corner, separated by a diagonal of white squares + */ @Test public void IsolateBlackContradictionRule_SimpleIsolateBlackTest() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/nurikabe/rules/IsolateBlackContradictionRule/SimpleIsolateBlack", nurikabe); -// TreeNode rootNode = nurikabe.getTree().getRootNode(); -// TreeTransition transition = rootNode.getChildren().get(0); -// transition.setRule(RULE); -// -// Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); -// -// NurikabeBoard board = (NurikabeBoard)transition.getBoard(); -// for(int i = 0; i < board.getHeight(); i++) { -// for(int k = 0; k < board.getWidth(); k++) { -// Point point = new Point(k, i); -// if(point.equals(new Point(0, 0)) || point.equals(new Point(3, 3))) { -// Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } else { -// Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); -// } -// } -// } + TestUtilities.importTestBoard("puzzles/nurikabe/rules/IsolateBlackContradictionRule/SimpleIsolateBlack", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeCell cell1 = board.getCell(0,0); + NurikabeCell cell2 = board.getCell(2,2); + + Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + + for(int i=0; i + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/FalseContradiction b/src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/FalseContradiction new file mode 100644 index 000000000..0f14d6916 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/FalseContradiction @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/InsufficientSpace b/src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/InsufficientSpace new file mode 100644 index 000000000..22163947a --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/InsufficientSpace @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/ExtraDiagonalSpace b/src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/ExtraDiagonalSpace new file mode 100644 index 000000000..5d9ad70e1 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/ExtraDiagonalSpace @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/AllCellsReachable b/src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/AllCellsReachable new file mode 100644 index 000000000..dbc5fadb2 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/AllCellsReachable @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/SimpleUnreachableTest b/src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/SimpleUnreachableTest new file mode 100644 index 000000000..3d456bdb0 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/UnreachableWhiteCellContradictionRule/SimpleUnreachableTest @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file From ee2feaad4f29a48ddf6fb9b9ae62f68afa4829e4 Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Fri, 20 Oct 2023 17:10:49 -0400 Subject: [PATCH 05/12] Finished Nurikabe test cases This commit includes all the finished Nurikabe test cases, including direct rules and the case rule. Comments have been added where appropriate. No significant change was made in some classes. --- .../BlackBetweenRegionsDirectRuleTest.java | 12 +++ .../rules/BlackOrWhiteCaseRuleTest.java | 5 +- .../rules/CannotReachCellDirectRuleTest.java | 94 +++++++++++++++++++ .../rules/CornerBlackDirectRuleTest.java | 3 + .../rules/FillinBlackDirectRuleTest.java | 63 +++++++++++++ .../rules/FillinWhiteDirectRuleTest.java | 61 ++++++++++++ .../PreventBlackSquareDirectRuleTest.java | 12 +++ .../rules/SurroundRegionDirectRuleTest.java | 6 ++ .../rules/WhiteBottleNeckDirectRuleTest.java | 6 ++ .../BlackOrWhiteCaseRule/SimpleBlackOrWhite | 13 +++ .../AllCellsReachable | 11 +++ .../SimpleUnreachableCell | 9 ++ .../rules/FillinBlackDirectRule/CornerBlack1 | 10 ++ .../rules/FillinBlackDirectRule/CornerBlack2 | 10 ++ .../rules/FillinWhiteDirectRule/CornerWhite1 | 11 +++ .../rules/FillinWhiteDirectRule/CornerWhite2 | 11 +++ 16 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 src/test/java/puzzles/nurikabe/rules/CannotReachCellDirectRuleTest.java create mode 100644 src/test/resources/puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite create mode 100644 src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/AllCellsReachable create mode 100644 src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/SimpleUnreachableCell create mode 100644 src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack1 create mode 100644 src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack2 create mode 100644 src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite1 create mode 100644 src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite2 diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java index b32ce23ce..a6652ea60 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java @@ -30,6 +30,9 @@ public static void setUp() { nurikabe = new Nurikabe(); } + /** + * Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from top left to bottom right) + */ @Test public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions1", nurikabe); @@ -62,6 +65,9 @@ public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() thr } } + /** + * Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from bottom left to top right) + */ @Test public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions2", nurikabe); @@ -94,6 +100,9 @@ public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() thr } } + /** + * Tests the Black Between Regions direct rule for regions that are horizontally opposite each other + */ @Test public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/HorizontalBlackBetweenRegions", nurikabe); @@ -123,6 +132,9 @@ public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() th } } + /** + * Tests the Black Between Regions direct rule for regions that are vertically opposite each other + */ @Test public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/VerticalBlackBetweenRegions", nurikabe); diff --git a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java index d270204ac..0b851be5c 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java @@ -25,9 +25,12 @@ public static void setUp() { nurikabe = new Nurikabe(); } + /** + * Tests the Black Or White case rule + */ @Test public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe); + TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite", nurikabe); TreeNode rootNode = nurikabe.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); diff --git a/src/test/java/puzzles/nurikabe/rules/CannotReachCellDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/CannotReachCellDirectRuleTest.java new file mode 100644 index 000000000..267f57f6d --- /dev/null +++ b/src/test/java/puzzles/nurikabe/rules/CannotReachCellDirectRuleTest.java @@ -0,0 +1,94 @@ +package puzzles.nurikabe.rules; + +import legup.MockGameBoardFacade; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.Assert; +import edu.rpi.legup.puzzle.nurikabe.Nurikabe; +import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.puzzle.nurikabe.rules.CannotReachCellDirectRule; +import edu.rpi.legup.save.InvalidFileFormatException; +import legup.TestUtilities; +import edu.rpi.legup.model.tree.TreeNode; +import edu.rpi.legup.model.tree.TreeTransition; +import java.awt.*; + +public class CannotReachCellDirectRuleTest { + + private static final CannotReachCellDirectRule RULE = new CannotReachCellDirectRule(); + private static Nurikabe nurikabe; + + @BeforeClass + public static void setUp() { + MockGameBoardFacade.getInstance(); + nurikabe = new Nurikabe(); + } + + /** + * Tests the Cannot Reach Cell direct rule for a simple unreachable cell + */ + @Test + public void CannotReachCellDirectRule_SimpleUnreachableCell() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/nurikabe/rules/CannotReachCellDirectRule/SimpleUnreachableCell", nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + + NurikabeBoard board = (NurikabeBoard)transition.getBoard(); + NurikabeCell cell = board.getCell(0,0); + cell.setData(NurikabeType.BLACK.toValue()); + board.addModifiedData(cell); + + Assert.assertNull(RULE.checkRule(transition)); + + for(int i=0; i + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/AllCellsReachable b/src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/AllCellsReachable new file mode 100644 index 000000000..63e38d25f --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/AllCellsReachable @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/SimpleUnreachableCell b/src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/SimpleUnreachableCell new file mode 100644 index 000000000..e11487564 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/CannotReachCellDirectRule/SimpleUnreachableCell @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack1 b/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack1 new file mode 100644 index 000000000..ae078229e --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack1 @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack2 b/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack2 new file mode 100644 index 000000000..f274fc774 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/CornerBlack2 @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite1 b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite1 new file mode 100644 index 000000000..de0ca4f71 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite1 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite2 b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite2 new file mode 100644 index 000000000..9fc228483 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/CornerWhite2 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From a6932d5ce81fb3c15044f7d8b79c8b4ff0f6bcf9 Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Fri, 27 Oct 2023 17:56:54 -0400 Subject: [PATCH 06/12] Complete rewrite of case rule test and some minor changes This commit includes a complete rewite of the case rule to test that it creates the number of children required in a correct manner. It also includes minor changes to some other tests. --- bin/main/edu/rpi/legup/log4j2.properties | 28 ++++++------- .../rules/BlackOrWhiteCaseRuleTest.java | 40 +++++++++++-------- .../MultipleNumbersContradictionRuleTest.java | 33 +++++++++++++++ .../TooFewSpacesContradictionRuleTest.java | 2 +- .../CornerBottleNeck | 2 +- .../BlackOrWhiteCaseRule/SimpleBlackOrWhite | 5 --- .../ComplexRegion | 19 +++++++++ 7 files changed, 92 insertions(+), 37 deletions(-) create mode 100644 src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/ComplexRegion diff --git a/bin/main/edu/rpi/legup/log4j2.properties b/bin/main/edu/rpi/legup/log4j2.properties index de1fa02ed..4f2556c2d 100644 --- a/bin/main/edu/rpi/legup/log4j2.properties +++ b/bin/main/edu/rpi/legup/log4j2.properties @@ -1,15 +1,15 @@ -# Logging level -# Root logger option -log4j.rootLogger=DEBUG, stdout, file -# Redirect log messages to console -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -# Redirect log messages to a log file, support file rolling. -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=Legup.log -log4j.appender.file.MaxFileSize=5MB -log4j.appender.file.MaxBackupIndex=10 -log4j.appender.file.layout=org.apache.log4j.PatternLayout +# Logging level +# Root logger option +log4j.rootLogger=DEBUG, stdout, file +# Redirect log messages to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n +# Redirect log messages to a log file, support file rolling. +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=Legup.log +log4j.appender.file.MaxFileSize=5MB +log4j.appender.file.MaxBackupIndex=10 +log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java index 0b851be5c..7c802ff78 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java @@ -1,6 +1,10 @@ package puzzles.nurikabe.rules; +import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard; +import edu.rpi.legup.puzzle.nurikabe.NurikabeCell; +import edu.rpi.legup.puzzle.nurikabe.NurikabeType; +import edu.rpi.legup.puzzle.nurikabe.rules.BlackOrWhiteCaseRule; import legup.MockGameBoardFacade; import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; @@ -12,11 +16,13 @@ import edu.rpi.legup.puzzle.nurikabe.rules.TooFewSpacesContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; + import java.awt.*; public class BlackOrWhiteCaseRuleTest { - private static final TooFewSpacesContradictionRule RULE = new TooFewSpacesContradictionRule(); + private static final BlackOrWhiteCaseRule RULE = new BlackOrWhiteCaseRule(); private static Nurikabe nurikabe; @BeforeClass @@ -26,7 +32,7 @@ public static void setUp() { } /** - * Tests the Black Or White case rule + * Tests the Black Or White case rule by ensuring that it results in two children, that contain a modified cell that is either black or white */ @Test public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException { @@ -35,20 +41,22 @@ public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidF TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); - Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard())); - NurikabeBoard board = (NurikabeBoard) transition.getBoard(); - Point location = new Point(1, 1); - for (int i = 0; i < board.getHeight(); i++) { - for (int k = 0; k < board.getWidth(); k++) { - Point point = new Point(k, i); - if (point.equals(location)) { - Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); - } - } - } + NurikabeCell cell = board.getCell(0,0); + ArrayList cases = RULE.getCases(board,cell); + + Assert.assertEquals(2,cases.size()); + + NurikabeBoard caseBoard = (NurikabeBoard) cases.get(0); + NurikabeBoard caseBoard2 = (NurikabeBoard) cases.get(1); + + Integer v1 = new Integer(0); + Integer v2 = new Integer(-1); + + Assert.assertTrue((caseBoard.getCell(0,0).getData().equals(v1) || caseBoard.getCell(0,0).equals(v2)) && + (caseBoard2.getCell(0,0).getData().equals(v1) || caseBoard2.getCell(0,0).getData().equals(v2))); + Assert.assertFalse(caseBoard.getCell(0,0).getData().equals(caseBoard2.getCell(0,0).getData())); + + } } diff --git a/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java b/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java index 56ada91d0..67995bffc 100644 --- a/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/MultipleNumbersContradictionRuleTest.java @@ -52,6 +52,38 @@ public void MultipleNumbersContradictionRule_TwoSurroundBlackTest() throws Inval } } + /** + * Tests the Multiple Numbers contradiction rule for a more complex regions with multiple numbers + */ + @Test + public void MultipleNumbersContradictionRule_ComplexRegion() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/nurikabe/rules/MultipleNumbersContradictionRule/ComplexRegion",nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeCell cell1 = board.getCell(0,0); + NurikabeCell cell2 = board.getCell(2,0); + NurikabeCell cell3 = board.getCell(4,0); + NurikabeCell cell4 = board.getCell(2,3); + NurikabeCell cell5 = board.getCell(4,4); + + Assert.assertNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard())); + for(int i=0; i - + diff --git a/src/test/resources/puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite b/src/test/resources/puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite index b30f64b75..fb5e45218 100644 --- a/src/test/resources/puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite +++ b/src/test/resources/puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite @@ -2,11 +2,6 @@ - - - - - diff --git a/src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/ComplexRegion b/src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/ComplexRegion new file mode 100644 index 000000000..5f8e607fe --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/MultipleNumbersContradictionRule/ComplexRegion @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 851ffaf5ea70e46b401075a64a95a62a32b27669 Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Tue, 31 Oct 2023 16:26:44 -0400 Subject: [PATCH 07/12] Minor addition to case rule Made a minor addition to the case rule to make it more comprehensive - testing the equality of the non-modified cells, and the relative sizes of the all the boards. --- .../nurikabe/rules/BlackOrWhiteCaseRuleTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java index 7c802ff78..55001e6d2 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java @@ -57,6 +57,19 @@ public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidF (caseBoard2.getCell(0,0).getData().equals(v1) || caseBoard2.getCell(0,0).getData().equals(v2))); Assert.assertFalse(caseBoard.getCell(0,0).getData().equals(caseBoard2.getCell(0,0).getData())); + Assert.assertEquals(caseBoard.getHeight(),caseBoard2.getHeight(), board.getHeight()); + Assert.assertEquals(caseBoard.getWidth(),caseBoard2.getWidth(), board.getWidth()); + + for(int i=0; i Date: Fri, 3 Nov 2023 17:28:11 -0400 Subject: [PATCH 08/12] deleted build folder --- .../BulbsInPathContradictionRule/BlockInVerticalPath | 11 ----------- .../LightInHorizontalPath | 10 ---------- .../BulbsInPathContradictionRule/LightInVerticalPath | 10 ---------- 3 files changed, 31 deletions(-) delete mode 100644 build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInVerticalPath delete mode 100644 build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath delete mode 100644 build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath diff --git a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInVerticalPath b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInVerticalPath deleted file mode 100644 index 5f27b3ec8..000000000 --- a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/BlockInVerticalPath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath deleted file mode 100644 index 1b4926106..000000000 --- a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInHorizontalPath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath b/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath deleted file mode 100644 index 48aa7010c..000000000 --- a/build/resources/test/puzzles/lightup/rules/BulbsInPathContradictionRule/LightInVerticalPath +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file From 9ac7253f2b35a65af08597e09f0ad91e9dda1b9e Mon Sep 17 00:00:00 2001 From: Relurk1 Date: Tue, 14 Nov 2023 16:55:34 -0500 Subject: [PATCH 09/12] Changes and additions to test suite This commit includes: - A change for readability made in the case rule, replacing Integer objects with NurikabeType - Adding false test cases where necessary - Updating test cases where necessary --- .../BlackBetweenRegionsDirectRuleTest.java | 24 +++++++++++++++ .../rules/BlackOrWhiteCaseRuleTest.java | 10 +++---- .../BlackSquareContradictionRuleTest.java | 22 +++++++++++++- .../rules/CornerBlackDirectRuleTest.java | 30 +++++++++++++++++-- .../rules/FillinBlackDirectRuleTest.java | 23 ++++++++++++++ .../rules/FillinWhiteDirectRuleTest.java | 26 ++++++++++++++++ .../IsolateBlackContradictionRuleTest.java | 22 +++++++++++++- .../rules/NoNumbersContradictionRuleTest.java | 26 +++++++++++++--- .../PreventBlackSquareDirectRuleTest.java | 20 +++++++++++++ .../rules/SurroundRegionDirectRuleTest.java | 22 ++++++++++++++ .../TooFewSpacesContradictionRuleTest.java | 23 ++++++++++++++ .../TooManySpacesContradictionRuleTest.java | 25 ++++++++++++++++ .../rules/WhiteBottleNeckDirectRuleTest.java | 26 ++++++++++++++++ .../FalseBlackBetweenRegions | 13 ++++++++ .../FalseBlackSquare | 11 +++++++ .../CornerBlackDirectRule/FalseCornerBlack | 12 ++++++++ .../FillinBlackDirectRule/FalseFillinBlack | 12 ++++++++ .../FillinWhiteDirectRule/FalseFillinWhite | 12 ++++++++ .../FalseIsolateBlack | 10 +++++++ .../{NoNumberReachable => FalseNoNumber} | 0 .../NoNumberContradictionRule/FalseNoNumber2 | 18 +++++++++++ .../{NoNumberSurroundBlack => SimpleNoNumber} | 0 .../FalseBlackSquare | 10 +++++++ .../FalseSurroundRegion | 10 +++++++ .../FalseTooFewSpaces | 17 +++++++++++ .../MultipleNumberRegion | 11 +++++++ .../WhiteBottleNeckDirectRule/FalseBottleNeck | 11 +++++++ 27 files changed, 432 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/FalseBlackBetweenRegions create mode 100644 src/test/resources/puzzles/nurikabe/rules/BlackSquareContradictionRule/FalseBlackSquare create mode 100644 src/test/resources/puzzles/nurikabe/rules/CornerBlackDirectRule/FalseCornerBlack create mode 100644 src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/FalseFillinBlack create mode 100644 src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/FalseFillinWhite create mode 100644 src/test/resources/puzzles/nurikabe/rules/IsolateBlackContradictionRule/FalseIsolateBlack rename src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/{NoNumberReachable => FalseNoNumber} (100%) create mode 100644 src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber2 rename src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/{NoNumberSurroundBlack => SimpleNoNumber} (100%) create mode 100644 src/test/resources/puzzles/nurikabe/rules/PreventBlackSquareDirectRule/FalseBlackSquare create mode 100644 src/test/resources/puzzles/nurikabe/rules/SurroundRegionDirectRule/FalseSurroundRegion create mode 100644 src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/FalseTooFewSpaces create mode 100644 src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/MultipleNumberRegion create mode 100644 src/test/resources/puzzles/nurikabe/rules/WhiteBottleNeckDirectRule/FalseBottleNeck diff --git a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java index a6652ea60..7e8b5eb83 100644 --- a/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java +++ b/src/test/java/puzzles/nurikabe/rules/BlackBetweenRegionsDirectRuleTest.java @@ -163,4 +163,28 @@ public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() thro } } } + + /** + * Tests the Black Between Regions direct rule for a false application of the rule, where a black tile is enclosed by one region + */ + @Test + public void BlackBetweenRegionsDirectRule_FalseBlackBetweenRegionsTest() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/FalseBlackBetweenRegions",nurikabe); + TreeNode rootNode = nurikabe.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + NurikabeBoard board = (NurikabeBoard) transition.getBoard(); + NurikabeCell cell = board.getCell(1,1); + cell.setData(NurikabeType.BLACK.toValue()); + board.addModifiedData(cell); + + Assert.assertNotNull(RULE.checkRule(transition)); + + for(int i=0; i + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/BlackSquareContradictionRule/FalseBlackSquare b/src/test/resources/puzzles/nurikabe/rules/BlackSquareContradictionRule/FalseBlackSquare new file mode 100644 index 000000000..813114443 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/BlackSquareContradictionRule/FalseBlackSquare @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/CornerBlackDirectRule/FalseCornerBlack b/src/test/resources/puzzles/nurikabe/rules/CornerBlackDirectRule/FalseCornerBlack new file mode 100644 index 000000000..0599fdfa4 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/CornerBlackDirectRule/FalseCornerBlack @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/FalseFillinBlack b/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/FalseFillinBlack new file mode 100644 index 000000000..731e2dc74 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/FillinBlackDirectRule/FalseFillinBlack @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/FalseFillinWhite b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/FalseFillinWhite new file mode 100644 index 000000000..f2599c71f --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/FillinWhiteDirectRule/FalseFillinWhite @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/IsolateBlackContradictionRule/FalseIsolateBlack b/src/test/resources/puzzles/nurikabe/rules/IsolateBlackContradictionRule/FalseIsolateBlack new file mode 100644 index 000000000..b4eb09302 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/IsolateBlackContradictionRule/FalseIsolateBlack @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberReachable b/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber similarity index 100% rename from src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberReachable rename to src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber diff --git a/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber2 b/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber2 new file mode 100644 index 000000000..be1fc64f7 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber2 @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberSurroundBlack b/src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/SimpleNoNumber similarity index 100% rename from src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberSurroundBlack rename to src/test/resources/puzzles/nurikabe/rules/NoNumberContradictionRule/SimpleNoNumber diff --git a/src/test/resources/puzzles/nurikabe/rules/PreventBlackSquareDirectRule/FalseBlackSquare b/src/test/resources/puzzles/nurikabe/rules/PreventBlackSquareDirectRule/FalseBlackSquare new file mode 100644 index 000000000..2fd8e7d35 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/PreventBlackSquareDirectRule/FalseBlackSquare @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/SurroundRegionDirectRule/FalseSurroundRegion b/src/test/resources/puzzles/nurikabe/rules/SurroundRegionDirectRule/FalseSurroundRegion new file mode 100644 index 000000000..5e0b04f68 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/SurroundRegionDirectRule/FalseSurroundRegion @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/FalseTooFewSpaces b/src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/FalseTooFewSpaces new file mode 100644 index 000000000..ca3e9be84 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/TooFewSpacesContradictionRule/FalseTooFewSpaces @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/MultipleNumberRegion b/src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/MultipleNumberRegion new file mode 100644 index 000000000..3ec126199 --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/TooManySpacesContradictionRule/MultipleNumberRegion @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/nurikabe/rules/WhiteBottleNeckDirectRule/FalseBottleNeck b/src/test/resources/puzzles/nurikabe/rules/WhiteBottleNeckDirectRule/FalseBottleNeck new file mode 100644 index 000000000..521576aeb --- /dev/null +++ b/src/test/resources/puzzles/nurikabe/rules/WhiteBottleNeckDirectRule/FalseBottleNeck @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From 9a617456bca7e0e7de3b3fd3f932dd2a3553967a Mon Sep 17 00:00:00 2001 From: Charles Tian <46334090+charlestian23@users.noreply.github.com> Date: Tue, 28 Nov 2023 16:17:44 -0500 Subject: [PATCH 10/12] Or Elimination, Or Introduction, Not Introduction, and And Introduction Test Cases (#689) * 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 * Added or elimination puzzle files * Renamed directory These should be for Or Introduction, not Or Elimination * Added Or Elimination files * Added FTU and UTF tests * More tests * Add Or Intro tests * Checkstyle fix * Spacing fix * Added not introduction test * Added And Introduction tests and modified Or Introduction tests --------- Co-authored-by: Ivan Ho <41582274+Corppet@users.noreply.github.com> --- .../rules/AndIntroductionDirectRuleTest.java | 105 ++++++++++++ .../rules/NotIntroductionTest.java | 122 ++++++++++++++ .../rules/OrEliminationTest.java | 150 ++++++++++++++++++ .../rules/OrIntroductionTest.java | 105 ++++++++++++ .../rules/AndIntroductionDirectRule/FUF | 14 ++ .../rules/AndIntroductionDirectRule/FUT | 14 ++ .../rules/AndIntroductionDirectRule/FUU | 13 ++ .../rules/AndIntroductionDirectRule/TUF | 14 ++ .../rules/AndIntroductionDirectRule/TUT | 14 ++ .../rules/AndIntroductionDirectRule/TUU | 13 ++ .../rules/AndIntroductionDirectRule/UUF | 13 ++ .../rules/AndIntroductionDirectRule/UUT | 13 ++ .../rules/AndIntroductionDirectRule/UUU | 12 ++ .../rules/NotIntroductionDirectRule/BlankA | 12 ++ .../rules/NotIntroductionDirectRule/FalseA | 13 ++ .../rules/NotIntroductionDirectRule/TrueA | 13 ++ .../rules/OrEliminationDirectRule/FTU | 14 ++ .../rules/OrEliminationDirectRule/UFU | 13 ++ .../rules/OrEliminationDirectRule/UTF | 14 ++ .../rules/OrEliminationDirectRule/UTU | 13 ++ .../rules/OrIntroductionDirectRule/FUF | 14 ++ .../rules/OrIntroductionDirectRule/FUT | 14 ++ .../rules/OrIntroductionDirectRule/FUU | 13 ++ .../rules/OrIntroductionDirectRule/TUF | 14 ++ .../rules/OrIntroductionDirectRule/TUT | 14 ++ .../rules/OrIntroductionDirectRule/TUU | 13 ++ .../rules/OrIntroductionDirectRule/UUF | 13 ++ .../rules/OrIntroductionDirectRule/UUT | 13 ++ .../rules/OrIntroductionDirectRule/UUU | 12 ++ 29 files changed, 814 insertions(+) create mode 100644 src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java create mode 100644 src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java create mode 100644 src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java create mode 100644 src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/BlankA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUU create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUF create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUT create mode 100644 src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUU diff --git a/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java b/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java new file mode 100644 index 000000000..4d4e009b2 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/AndIntroductionDirectRuleTest.java @@ -0,0 +1,105 @@ +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.DirectRuleAndIntroduction; +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 AndIntroductionDirectRuleTest { + private static final DirectRuleAndIntroduction RULE = new DirectRuleAndIntroduction(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given a statement: A ^ B + * + * Asserts that if at least 1 of A or B is false, then this is a valid application + * of the rule if and only if ^ is false. + * + * @param filePath The file path for test board setup. + * @throws InvalidFileFormatException + */ + @Test + public void FalseAndTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/"; + falseAndTestHelper(path + "FUF"); + falseAndTestHelper(path + "FUU"); + falseAndTestHelper(path + "UUF"); + falseAndTestHelper(path + "FUT"); + falseAndTestHelper(path + "TUF"); + } + + 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 and = board.getCell(1, 0); + + and.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(and); + Assert.assertNotNull(RULE.checkRule(transition)); + + and.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(and); + Assert.assertNull(RULE.checkRule(transition)); + } + + /** + * Given a statement: A ^ B + * + * Asserts that setting ^ to true is a valid application of the rule if + * and only if both A and B are true. + * + * @param filePath The file path for test board setup. + * @throws InvalidFileFormatException + */ + @Test + public void FalseOrTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/AndIntroductionDirectRule/"; + String[] letters = {"T", "F", "U"}; + for (String first : letters) { + for (String second : letters) { + trueAndTestHelper(path + first + "U" + 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); + ShortTruthTableCell and = board.getCell(1, 0); + + and.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(and); + + if (a.getType() == ShortTruthTableCellType.TRUE && 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/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java new file mode 100644 index 000000000..a0a062ab3 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/NotIntroductionTest.java @@ -0,0 +1,122 @@ +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.DirectRuleNotIntroduction; +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 NotIntroductionTest { + private static final DirectRuleNotIntroduction RULE = new DirectRuleNotIntroduction(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given one statement: ¬A where A is false + * + * Asserts that this is a valid application of this rule if and only if ¬ is true + * + * @throws InvalidFileFormatException + */ + @Test + public void FalseNot() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA", 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 not = board.getCell(0, 0); + not.setData(cellType); + board.addModifiedData(not); + + if (cellType == ShortTruthTableCellType.TRUE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + + /** + * Given one statement: ¬A where A is true + * + * Asserts that this is a valid application of this rule if and only if ¬ is false + * + * @throws InvalidFileFormatException + */ + @Test + public void TrueNot() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA", 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 not = board.getCell(0, 0); + not.setData(cellType); + board.addModifiedData(not); + + 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/NotIntroductionDirectRule/BlankA", 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); + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java b/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java new file mode 100644 index 000000000..6cdd0d639 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/OrEliminationTest.java @@ -0,0 +1,150 @@ +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.DirectRuleOrElimination; +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 OrEliminationTest { + private static final DirectRuleOrElimination RULE = new DirectRuleOrElimination(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given a statement: A V B, where A is false and V is true + * + * Asserts that this is a valid application of the rule if and only if B is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void FTUTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell cell = board.getCell(2, 0); + + cell.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(cell); + Assert.assertNull(RULE.checkRule(transition)); + + cell.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(cell); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given a statement: A V B, where B is false and V is true + * + * Asserts that this is a valid application of the rule if and only if B is true. + * + * @throws InvalidFileFormatException + */ + @Test + public void UTFTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF", stt); + TreeNode rootNode = stt.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + ShortTruthTableBoard board = (ShortTruthTableBoard) transition.getBoard(); + ShortTruthTableCell cell = board.getCell(0, 0); + + cell.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(cell); + Assert.assertNull(RULE.checkRule(transition)); + + cell.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(cell); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given a statement: A V B, where V is false + * + * Asserts that this is a valid application of the rule if and only if both A + * and B are false. + * + * @throws InvalidFileFormatException + */ + @Test + public void UFUTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU", 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 a = board.getCell(0, 0); + ShortTruthTableCell b = board.getCell(2, 0); + + a.setData(cellType1); + b.setData(cellType2); + + board.addModifiedData(a); + board.addModifiedData(b); + + if (cellType1 == ShortTruthTableCellType.FALSE && cellType2 == ShortTruthTableCellType.FALSE) { + Assert.assertNull(RULE.checkRule(transition)); + } + else { + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } + } + + /** + * Given a statement: A V B, where V is true + * + * Asserts that setting both A and B is not a valid application of this rule. + * + * @throws InvalidFileFormatException + */ + @Test + public void UTUTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU", 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 a = board.getCell(0, 0); + ShortTruthTableCell b = board.getCell(2, 0); + + a.setData(cellType1); + b.setData(cellType2); + + board.addModifiedData(a); + board.addModifiedData(b); + + Assert.assertNotNull(RULE.checkRule(transition)); + } + } + } +} \ No newline at end of file diff --git a/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java b/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java new file mode 100644 index 000000000..13cb10d55 --- /dev/null +++ b/src/test/java/puzzles/shorttruthtable/rules/OrIntroductionTest.java @@ -0,0 +1,105 @@ +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.DirectRuleOrIntroduction; +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 OrIntroductionTest { + private static final DirectRuleOrIntroduction RULE = new DirectRuleOrIntroduction(); + private static ShortTruthTable stt; + + @BeforeClass + public static void setup() { + MockGameBoardFacade.getInstance(); + stt = new ShortTruthTable(); + } + + /** + * Given a statement: A V B + * + * Asserts that if at least 1 of A or B is true, then this is a valid application + * of the rule if and only if V is true. + * + * @param filePath The file path for test board setup. + * @throws InvalidFileFormatException + */ + @Test + public void TrueOrTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/OrIntroductionDirectRule/"; + trueOrTestHelper(path + "TUT"); + trueOrTestHelper(path + "TUU"); + trueOrTestHelper(path + "UUT"); + trueOrTestHelper(path + "TUF"); + trueOrTestHelper(path + "FUT"); + } + + private void trueOrTestHelper(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 or = board.getCell(1, 0); + + or.setData(ShortTruthTableCellType.TRUE); + board.addModifiedData(or); + Assert.assertNull(RULE.checkRule(transition)); + + or.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(or); + Assert.assertNotNull(RULE.checkRule(transition)); + } + + /** + * Given a statement: A V B + * + * Asserts that setting V to false is a valid application of the rule if + * and only if both A and B are false. + * + * @param filePath The file path for test board setup. + * @throws InvalidFileFormatException + */ + @Test + public void FalseOrTest() throws InvalidFileFormatException { + String path = "puzzles/shorttruthtable/rules/OrIntroductionDirectRule/"; + String[] letters = {"T", "F", "U"}; + for (String first : letters) { + for (String second : letters) { + falseOrTestHelper(path + first + "U" + second); + } + } + } + + private void falseOrTestHelper(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); + ShortTruthTableCell or = board.getCell(1, 0); + + or.setData(ShortTruthTableCellType.FALSE); + board.addModifiedData(or); + + if (a.getType() == ShortTruthTableCellType.FALSE && b.getType() == ShortTruthTableCellType.FALSE) { + 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/AndIntroductionDirectRule/FUF b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUF new file mode 100644 index 000000000..003792ec0 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUT b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUT new file mode 100644 index 000000000..05803b88d --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUU b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUU new file mode 100644 index 000000000..b97eafdfe --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/FUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUF b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUF new file mode 100644 index 000000000..fc10f77bb --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUT b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUT new file mode 100644 index 000000000..dc99e3cdc --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUU b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUU new file mode 100644 index 000000000..2c592ef86 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/TUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUF b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUF new file mode 100644 index 000000000..39b5fb079 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUF @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUT b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUT new file mode 100644 index 000000000..261c035cd --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUT @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUU b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUU new file mode 100644 index 000000000..d9f415439 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/AndIntroductionDirectRule/UUU @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/BlankA b/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/BlankA new file mode 100644 index 000000000..e7bf96e4a --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/BlankA @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA b/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA new file mode 100644 index 000000000..d4c178464 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/FalseA @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA b/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA new file mode 100644 index 000000000..7c4f71984 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/NotIntroductionDirectRule/TrueA @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU new file mode 100644 index 000000000..bda22c0e6 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/FTU @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU new file mode 100644 index 000000000..b7c23215e --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UFU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF new file mode 100644 index 000000000..60eaca2b8 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU new file mode 100644 index 000000000..c28ba1fde --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrEliminationDirectRule/UTU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUF b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUF new file mode 100644 index 000000000..2326f8df4 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUT b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUT new file mode 100644 index 000000000..447c91981 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUU b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUU new file mode 100644 index 000000000..083c30039 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/FUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUF b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUF new file mode 100644 index 000000000..ef36a432d --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUF @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUT b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUT new file mode 100644 index 000000000..05f65ad45 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUT @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUU b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUU new file mode 100644 index 000000000..d6e54b326 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/TUU @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUF b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUF new file mode 100644 index 000000000..5f69fb73f --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUF @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUT b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUT new file mode 100644 index 000000000..d7ef8cd88 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUT @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUU b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUU new file mode 100644 index 000000000..005a4f462 --- /dev/null +++ b/src/test/resources/puzzles/shorttruthtable/rules/OrIntroductionDirectRule/UUU @@ -0,0 +1,12 @@ + + + + + + + + + + + + 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 11/12] 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 @@ + + + + + + + + + + + + From ca9fef9d88f83e6885bf56b45221715f6b824b6d Mon Sep 17 00:00:00 2001 From: Jacob Long <123578010+jac-oblong@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:59:54 -0500 Subject: [PATCH 12/12] Fix treetent puzzle editor (#692) * fix treetent puzzle editor (add breaks for switch) (exporter exports same data that importer expects) * allow for treetent clue to go up/down * comply with checkstyles --------- Co-authored-by: Jacob Long Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> --- .../rpi/legup/model/gameboard/GridBoard.java | 37 ++++++++++++++++--- .../legup/puzzle/treetent/TreeTentCell.java | 16 ++++++++ .../puzzle/treetent/TreeTentCellFactory.java | 2 +- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java index 3e94c57ad..d31e8185a 100644 --- a/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java +++ b/src/main/java/edu/rpi/legup/model/gameboard/GridBoard.java @@ -71,15 +71,40 @@ public void setCell(int x, int y, Element e, MouseEvent m) { if (this instanceof TreeTentBoard && ((y == dimension.height && 0 <= x && x < dimension.width) || (x == dimension.width && 0 <= y && y < dimension.height))) { TreeTentBoard treeTentBoard = ((TreeTentBoard) this); TreeTentClue clue = treeTentBoard.getClue(x, y); - if (y == dimension.height && clue.getData() < dimension.width) { - clue.setData(clue.getData() + 1); + if (y == dimension.height) { + if (m.getButton() == MouseEvent.BUTTON1) { + if (clue.getData() < dimension.height) { + clue.setData(clue.getData() + 1); + } + else { + clue.setData(0); + } + } + else { + if (clue.getData() > 0) { + clue.setData(clue.getData() - 1); + } + else { + clue.setData(dimension.height); + } + } } - else { - if (x == dimension.width && clue.getData() < dimension.height) { - clue.setData(clue.getData() + 1); + else { //x == dimension.width + if (m.getButton() == MouseEvent.BUTTON1) { + if (clue.getData() < dimension.width) { + clue.setData(clue.getData() + 1); + } + else { + clue.setData(0); + } } else { - clue.setData(0); + if (clue.getData() > 0) { + clue.setData(clue.getData() - 1); + } + else { + clue.setData(dimension.width); + } } } } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java index 290e0858d..b6411a5cf 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCell.java @@ -16,15 +16,31 @@ public TreeTentType getType() { return data; } + public int getValue() { + switch (data) { + case TREE: + return 1; + case GRASS: + return 2; + case TENT: + return 3; + default: + return 0; + } + } + @Override public void setType(Element e, MouseEvent m) { switch (e.getElementName()) { case "Unknown Tile": this.data = TreeTentType.UNKNOWN; + break; case "Tree Tile": this.data = TreeTentType.TREE; + break; case "Grass Tile": this.data = TreeTentType.GRASS; + break; case "Tent Tile": this.data = TreeTentType.TENT; } diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java index 969ffdf0f..20b8066a4 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentCellFactory.java @@ -83,7 +83,7 @@ public org.w3c.dom.Element exportCell(Document document, PuzzleElement puzzleEle TreeTentCell cell = (TreeTentCell) puzzleElement; Point loc = cell.getLocation(); - cellElement.setAttribute("value", String.valueOf(cell.getData())); + cellElement.setAttribute("value", String.valueOf(cell.getValue())); cellElement.setAttribute("x", String.valueOf(loc.x)); cellElement.setAttribute("y", String.valueOf(loc.y));