From 9e623a005927781c8450438f5d49ef3963ec9c50 Mon Sep 17 00:00:00 2001 From: Bram van Heuveln Date: Sun, 5 May 2024 18:09:31 +0000 Subject: [PATCH] Automated Java code formatting changes --- .../edu/rpi/legup/model/PuzzleImporter.java | 27 ++-- .../legup/puzzle/treetent/TreeTentBoard.java | 2 - .../puzzle/treetent/TreeTentImporter.java | 1 - .../treetent/rules/FillinRowCaseRule.java | 37 +++-- .../edu/rpi/legup/ui/ProofEditorPanel.java | 2 +- .../rules/BlackoutDirectRuleTest.java | 49 +++--- .../rules/EmptyFieldDirectRuleTest.java | 83 +++++----- .../treetent/rules/FillinRowCaseRuleTest.java | 49 +++--- .../rules/FinishWithGrassDirectRuleTest.java | 149 ++++++++--------- .../rules/FinishWithTentsDirectRuleTest.java | 152 ++++++++---------- .../rules/LastCampingSpotDirectRuleTest.java | 80 +++++---- .../treetent/rules/LinkTentCaseRuleTest.java | 33 ++-- .../treetent/rules/LinkTreeCaseRuleTest.java | 46 +++--- .../SurroundTentWithGrassDirectRuleTest.java | 62 ++++--- .../rules/TentForTreeDirectRuleTest.java | 151 ++++++++--------- .../rules/TreeForTentDirectRuleTest.java | 63 ++++---- 16 files changed, 450 insertions(+), 536 deletions(-) diff --git a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java index c22831c8d..0902478db 100644 --- a/src/main/java/edu/rpi/legup/model/PuzzleImporter.java +++ b/src/main/java/edu/rpi/legup/model/PuzzleImporter.java @@ -6,8 +6,6 @@ import edu.rpi.legup.model.rules.Rule; import edu.rpi.legup.model.tree.*; import edu.rpi.legup.save.InvalidFileFormatException; - -import java.lang.reflect.Array; import java.util.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -132,18 +130,19 @@ public void initializePuzzle(Node node) throws InvalidFileFormatException { public abstract void initializeBoard(String[] statements) throws UnsupportedOperationException, IllegalArgumentException; - /** - * Used to check that elements in the proof tree are saved properly. - *

Make sure the list elements are lowercase - * - * @return A list of elements that will change when solving the puzzle - * * e.g. {"cell"}, {"cell", "line"} - */ - public List getImporterElements() { - List elements = new ArrayList<>(); - elements.add("cell"); - return elements; - } + /** + * Used to check that elements in the proof tree are saved properly. + * + *

Make sure the list elements are lowercase + * + * @return A list of elements that will change when solving the puzzle * e.g. {"cell"}, {"cell", + * "line"} + */ + public List getImporterElements() { + List elements = new ArrayList<>(); + elements.add("cell"); + return elements; + } /** * Creates the proof for building diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java index 6ded23a18..c8962aa03 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentBoard.java @@ -3,8 +3,6 @@ import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.GridBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; -import edu.rpi.legup.model.tree.Tree; - import java.awt.*; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java index c791617ce..56dcca59f 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/TreeTentImporter.java @@ -5,7 +5,6 @@ import java.awt.*; import java.util.ArrayList; import java.util.List; - import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; diff --git a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java index a796c992a..aaa1a8fbc 100644 --- a/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java +++ b/src/main/java/edu/rpi/legup/puzzle/treetent/rules/FillinRowCaseRule.java @@ -1,11 +1,9 @@ package edu.rpi.legup.puzzle.treetent.rules; -import edu.rpi.legup.model.Puzzle; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.gameboard.CaseBoard; import edu.rpi.legup.model.gameboard.PuzzleElement; import edu.rpi.legup.model.rules.CaseRule; -import edu.rpi.legup.model.tree.Tree; import edu.rpi.legup.model.tree.TreeTransition; import edu.rpi.legup.puzzle.treetent.TreeTentBoard; import edu.rpi.legup.puzzle.treetent.TreeTentCell; @@ -13,9 +11,7 @@ import edu.rpi.legup.puzzle.treetent.TreeTentType; import java.awt.*; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; -import java.util.ListIterator; public class FillinRowCaseRule extends CaseRule { @@ -95,7 +91,6 @@ public ArrayList getCases(Board board, PuzzleElement puzzleElement) { } /** - * * @param iBoard the board to place tents onto * @param tiles the locations where tents can be placed * @param target the target number of tents to place @@ -111,14 +106,21 @@ private ArrayList genCombinations( boolean isRow) { ArrayList generatedBoards = new ArrayList<>(); genCombRecursive( - iBoard, tiles, target, 0, new ArrayList(), 0, index, generatedBoards, isRow); + iBoard, + tiles, + target, + 0, + new ArrayList(), + 0, + index, + generatedBoards, + isRow); return generatedBoards; } /** - * - * Recursive function to generate all ways of placing the target number of tents - * from the list of tiles to fill. + * Recursive function to generate all ways of placing the target number of tents from the list + * of tiles to fill. * * @param iBoard The board * @param tiles Unknown Tiles to fill @@ -128,10 +130,8 @@ private ArrayList genCombinations( * @param selected the cells which have tents * @param index The index of the clue * @param isRow Used for checking if the board is good - * - * The generated boards are placed into generatedBoards (passed by reference) + *

The generated boards are placed into generatedBoards (passed by reference) */ - private void genCombRecursive( TreeTentBoard iBoard, List tiles, @@ -168,14 +168,23 @@ private void genCombRecursive( // // Backtracking: // Remove the placed tent from the board and selected - for (int i = currentTile; i < tiles.size(); ++i){ + for (int i = currentTile; i < tiles.size(); ++i) { TreeTentCell tile = tiles.get(i); selected.add(tile); PuzzleElement element = iBoard.getPuzzleElement(tile); element.setData(TreeTentType.TENT); iBoard.addModifiedData(element); if (goodBoard(iBoard, index, isRow)) { - genCombRecursive(iBoard, tiles, target, current + 1, selected, i + 1, index, generatedBoards, isRow); + genCombRecursive( + iBoard, + tiles, + target, + current + 1, + selected, + i + 1, + index, + generatedBoards, + isRow); } element.setData(TreeTentType.UNKNOWN); iBoard.addModifiedData(element); diff --git a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java index 8401e19f2..645a2c0d7 100644 --- a/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java +++ b/src/main/java/edu/rpi/legup/ui/ProofEditorPanel.java @@ -580,7 +580,7 @@ private void saveProofAs() { if (puzzle == null) { return; } - + LegupPreferences preferences = LegupPreferences.getInstance(); File preferredDirectory = new File(preferences.getUserPref(LegupPreferences.WORK_DIRECTORY)); diff --git a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java index 7789b273b..59d5b37af 100644 --- a/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java +++ b/src/test/java/puzzles/starbattle/rules/BlackoutDirectRuleTest.java @@ -2,30 +2,30 @@ // Commenting this out for now, but once Star Battle is fully implemented this should // be uncommented and finished. -//package puzzles.starbattle.rules; +// package puzzles.starbattle.rules; // -//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 legup.MockGameBoardFacade; -//import legup.TestUtilities; -//import edu.rpi.legup.model.tree.TreeNode; -//import edu.rpi.legup.model.tree.TreeTransition; -//import org.junit.Assert; -//import org.junit.BeforeClass; -//import org.junit.Test; +// 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 legup.MockGameBoardFacade; +// import legup.TestUtilities; +// import edu.rpi.legup.model.tree.TreeNode; +// import edu.rpi.legup.model.tree.TreeTransition; +// import org.junit.Assert; +// import org.junit.BeforeClass; +// import org.junit.Test; // -//import edu.rpi.legup.puzzle.starbattle.StarBattle; -//import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCell; -//import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; -//import edu.rpi.legup.puzzle.starbattle.rules.BlackoutDirectRule; -//import edu.rpi.legup.save.InvalidFileFormatException; +// import edu.rpi.legup.puzzle.starbattle.StarBattle; +// import edu.rpi.legup.puzzle.starbattle.StarBattleBoard; +// import edu.rpi.legup.puzzle.starbattle.StarBattleCell; +// import edu.rpi.legup.puzzle.starbattle.StarBattleCellType; +// import edu.rpi.legup.puzzle.starbattle.rules.BlackoutDirectRule; +// import edu.rpi.legup.save.InvalidFileFormatException; // -//import java.awt.*; +// import java.awt.*; // -//public class BlackoutDirectRuleTest { +// public class BlackoutDirectRuleTest { // // private static final BlackoutDirectRule RULE = new BlackoutDirectRule(); // private static StarBattle starbattle; @@ -38,7 +38,9 @@ // // @Test // public void BlackoutDirectRuleTest_ColumnBlackout() throws InvalidFileFormatException { -// TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/ColumnBlackout", starbattle); +// +// TestUtilities.importTestBoard("puzzles/starbattle/rules/BlackoutDirectRule/ColumnBlackout", +// starbattle); // TreeNode rootNode = starbattle.getTree().getRootNode(); // TreeTransition transition = rootNode.getChildren().get(0); // transition.setRule(RULE); @@ -61,7 +63,8 @@ // 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(cell1.getLocation()) || point.equals(cell2.getLocation()) || point.equals(cell3.getLocation())) { +// if (point.equals(cell1.getLocation()) || point.equals(cell2.getLocation()) || +// point.equals(cell3.getLocation())) { // Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); // } // else { @@ -70,4 +73,4 @@ // } // } // } -//} +// } diff --git a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java index 8ffb2ee4f..c704d59b7 100644 --- a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java @@ -26,17 +26,16 @@ public static void setUp() { treetent = new TreeTent(); } - /** - * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule - *

Empty - * XXX - * XGX - * XXX - *

Makes the (1, 1) tile GRASS - * Checks if the rule correctly detects no trees around the grass tile - */ - @Test - public void EmptyFieldTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule + * + *

Empty XXX XGX XXX + * + *

Makes the (1, 1) tile GRASS Checks if the rule correctly detects no trees around the grass + * tile + */ + @Test + public void EmptyFieldTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyField", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -70,17 +69,16 @@ public void EmptyFieldTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule - *

Trees are at (0, 0), (2, 0), (0, 2), and (2, 2) - * RXR - * XGX - * RXR - *

Makes the (1, 1) tile GRASS - * Checks if the rule correctly ignores the trees on the diagonals - */ - @Test - public void DiagonalTreeTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule + * + *

Trees are at (0, 0), (2, 0), (0, 2), and (2, 2) RXR XGX RXR + * + *

Makes the (1, 1) tile GRASS Checks if the rule correctly ignores the trees on the + * diagonals + */ + @Test + public void DiagonalTreeTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/EmptyFieldDirectRule/DiagonalTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -114,17 +112,15 @@ public void DiagonalTreeTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule - *

Trees are at (0, 1), (1, 0), (1, 2), and (2, 1) - * XRX - * RGR - * XRX - *

Makes the (1, 1) tile GRASS - * Checks if the rule is not valid when there are adjacent trees - */ - @Test - public void EmptyFieldTestFail() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule + * + *

Trees are at (0, 1), (1, 0), (1, 2), and (2, 1) XRX RGR XRX + * + *

Makes the (1, 1) tile GRASS Checks if the rule is not valid when there are adjacent trees + */ + @Test + public void EmptyFieldTestFail() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -153,17 +149,16 @@ public void EmptyFieldTestFail() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule - *

Tree at (1, 0) - * XRX - * XGX - * XXX - *

Makes the (1, 1) tile GRASS - * Checks if the rule is not valid when there is one adjacent tree - */ - @Test - public void EmptyFieldTestFailTop() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests EmptyFieldDirectRule + * + *

Tree at (1, 0) XRX XGX XXX + * + *

Makes the (1, 1) tile GRASS Checks if the rule is not valid when there is one adjacent + * tree + */ + @Test + public void EmptyFieldTestFailTop() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); diff --git a/src/test/java/puzzles/treetent/rules/FillinRowCaseRuleTest.java b/src/test/java/puzzles/treetent/rules/FillinRowCaseRuleTest.java index 71b478e7a..3b8389407 100644 --- a/src/test/java/puzzles/treetent/rules/FillinRowCaseRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/FillinRowCaseRuleTest.java @@ -6,17 +6,15 @@ import edu.rpi.legup.puzzle.treetent.*; import edu.rpi.legup.puzzle.treetent.rules.FillinRowCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.lang.reflect.Array; -import java.util.ArrayList; - public class FillinRowCaseRuleTest { - private static final FillinRowCaseRule RULE = new FillinRowCaseRule(); + private static final FillinRowCaseRule RULE = new FillinRowCaseRule(); private static TreeTent treetent; @BeforeClass @@ -26,11 +24,11 @@ public static void setUp() { } /** - * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles - * and a clue of 0 tents in the row. + * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles and a clue of 0 + * tents in the row. * - *

checks that 1 case is created and that it is equivalent to FinishWithGrass rule - * May need to change checks due to issue #777 + *

checks that 1 case is created and that it is equivalent to FinishWithGrass rule May need + * to change checks due to issue #777 * * @throws InvalidFileFormatException */ @@ -98,16 +96,12 @@ public void TentOrTreeTestZeroTentClue() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles - * and a clue of 1 tent in the row. The column rules make the board impossible, but - * they are not checked here. + * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles and a clue of 1 + * tent in the row. The column rules make the board impossible, but they are not checked here. * - *

checks 3 cases are created checks; - * first case is TENT tile at x=0, - * second case is TENT tile at x=1, - * and a third case is TENT tile at x=2. - * The cases can be in any order. - * Then, it checks that other cells have not been modified + *

checks 3 cases are created checks; first case is TENT tile at x=0, second case is TENT + * tile at x=1, and a third case is TENT tile at x=2. The cases can be in any order. Then, it + * checks that other cells have not been modified * * @throws InvalidFileFormatException */ @@ -145,7 +139,7 @@ public void FillInRowEmptyOneTentClue() throws InvalidFileFormatException { for (int w = 0; w < board.getWidth(); w++) { for (int h = 0; h < board.getHeight(); h++) { if (h == 1) { - continue; + continue; } original_cell = board.getCell(w, h); @@ -155,7 +149,6 @@ public void FillInRowEmptyOneTentClue() throws InvalidFileFormatException { case_cell = testCase.getCell(w, h); Assert.assertEquals(original_cell.getType(), case_cell.getType()); - } } } @@ -199,13 +192,11 @@ public void FillInRowEmptyOneTentClue() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles - * and a clue of 2 tent in the row. The column rules make the board impossible, but - * they are not checked here. + * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles and a clue of 2 + * tent in the row. The column rules make the board impossible, but they are not checked here. * - *

checks 1 case is created. Checks that the case is when - * there are TENT tiles at x=0 and x=2. - * Then, it checks that other cells have not been modified + *

checks 1 case is created. Checks that the case is when there are TENT tiles at x=0 and + * x=2. Then, it checks that other cells have not been modified * * @throws InvalidFileFormatException */ @@ -287,8 +278,8 @@ public void FillInRowEmptyTwoTentClue() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles - * and a clue of 3 tent in the row. + * empty 3x3 TreeTent puzzle Tests FillinRowCaseRule on row with 3 UNKNOWN tiles and a clue of 3 + * tent in the row. * *

checks that 0 cases are created * @@ -319,8 +310,8 @@ public void FillInRowEmptyThreeTentClue() throws InvalidFileFormatException { } /** - * empty 5x5 TreeTent puzzle Tests FillinRowCaseRule on row with 5 UNKNOWN tiles - * and a clue of 2 tents in the row. + * empty 5x5 TreeTent puzzle Tests FillinRowCaseRule on row with 5 UNKNOWN tiles and a clue of 2 + * tents in the row. * *

checks that 6 cases are created and each case has the right number of tents * diff --git a/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java index f37761e26..c89c96dd1 100644 --- a/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/FinishWithGrassDirectRuleTest.java @@ -28,18 +28,16 @@ public static void setUp() { treetent = new TreeTent(); } - /** - * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Tent at (1, 1) - * XXX x - * GTG 1 - * XXX x - * xxx - *

Makes (0, 1) and (2, 1) GRASS - * Checks if the rule detects the middle row to be filled in correctly - */ - @Test - public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule + * + *

Tent at (1, 1) XXX x GTG 1 XXX x xxx + * + *

Makes (0, 1) and (2, 1) GRASS Checks if the rule detects the middle row to be filled in + * correctly + */ + @Test + public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -78,18 +76,16 @@ public void FinishWithGrassHorizontalTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Tent at (0, 0) - * TXX x - * GXX x - * GXX x - * 1xx - *

Makes (0, 1) and (0, 2) GRASS - * Checks if the rule detects the leftmost column to be filled in correctly - */ - @Test - public void FinishWithGrassVerticalTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule + * + *

Tent at (0, 0) TXX x GXX x GXX x 1xx + * + *

Makes (0, 1) and (0, 2) GRASS Checks if the rule detects the leftmost column to be filled + * in correctly + */ + @Test + public void FinishWithGrassVerticalTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithGrassDirectRule/CornerTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -130,13 +126,11 @@ public void FinishWithGrassVerticalTest() throws InvalidFileFormatException { /** * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Tent at (0, 0) - * TGG 1 - * GXX x - * GXX x - * 1xx - *

Makes (0, 1), (0, 2), (1, 0), and (2, 0) GRASS - * Checks if the rule detects the top row and leftmost column to be filled in correctly + * + *

Tent at (0, 0) TGG 1 GXX x GXX x 1xx + * + *

Makes (0, 1), (0, 2), (1, 0), and (2, 0) GRASS Checks if the rule detects the top row and + * leftmost column to be filled in correctly */ @Test public void FinishWithGrassTest() throws InvalidFileFormatException { @@ -186,18 +180,16 @@ public void FinishWithGrassTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Empty - * GGG 0 - * GGG 0 - * GGG 0 - * 000 - *

Fill Board with GRASS - * Checks if the rule allows all cells to be filled when the clue for all rows and columns is zero. - */ - @Test - public void NoTentTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule + * + *

Empty GGG 0 GGG 0 GGG 0 000 + * + *

Fill Board with GRASS Checks if the rule allows all cells to be filled when the clue for + * all rows and columns is zero. + */ + @Test + public void NoTentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithGrassDirectRule/NoTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -231,18 +223,16 @@ public void NoTentTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Tent at (1, 1) - * XGX x - * GTG 1 - * XGX x - * x1x - *

Makes (1, 0), (0, 1), (2, 1), and (1, 2) GRASS - * Checks if the rule correctly allows the central row and column to be filled with grass. - */ - @Test - public void MiddleTentTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule + * + *

Tent at (1, 1) XGX x GTG 1 XGX x x1x + * + *

Makes (1, 0), (0, 1), (2, 1), and (1, 2) GRASS Checks if the rule correctly allows the + * central row and column to be filled with grass. + */ + @Test + public void MiddleTentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithGrassDirectRule/MiddleTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -290,18 +280,16 @@ public void MiddleTentTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Empty - * GGG 1 - * GGG 1 - * GGG 1 - * 111 - *

Fill Board with GRASS - * Checks if the rule is not valid when a row or column does not have the required number of tents but is filled with grass - */ - @Test - public void FailTentTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithGrassDirectRule + * + *

Empty GGG 1 GGG 1 GGG 1 111 + * + *

Fill Board with GRASS Checks if the rule is not valid when a row or column does not have + * the required number of tents but is filled with grass + */ + @Test + public void FailTentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithGrassDirectRule/FailTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -335,22 +323,17 @@ public void FailTentTest() throws InvalidFileFormatException { } } - /** - * 7x7 TreeTent puzzle Tests FinishWithGrassDirectRule - *

Tents at (1, 3), (3, 3), and (5, 3) - * XXXXXXX x - * XXXXXXX x - * XXXXXXX x - * TGTGTGT 4 - * XXXXXXX x - * XXXXXXX x - * XXXXXXX x - * xxxxxxx - *

Makes (0, 3), (2, 3), (4, 3), and (6, 3) GRASS - * Checks if applying the rule on row 3 is valid - */ - @Test - public void SpacedOutTentTest() throws InvalidFileFormatException { + /** + * 7x7 TreeTent puzzle Tests FinishWithGrassDirectRule + * + *

Tents at (1, 3), (3, 3), and (5, 3) XXXXXXX x XXXXXXX x XXXXXXX x TGTGTGT 4 XXXXXXX x + * XXXXXXX x XXXXXXX x xxxxxxx + * + *

Makes (0, 3), (2, 3), (4, 3), and (6, 3) GRASS Checks if applying the rule on row 3 is + * valid + */ + @Test + public void SpacedOutTentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithGrassDirectRule/SpacedOutTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); diff --git a/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java index d82be3f87..b72b0f556 100644 --- a/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java @@ -27,18 +27,15 @@ public static void setUp() { treetent = new TreeTent(); } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Grass at (0, 0) - * GTT 2 - * XXX x - * XXX x - * xxx - *

Makes (1, 0) and (2, 0) TENT - * Checks that the rule correctly fills in the first row - */ - @Test - public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Grass at (0, 0) GTT 2 XXX x XXX x xxx + * + *

Makes (1, 0) and (2, 0) TENT Checks that the rule correctly fills in the first row + */ + @Test + public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithHorizontalTents", treetent); @@ -71,18 +68,15 @@ public void FinishWithHorizontalTentsTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Grass at (0, 0) - * GXX x - * TXX x - * TXX x - * 2xx - *

Makes (0, 1) and (0, 2) TENT - * Checks that the rule correctly fills in the first column - */ - @Test - public void FinishWithVerticalTentsTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Grass at (0, 0) GXX x TXX x TXX x 2xx + * + *

Makes (0, 1) and (0, 2) TENT Checks that the rule correctly fills in the first column + */ + @Test + public void FinishWithVerticalTentsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithVerticalTents", treetent); @@ -115,18 +109,16 @@ public void FinishWithVerticalTentsTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Grass at (0, 0) - * GTT 2 - * TXX x - * TXX x - * 2xx - *

Makes (1, 0), (2, 0), (0, 1) and (0, 2) TENT - * Checks that the rule correctly fills both the first row and first column - */ - @Test - public void FinishWithTentsTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Grass at (0, 0) GTT 2 TXX x TXX x 2xx + * + *

Makes (1, 0), (2, 0), (0, 1) and (0, 2) TENT Checks that the rule correctly fills both the + * first row and first column + */ + @Test + public void FinishWithTentsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -167,18 +159,16 @@ public void FinishWithTentsTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Tent at (1, 1) - * XTX x - * TTT 3 - * XTX x - * x3x - *

Makes (1, 0), (0, 1), (2, 1), and (1, 2) TENT - * Checks that the rule correctly fills in the middle row and column when a tent starts at (1, 1) - */ - @Test - public void AdditionalTentsTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Tent at (1, 1) XTX x TTT 3 XTX x x3x + * + *

Makes (1, 0), (0, 1), (2, 1), and (1, 2) TENT Checks that the rule correctly fills in the + * middle row and column when a tent starts at (1, 1) + */ + @Test + public void AdditionalTentsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/AdditionalTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -219,18 +209,16 @@ public void AdditionalTentsTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Empty - * TTT 0 - * TTT 0 - * TTT 0 - * 000 - *

Fills the board with tents - * Checks that the rule does not allow for more tents in any of the rows or columns - */ - @Test - public void FinishWithTentsFailTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Empty TTT 0 TTT 0 TTT 0 000 + * + *

Fills the board with tents Checks that the rule does not allow for more tents in any of + * the rows or columns + */ + @Test + public void FinishWithTentsFailTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsFail", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -259,18 +247,16 @@ public void FinishWithTentsFailTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Tent at (1, 1) - * XTX x - * TTT 1 - * XTX x - * x1x - *

Makes (1, 0), (0, 1), (2, 1) and (1, 2) Tent - * Checks that the rule does not allow for more tents in the central row or central column - */ - @Test - public void TooManyTentsTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Tent at (1, 1) XTX x TTT 1 XTX x x1x + * + *

Makes (1, 0), (0, 1), (2, 1) and (1, 2) Tent Checks that the rule does not allow for more + * tents in the central row or central column + */ + @Test + public void TooManyTentsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/TooManyTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -302,18 +288,16 @@ public void TooManyTentsTest() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule - *

Tent at (1, 1) - * XTX x - * TTT 2 - * XTX x - * x2x - *

Makes (1, 0), (0, 1), (2, 1) and (1, 2) Tent - * Checks that the rule is not satisfied because there are multiple configurations of tents for the central row and central column - */ - @Test - public void AmbiguousTentsTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests FinishWithTentsDirectRule + * + *

Tent at (1, 1) XTX x TTT 2 XTX x x2x + * + *

Makes (1, 0), (0, 1), (2, 1) and (1, 2) Tent Checks that the rule is not satisfied because + * there are multiple configurations of tents for the central row and central column + */ + @Test + public void AmbiguousTentsTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/FinishWithTentsDirectRule/AmbiguousTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); diff --git a/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java index ad4559922..fdd55029f 100644 --- a/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java @@ -26,17 +26,15 @@ public static void setUp() { treetent = new TreeTent(); } - /** - * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule - *

TREE at (1, 1) and (0, 1); GRASS at (1, 2) and (2, 1) - * XTX - * RRG - * XGX - *

Makes (1, 0) TENT - * Checks that a tent must be placed above the central tree - */ - @Test - public void EmptyFieldTest_Up() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule + * + *

TREE at (1, 1) and (0, 1); GRASS at (1, 2) and (2, 1) XTX RRG XGX + * + *

Makes (1, 0) TENT Checks that a tent must be placed above the central tree + */ + @Test + public void EmptyFieldTest_Up() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -64,17 +62,15 @@ public void EmptyFieldTest_Up() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule - *

TREE at (1, 1) and (0, 1); GRASS at (1, 0) and (1, 2) - * XGX - * RRG - * XTX - *

Makes (1, 2) TENT - * Checks that a tent must be placed below the central tree - */ - @Test - public void EmptyFieldTest_Down() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule + * + *

TREE at (1, 1) and (0, 1); GRASS at (1, 0) and (1, 2) XGX RRG XTX + * + *

Makes (1, 2) TENT Checks that a tent must be placed below the central tree + */ + @Test + public void EmptyFieldTest_Down() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -102,17 +98,15 @@ public void EmptyFieldTest_Down() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule - *

TREE at (1, 1) and (2, 1); GRASS at (1, 0) and (1, 2) - * XGX - * TRR - * XGX - *

Makes (0, 1) TENT - * Checks that a tent must be placed on the left of the central tree - */ - @Test - public void EmptyFieldTest_Left() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule + * + *

TREE at (1, 1) and (2, 1); GRASS at (1, 0) and (1, 2) XGX TRR XGX + * + *

Makes (0, 1) TENT Checks that a tent must be placed on the left of the central tree + */ + @Test + public void EmptyFieldTest_Left() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); @@ -140,17 +134,15 @@ public void EmptyFieldTest_Left() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule - *

TREE at (1, 1) and (1, 2); GRASS at (0, 1) and (1, 0) - * XGX - * GRT - * XRX - *

Makes (2, 1) TENT - * Checks that a tent must be placed to the right of the central tree - */ - @Test - public void EmptyFieldTest_Right() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests LastCampingSpotDirectRule + * + *

TREE at (1, 1) and (1, 2); GRASS at (0, 1) and (1, 0) XGX GRT XRX + * + *

Makes (2, 1) TENT Checks that a tent must be placed to the right of the central tree + */ + @Test + public void EmptyFieldTest_Right() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); diff --git a/src/test/java/puzzles/treetent/rules/LinkTentCaseRuleTest.java b/src/test/java/puzzles/treetent/rules/LinkTentCaseRuleTest.java index 3ed1fd79e..ed482eba0 100644 --- a/src/test/java/puzzles/treetent/rules/LinkTentCaseRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/LinkTentCaseRuleTest.java @@ -1,22 +1,18 @@ 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.*; import edu.rpi.legup.puzzle.treetent.rules.LinkTentCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.LinkedList; - public class LinkTentCaseRuleTest { private static final LinkTentCaseRule RULE = new LinkTentCaseRule(); private static TreeTent treetent; @@ -28,8 +24,8 @@ public static void setUp() { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent - * with one tree surrounding it. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent with one tree surrounding + * it. * *

checks that 1 cases is with the line connecting the central tent and the tree * @@ -76,11 +72,11 @@ public void LinkTentOneTreeTest() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent - * with four trees surrounding it. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent with four trees + * surrounding it. * - *

checks that 4 cases are created, each of which create a line - * connecting the tent to one of the four trees without repeat. + *

checks that 4 cases are created, each of which create a line connecting the tent to one of + * the four trees without repeat. * * @throws InvalidFileFormatException */ @@ -106,7 +102,7 @@ public void LinkTentFourTreesTest() throws InvalidFileFormatException { expectedLines.addFirst(new TreeTentLine(board.getCell(1, 1), board.getCell(1, 2))); for (Board testCaseBoard : cases) { - TreeTentBoard testCase = (TreeTentBoard) testCaseBoard ; + TreeTentBoard testCase = (TreeTentBoard) testCaseBoard; ArrayList lines = testCase.getLines(); // Each case should connect one line from the tent to @@ -142,17 +138,15 @@ public void LinkTentFourTreesTest() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent - * with zero trees around it. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent with zero trees around it. * - *

Ensures no cases are created + *

Ensures no cases are created * * @throws InvalidFileFormatException */ @Test public void LinkTentNoTreesTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard( - "puzzles/treetent/rules/LinkTentCaseRule/NoTrees", treetent); + TestUtilities.importTestBoard("puzzles/treetent/rules/LinkTentCaseRule/NoTrees", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -166,10 +160,9 @@ public void LinkTentNoTreesTest() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent - * with trees on a diagonal. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tent with trees on a diagonal. * - *

Ensures no cases are created + *

Ensures no cases are created * * @throws InvalidFileFormatException */ diff --git a/src/test/java/puzzles/treetent/rules/LinkTreeCaseRuleTest.java b/src/test/java/puzzles/treetent/rules/LinkTreeCaseRuleTest.java index fffde14b1..be237e8d4 100644 --- a/src/test/java/puzzles/treetent/rules/LinkTreeCaseRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/LinkTreeCaseRuleTest.java @@ -1,6 +1,5 @@ package puzzles.treetent.rules; -import com.sun.source.doctree.LinkTree; import edu.rpi.legup.model.gameboard.Board; import edu.rpi.legup.model.tree.TreeNode; import edu.rpi.legup.model.tree.TreeTransition; @@ -10,16 +9,15 @@ import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.rules.LinkTreeCaseRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class LinkTreeCaseRuleTest { - private static final LinkTreeCaseRule RULE = new LinkTreeCaseRule(); + private static final LinkTreeCaseRule RULE = new LinkTreeCaseRule(); private static TreeTent treetent; @BeforeClass @@ -29,17 +27,15 @@ public static void setUp() { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree - * with one tent above + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree with one tent above * - *

Ensures one case is created that connects the tree to the tent. + *

Ensures one case is created that connects the tree to the tent. * * @throws InvalidFileFormatException */ @Test public void LinkTentOneTentTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard( - "puzzles/treetent/rules/LinkTreeCaseRule/OneTent", treetent); + TestUtilities.importTestBoard("puzzles/treetent/rules/LinkTreeCaseRule/OneTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -77,20 +73,18 @@ public void LinkTentOneTentTest() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree - * with two tents, one on the left and one on the right. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree with two tents, one on the + * left and one on the right. * - *

Ensures two cases are created, one connecting the tree and the - * left tent, and one connecting the tree and the right tent. - * Because tents must be surrounded by grass, there can be at most - * two tents around a given tree. + *

Ensures two cases are created, one connecting the tree and the left tent, and one + * connecting the tree and the right tent. Because tents must be surrounded by grass, there can + * be at most two tents around a given tree. * * @throws InvalidFileFormatException */ @Test public void LinkTentTwoTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard( - "puzzles/treetent/rules/LinkTreeCaseRule/TwoTents", treetent); + TestUtilities.importTestBoard("puzzles/treetent/rules/LinkTreeCaseRule/TwoTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -107,7 +101,7 @@ public void LinkTentTwoTentsTest() throws InvalidFileFormatException { expectedLines.addFirst(new TreeTentLine(board.getCell(1, 1), board.getCell(2, 1))); for (Board testCaseBoard : cases) { - TreeTentBoard testCase = (TreeTentBoard) testCaseBoard ; + TreeTentBoard testCase = (TreeTentBoard) testCaseBoard; ArrayList lines = testCase.getLines(); // Each case should connect one line from the tent to @@ -143,17 +137,15 @@ public void LinkTentTwoTentsTest() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree - * with zero tents around it. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree with zero tents around it. * - *

Ensures no cases are created + *

Ensures no cases are created * * @throws InvalidFileFormatException */ @Test public void LinkTentNoTreesTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard( - "puzzles/treetent/rules/LinkTreeCaseRule/NoTents", treetent); + TestUtilities.importTestBoard("puzzles/treetent/rules/LinkTreeCaseRule/NoTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -167,17 +159,15 @@ public void LinkTentNoTreesTest() throws InvalidFileFormatException { } /** - * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree - * with tents on a diagonal. + * empty 3x3 TreeTent puzzle Tests LinkTentCaseRule on a central tree with tents on a diagonal. * - *

Ensures no cases are created + *

Ensures no cases are created * * @throws InvalidFileFormatException */ @Test public void LinkTentDiagTentsTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard( - "puzzles/treetent/rules/LinkTreeCaseRule/NoTents", treetent); + TestUtilities.importTestBoard("puzzles/treetent/rules/LinkTreeCaseRule/NoTents", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); diff --git a/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java index 6177bb64c..dc61cb863 100644 --- a/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/SurroundTentWithGrassDirectRuleTest.java @@ -27,17 +27,16 @@ public static void setUp() { treetent = new TreeTent(); } - /** - * 3x3 TreeTent puzzle Tests SurroundTentWithGrassDirectRule - *

TREE at (0, 0), (2, 0), (0, 1), (2, 1), (1, 2), and (2, 2); TENT at (1, 1) - * RGR - * RTR - * GRR - *

Makes (1, 0) and (0, 2) GRASS - * Checks that the rule detects unknown adjacent and diagonal tiles correctly - */ - @Test - public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests SurroundTentWithGrassDirectRule + * + *

TREE at (0, 0), (2, 0), (0, 1), (2, 1), (1, 2), and (2, 2); TENT at (1, 1) RGR RTR GRR + * + *

Makes (1, 0) and (0, 2) GRASS Checks that the rule detects unknown adjacent and diagonal + * tiles correctly + */ + @Test + public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrass", treetent); @@ -69,17 +68,16 @@ public void SurroundTentWithGrassBasicRuleTest() throws InvalidFileFormatExcepti } } - /** - * 3x3 TreeTent puzzle Tests SurroundTentWithGrassDirectRule - *

TENT at (1, 1) - * GGG - * GTG - * GGG - *

Makes all cells adjacent and diagonal to the tent GRASS - * Checks that the rule detects all adjacent and diagonal tiles correctly - */ - @Test - public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests SurroundTentWithGrassDirectRule + * + *

TENT at (1, 1) GGG GTG GGG + * + *

Makes all cells adjacent and diagonal to the tent GRASS Checks that the rule detects all + * adjacent and diagonal tiles correctly + */ + @Test + public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassBad", treetent); @@ -137,17 +135,15 @@ public void SurroundTentWithGrassBasicRuleTest_BadBoard() throws InvalidFileForm } } - /** - * 3x3 TreeTent puzzle Tests SurroundTentWithGrassDirectRule - *

TENT at (1, 1); TREE on all adjacent and diagonal tiles - * RRR - * RTR - * RRR - *

Null - * Checks that the rule correctly detects no missing tiles - */ - @Test - public void SurroundTentWithGrassBasicRuleTest_FullBoard() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests SurroundTentWithGrassDirectRule + * + *

TENT at (1, 1); TREE on all adjacent and diagonal tiles RRR RTR RRR + * + *

Null Checks that the rule correctly detects no missing tiles + */ + @Test + public void SurroundTentWithGrassBasicRuleTest_FullBoard() throws InvalidFileFormatException { TestUtilities.importTestBoard( "puzzles/treetent/rules/SurroundTentWithGrassDirectRule/SurroundTentWithGrassTrees", treetent); diff --git a/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java index e55704ec2..6bd2db071 100644 --- a/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TentForTreeDirectRuleTest.java @@ -5,14 +5,13 @@ import edu.rpi.legup.puzzle.treetent.*; import edu.rpi.legup.puzzle.treetent.rules.TentForTreeDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class TentForTreeDirectRuleTest { private static final TentForTreeDirectRule RULE = new TentForTreeDirectRule(); @@ -24,62 +23,58 @@ public static void setUp() { treetent = new TreeTent(); } - /** - * 3x3 TreeTent puzzle Tests TentForTreeDirectRule - *

TREE at (1, 0); TENT at (1, 1) - * XRX - * XTX - * XXX - *

Makes a line between (1, 0) and (1, 1) - * Checks that the rule correctly detects the central tent as the only possible connection - */ - @Test - public void TentForTreeTestOneTreeOneTentTest() throws InvalidFileFormatException { - - TestUtilities.importTestBoard( - "puzzles/treetent/rules/TentForTreeDirectRule/OneTreeOneTent", - treetent); - - TreeNode rootNode = treetent.getTree().getRootNode(); - TreeTransition transition = rootNode.getChildren().get(0); - transition.setRule(RULE); - - TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - - TreeTentCell cell1 = board.getCell(1, 0); - TreeTentCell cell2 = board.getCell(1, 1); - TreeTentLine line = new TreeTentLine(cell1, cell2); - - board.addModifiedData(line); - board.getLines().add(line); - - Assert.assertNull(RULE.checkRule(transition)); - - ArrayList lines = board.getLines(); - for (TreeTentLine l : lines) { - if (l.compare((line))) { - Assert.assertNull(RULE.checkRuleAt(transition, l)); - } else { - Assert.assertNotNull(RULE.checkRuleAt(transition, l)); + /** + * 3x3 TreeTent puzzle Tests TentForTreeDirectRule + * + *

TREE at (1, 0); TENT at (1, 1) XRX XTX XXX + * + *

Makes a line between (1, 0) and (1, 1) Checks that the rule correctly detects the central + * tent as the only possible connection + */ + @Test + public void TentForTreeTestOneTreeOneTentTest() throws InvalidFileFormatException { + + TestUtilities.importTestBoard( + "puzzles/treetent/rules/TentForTreeDirectRule/OneTreeOneTent", treetent); + + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(1, 0); + TreeTentCell cell2 = board.getCell(1, 1); + TreeTentLine line = new TreeTentLine(cell1, cell2); + + board.addModifiedData(line); + board.getLines().add(line); + + Assert.assertNull(RULE.checkRule(transition)); + + ArrayList lines = board.getLines(); + for (TreeTentLine l : lines) { + if (l.compare((line))) { + Assert.assertNull(RULE.checkRuleAt(transition, l)); + } else { + Assert.assertNotNull(RULE.checkRuleAt(transition, l)); + } } } - } - - /** - * 3x3 TreeTent puzzle Tests TentForTreeDirectRule - *

TREE at (1, 0) and (1, 2); TENT at (1, 1) - * XRX - * XTX - * XRX - *

Makes a line between (1, 0) and (1, 1) - * Checks that the rule works when connecting a line between the tree at (1, 0) and tent at (1, 1) - */ - @Test - public void TentForTreeArbitraryTreeTest() throws InvalidFileFormatException { + + /** + * 3x3 TreeTent puzzle Tests TentForTreeDirectRule + * + *

TREE at (1, 0) and (1, 2); TENT at (1, 1) XRX XTX XRX + * + *

Makes a line between (1, 0) and (1, 1) Checks that the rule works when connecting a line + * between the tree at (1, 0) and tent at (1, 1) + */ + @Test + public void TentForTreeArbitraryTreeTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TentForTreeDirectRule/ArbitraryTree", - treetent); + "puzzles/treetent/rules/TentForTreeDirectRule/ArbitraryTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -97,21 +92,19 @@ public void TentForTreeArbitraryTreeTest() throws InvalidFileFormatException { Assert.assertNull(RULE.checkRule(transition)); } - /** - * 3x3 TreeTent puzzle Tests TentForTreeDirectRule - *

TREE at (1, 0) and (1, 2); TENT at (1, 1); LINE between (1, 0) and (1, 1) - * XRX - * XTX - * XRX - *

Makes a line between (1, 1) and (1, 2) - * Checks that the rule fails for the tree at (1, 2) because there are no valid tents to connect to - */ - @Test - public void TentForTreeConnectedTent() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests TentForTreeDirectRule + * + *

TREE at (1, 0) and (1, 2); TENT at (1, 1); LINE between (1, 0) and (1, 1) XRX XTX XRX + * + *

Makes a line between (1, 1) and (1, 2) Checks that the rule fails for the tree at (1, 2) + * because there are no valid tents to connect to + */ + @Test + public void TentForTreeConnectedTent() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TentForTreeDirectRule/ArbitraryTree", - treetent); + "puzzles/treetent/rules/TentForTreeDirectRule/ArbitraryTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -134,20 +127,18 @@ public void TentForTreeConnectedTent() throws InvalidFileFormatException { } } - /** - * 3x3 TreeTent puzzle Tests TentForTreeDirectRule - *

TREE at (1, 1); TENT at (1, 0) and (1, 2) - * XTX - * XRX - * XTX - *

Makes a line between (1, 1) and (1, 2) - * Checks that the rule fails for the tree at (1, 1) because there are two valid tents to connect to - */ - @Test - public void TentForTreeOneTreeTwoAdjacentTent() throws InvalidFileFormatException { + /** + * 3x3 TreeTent puzzle Tests TentForTreeDirectRule + * + *

TREE at (1, 1); TENT at (1, 0) and (1, 2) XTX XRX XTX + * + *

Makes a line between (1, 1) and (1, 2) Checks that the rule fails for the tree at (1, 1) + * because there are two valid tents to connect to + */ + @Test + public void TentForTreeOneTreeTwoAdjacentTent() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TentForTreeDirectRule/OneTreeTwoAdjacentTent", - treetent); + "puzzles/treetent/rules/TentForTreeDirectRule/OneTreeTwoAdjacentTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); diff --git a/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java index ba1b49b8c..3cccdc417 100644 --- a/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TreeForTentDirectRuleTest.java @@ -8,14 +8,13 @@ import edu.rpi.legup.puzzle.treetent.TreeTentLine; import edu.rpi.legup.puzzle.treetent.rules.TreeForTentDirectRule; import edu.rpi.legup.save.InvalidFileFormatException; +import java.util.ArrayList; import legup.MockGameBoardFacade; import legup.TestUtilities; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; -import java.util.ArrayList; - public class TreeForTentDirectRuleTest { private static final TreeForTentDirectRule RULE = new TreeForTentDirectRule(); @@ -29,19 +28,17 @@ public static void setUp() { /** * 3x3 TreeTent puzzle Tests TreeForTentDirectRule - *

TENT at (1, 0); TREE at (1, 1) - * XTX - * XRX - * XXX - *

Makes a line between (1, 0) and (1, 1) - * Checks that the rule correctly detects the central tree as the only possible connection + * + *

TENT at (1, 0); TREE at (1, 1) XTX XRX XXX + * + *

Makes a line between (1, 0) and (1, 1) Checks that the rule correctly detects the central + * tree as the only possible connection */ - @Test - public void TreeForTentTestOneTreeOneTentTest() throws InvalidFileFormatException { + @Test + public void TreeForTentTestOneTreeOneTentTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TreeForTentDirectRule/OneTentOneTree", - treetent); + "puzzles/treetent/rules/TreeForTentDirectRule/OneTentOneTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -61,19 +58,17 @@ public void TreeForTentTestOneTreeOneTentTest() throws InvalidFileFormatExceptio /** * 3x3 TreeTent puzzle Tests TreeForTentDirectRule - *

TENT at (1, 0) and (1, 2); TREE at (1, 1) - * XTX - * XRX - * XTX - *

Makes a line between (1, 0) and (1, 1) - * Checks that the rule works when connecting a line between the tent at (1, 0) and the tree at (1, 1) + * + *

TENT at (1, 0) and (1, 2); TREE at (1, 1) XTX XRX XTX + * + *

Makes a line between (1, 0) and (1, 1) Checks that the rule works when connecting a line + * between the tent at (1, 0) and the tree at (1, 1) */ @Test public void TentForTreeWithArbitraryTreeTest() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TreeForTentDirectRule/ArbitraryTent", - treetent); + "puzzles/treetent/rules/TreeForTentDirectRule/ArbitraryTent", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -93,19 +88,17 @@ public void TentForTreeWithArbitraryTreeTest() throws InvalidFileFormatException /** * 3x3 TreeTent puzzle Tests TreeForTentDirectRule - *

TENT at (1, 0) and (1, 2); TREE at (1, 1); LINE between (1, 0) and (1, 1) - * XTX - * XRX - * XTX - *

Makes a line between (1, 1) and (1, 2) - * Checks that the rule fails for the tent at (1, 2) because there are no valid trees to connect to + * + *

TENT at (1, 0) and (1, 2); TREE at (1, 1); LINE between (1, 0) and (1, 1) XTX XRX XTX + * + *

Makes a line between (1, 1) and (1, 2) Checks that the rule fails for the tent at (1, 2) + * because there are no valid trees to connect to */ @Test public void TentForTreeConnectedTent() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TreeForTentDirectRule/ConnectedTree", - treetent); + "puzzles/treetent/rules/TreeForTentDirectRule/ConnectedTree", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); @@ -130,18 +123,16 @@ public void TentForTreeConnectedTent() throws InvalidFileFormatException { /** * 3x3 TreeTent puzzle Tests TreeForTentDirectRule - *

TENT at (1, 1); TREE at (1, 0) and (1, 2) - * XRX - * XTX - * XRX - *

Makes a line between (1, 1) and (1, 2) - * Checks that the rule fails for the tree at (1, 1) because there are two valid trees to connect to + * + *

TENT at (1, 1); TREE at (1, 0) and (1, 2) XRX XTX XRX + * + *

Makes a line between (1, 1) and (1, 2) Checks that the rule fails for the tree at (1, 1) + * because there are two valid trees to connect to */ @Test public void TentForTreeOneTreeTwoAdjacentTent() throws InvalidFileFormatException { TestUtilities.importTestBoard( - "puzzles/treetent/rules/TreeForTentDirectRule/OneTentTwoAdjacentTrees", - treetent); + "puzzles/treetent/rules/TreeForTentDirectRule/OneTentTwoAdjacentTrees", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0);