From 14b0750264664ca0c97b1b4dd32e29e91152dd85 Mon Sep 17 00:00:00 2001 From: Kevin-771 <70790256+Kevin-771@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:33:56 -0500 Subject: [PATCH] added TentOrGrassCaseRuleTests (#688) * added a test * added more to test * test * should work now * should work now --------- Co-authored-by: Charles Tian <46334090+charlestian23@users.noreply.github.com> --- src/test/java/legup/TestRunner.java | 5 +- .../rules/TentOrGrassCaseRuleTest.java | 51 +++++++++++++++---- .../rules/TentOrGrassCaseRule/TestPuzzle | 19 +++++++ 3 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle diff --git a/src/test/java/legup/TestRunner.java b/src/test/java/legup/TestRunner.java index 9d79c590e..3a74c4c61 100644 --- a/src/test/java/legup/TestRunner.java +++ b/src/test/java/legup/TestRunner.java @@ -42,8 +42,6 @@ public static void main(String[] args) { Result result12 = JUnitCore.runClasses(TooManyBulbsContradictionRuleTest.class); printTestResults(result12); - - //nurikabe tests Result result13 = JUnitCore.runClasses(BlackBetweenRegionsDirectRuleTest.class); printTestResults(result13); @@ -76,7 +74,6 @@ public static void main(String[] args) { Result result27 = JUnitCore.runClasses(WhiteBottleNeckDirectRuleTest.class); printTestResults(result27); - // Treetent Result result28 = JUnitCore.runClasses(EmptyFieldDirectRuleTest.class); printTestResults(result28); @@ -94,6 +91,8 @@ public static void main(String[] args) { printTestResults(result34); Result result35 = JUnitCore.runClasses(TreeForTentDirectRuleTest.class); printTestResults(result35); + Result result36 = JUnitCore.runClasses(TentOrGrassCaseRuleTest.class); + printTestResults(result36); } private static void printTestResults(Result result) { diff --git a/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java b/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java index c7159ccad..4ec8b4e36 100644 --- a/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java @@ -1,14 +1,12 @@ package puzzles.treetent.rules; import edu.rpi.legup.model.gameboard.Board; -import edu.rpi.legup.model.tree.Tree; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.treetent.TreeTent; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; import edu.rpi.legup.puzzle.treetent.TreeTentType; -import edu.rpi.legup.puzzle.treetent.rules.FillinRowCaseRule; import edu.rpi.legup.puzzle.treetent.rules.TentOrGrassCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; import legup.MockGameBoardFacade; @@ -23,32 +21,63 @@ public class TentOrGrassCaseRuleTest { private static final TentOrGrassCaseRule RULE = new TentOrGrassCaseRule(); private static TreeTent treetent; - + @BeforeClass - public static void setUp(){ + public static void setUp() { MockGameBoardFacade.getInstance(); treetent = new TreeTent(); } /** + * empty 3x3 TreeTent puzzle + * Tests TentOrGrassCaseRule on UNKOWN tile + * at (0,0) + * + * checks 2 cases are created + * checks first case is TENT tile + * checks second case is GRASS tile + * checks other cells have not been modified + * * @throws InvalidFileFormatException - * A temporary test */ @Test - public void TentOrGrassCaseRule_Test() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest", treetent); + public void TentOrTreeTest() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell testing_cell = board.getCell(1, 0); + TreeTentCell testing_cell = board.getCell(0, 0); ArrayList cases = RULE.getCases(board, testing_cell); + // assert correct number of cases created Assert.assertEquals(2, cases.size()); - //Store the 0,1 cells from each case - //Assert that the Array of their states match to a an array of the expected. - } + // TENT case + TreeTentBoard tentCase = (TreeTentBoard) cases.get(0); + Assert.assertEquals(tentCase.getCell(0, 0).getType(), TreeTentType.TENT); + + // GRASS case + TreeTentBoard grassCase = (TreeTentBoard) cases.get(1); + Assert.assertEquals(grassCase.getCell(0, 0).getType(), TreeTentType.GRASS); + // checks other cells have not been modified + TreeTentCell original_cell; + TreeTentCell case_cell; + + for (int w =0; w < board.getWidth(); w++) { + for (int h = 0; h < board.getHeight(); h++) { + if (w == 0 && h ==0) { + continue; + } + original_cell = board.getCell(w, h); + case_cell = tentCase.getCell(w, h); + Assert.assertEquals(original_cell.getType(), case_cell.getType()); + + case_cell = grassCase.getCell(w, h); + Assert.assertEquals(original_cell.getType(), case_cell.getType()); + } + } + } } diff --git a/src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle b/src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle new file mode 100644 index 000000000..a13c7cc55 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TestPuzzle @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file