diff --git a/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java index dff292977..725c3c9de 100644 --- a/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/FinishWithTentsDirectRuleTest.java @@ -126,7 +126,7 @@ public void FinishWithTentsTest() throws InvalidFileFormatException { TreeTentCell cell2 = board.getCell(1, 2); TreeTentCell cell3 = board.getCell(0, 1); TreeTentCell cell4 = board.getCell(2, 1); - + cell1.setData(TreeTentType.TENT); cell2.setData(TreeTentType.TENT); cell3.setData(TreeTentType.TENT); diff --git a/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java index 415b4f4b9..3e1b390fb 100644 --- a/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/LastCampingSpotDirectRuleTest.java @@ -27,9 +27,14 @@ public static void setUp() { treetent = new TreeTent(); } + /** + * @throws InvalidFileFormatException + * + * Checks if a test works for an empty square above a tree which is surrounded on all other sides. + */ @Test - public void EmptyFieldTest() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpot", treetent); + public void EmptyFieldTest_Up() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -55,6 +60,108 @@ public void EmptyFieldTest() throws InvalidFileFormatException { } } } + + /** + * @throws InvalidFileFormatException + * + * Checks if a test works for an empty square below a tree which is surrounded on all other sides. + */ + @Test + public void EmptyFieldTest_Down() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown", 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, 2); + cell1.setData(TreeTentType.TENT); + + board.addModifiedData(cell1); + + 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(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * + * Checks if a test works for an empty square to the left of a tree which is surrounded on all other sides. + */ + @Test + public void EmptyFieldTest_Left() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0, 1); + cell1.setData(TreeTentType.TENT); + + board.addModifiedData(cell1); + + 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(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * + * Checks if a test works for an empty square to the right of a tree which is surrounded on all other sides. + */ + @Test + public void EmptyFieldTest_Right() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(2, 1); + cell1.setData(TreeTentType.TENT); + + board.addModifiedData(cell1); + + 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(cell1.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } } diff --git a/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java b/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java new file mode 100644 index 000000000..c7159ccad --- /dev/null +++ b/src/test/java/puzzles/treetent/rules/TentOrGrassCaseRuleTest.java @@ -0,0 +1,54 @@ +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; +import legup.TestUtilities; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.awt.*; +import java.util.ArrayList; + +public class TentOrGrassCaseRuleTest { + private static final TentOrGrassCaseRule RULE = new TentOrGrassCaseRule(); + private static TreeTent treetent; + + @BeforeClass + public static void setUp(){ + MockGameBoardFacade.getInstance(); + treetent = new TreeTent(); + } + + /** + * @throws InvalidFileFormatException + * A temporary test + */ + @Test + public void TentOrGrassCaseRule_Test() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest", 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); + 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. + + } + +} diff --git a/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java index bfcb80a23..a5999dc6e 100644 --- a/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TooFewTentsContradictionRuleTest.java @@ -1,5 +1,6 @@ package puzzles.treetent.rules; +import edu.rpi.legup.puzzle.treetent.TreeTentCell; import legup.MockGameBoardFacade; import legup.TestUtilities; import edu.rpi.legup.model.tree.TreeNode; @@ -10,8 +11,6 @@ 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.TooFewTentsContradictionRule; import edu.rpi.legup.save.InvalidFileFormatException; @@ -28,9 +27,46 @@ public static void setUp() { treetent = new TreeTent(); } + /** + * @throws InvalidFileFormatException + * Using a 1x1 Puzzle Grid, which is just grass, checks if the fact it expects a tent on the y-axis is caught. + */ + @Test + public void TooFewTentsContradictionRule_JustY() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsJustY", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + Assert.assertNull(RULE.checkContradiction(board)); + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); + } + + /** + * @throws InvalidFileFormatException + * Using a 1x1 Puzzle Grid, which is just a tent, checks if the fact it expects 2 tents on the y-axis is caught. + * (This is an impossible situation given the constraints, but for the purposes of the test it is fine) + */ + @Test + public void TooFewTentsContradictionRule_WithTent() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + Assert.assertNull(RULE.checkContradiction(board)); + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); + } + + /** + * @throws InvalidFileFormatException + * Using a 1x1 Puzzle Grid, which is just grass, checks if the fact it expects a tent on both x and y is caught. + */ @Test - public void TooFewTentsContradictionRule_() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents", treetent); + public void TooFewTentsContradictionRule_DoubleBad() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad", treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); @@ -39,5 +75,177 @@ public void TooFewTentsContradictionRule_() throws InvalidFileFormatException { Assert.assertNull(RULE.checkContradiction(board)); Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(0, 0))); } + + /** + * @throws InvalidFileFormatException + * Looks at a 2x2 Board in the format: + * [] Tr + * [] Gr + * Column 2 is checked to have 1 Tent (which is not present, thus producing a contradiction) + */ + @Test + public void TooFewTentsContradictionRule_2x2ColumnOnly() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + Assert.assertNull(RULE.checkContradiction(board)); + + TreeTentCell cell1 = board.getCell(1,0); + TreeTentCell cell2 = board.getCell(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(cell1.getLocation()) || point.equals(cell2.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Looks at a 2x2 Board in the format: + * Tr Gr + * [] [] + * Row 1 is checked to have 1 Tent (which is not present, thus producing a contradiction) + */ + @Test + public void TooFewTentsContradictionRule_2x2RowOnly() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + Assert.assertNull(RULE.checkContradiction(board)); + + TreeTentCell cell1 = board.getCell(0,0); + TreeTentCell cell2 = board.getCell(1,0); + + 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())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Looks at a 3x3 Board in the format: + * [] Tr [] + * [] Gr [] + * [] Gr [] + * Column 2 is checked to have 1 Tent (which is not present, thus producing a contradiction) + */ + @Test + public void TooFewTentsContradictionRule_3x3OneColumn() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + Assert.assertNull(RULE.checkContradiction(board)); + + TreeTentCell cell1 = board.getCell(1,0); + TreeTentCell cell2 = board.getCell(1,1); + TreeTentCell cell3 = board.getCell(1,2); + + 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())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Looks at a 3x3 Board in the format: + * Gr Tr Gr + * Gr [] Gr + * Gr Tr Gr + * Column 1 and 3 are checked to have 1 Tent (which is not present, thus producing a contradiction) + */ + @Test + public void TooFewTentsContradictionRule_3x3TwoColumn() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + Assert.assertNull(RULE.checkContradiction(board)); + + TreeTentCell cell1 = board.getCell(0,0); + TreeTentCell cell2 = board.getCell(0,1); + TreeTentCell cell3 = board.getCell(0,2); + TreeTentCell cell4 = board.getCell(2,0); + TreeTentCell cell5 = board.getCell(2,1); + TreeTentCell cell6 = board.getCell(2,2); + + 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()) || + point.equals(cell4.getLocation()) || point.equals(cell5.getLocation()) || point.equals(cell6.getLocation())) { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Looks at a 2x2 Board in the format: + * Tn [] + * Tr [] + * This should fail the contradiction as it is a legal board. + */ + @Test + public void TooFewTentsContradictionRule_NoContradiction() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + Assert.assertNotNull(RULE.checkContradiction(board)); + + 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/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java b/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java index 2845c7b25..2a351556b 100644 --- a/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/TooManyTentsContradictionRuleTest.java @@ -28,17 +28,162 @@ public static void setUp() { treetent = new TreeTent(); } + /* + TESTING BASIS: + All test in this Rule use a 3x3 table. + There is a Tree at (1,1) + There are tents at (0,1) and (2,2) + All Tent Counts are listed left to right or top to bottom + */ + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTents if: + * Row Tent Counts: 0,0,0 + * Column Tent Counts: 0,0,0 + */ + @Test + public void TooManyTentsContradictionRule_TotalFail() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTotalFail",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0,1); + + Assert.assertNull(RULE.checkContradiction(board)); + + 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())) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTents if: + * Row Tent Counts: 1,0,0 + * Column Tent Counts: 0,0,0 + */ + @Test + public void TooManyTentsContradictionRule_TopRight() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopRight",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0,0); + TreeTentCell cell2 = board.getCell(0,1); + + Assert.assertNull(RULE.checkContradiction(board)); + + 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())) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTests if: + * Row Tent Counts: 0,0,1 + * Column Tent Counts: 0,0,0 + */ + @Test + public void TooManyTentsContradictionRule_BottomRight() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomRight",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0,1); + TreeTentCell cell2 = board.getCell(0,2); + + Assert.assertNull(RULE.checkContradiction(board)); + + 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())) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTents if: + * Row Tent Counts: 0,0,0 + * Column Tent Counts: 0,1,0 + */ + @Test + public void TooManyTentsContradictionRule_TopDown() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopDown",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0,1); + TreeTentCell cell2 = board.getCell(1,1); + + Assert.assertNull(RULE.checkContradiction(board)); + + 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())) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTents if: + * Row Tent Counts: 0,0,0 + * Column Tent Counts: 0,0,1 + */ @Test - public void TooManyTentsContradictionRule_Column_Row() throws InvalidFileFormatException { - TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsContradictionRuleColumn_Row", treetent); + public void TooManyTentsContradictionRule_BottomDown() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomDown",treetent); TreeNode rootNode = treetent.getTree().getRootNode(); TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); TreeTentBoard board = (TreeTentBoard) transition.getBoard(); - TreeTentCell cell1 = board.getCell(0, 1); - TreeTentCell cell2 = board.getCell(2, 1); + TreeTentCell cell1 = board.getCell(0,1); + TreeTentCell cell2 = board.getCell(2,1); Assert.assertNull(RULE.checkContradiction(board)); @@ -49,9 +194,78 @@ public void TooManyTentsContradictionRule_Column_Row() throws InvalidFileFormatE Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } else { - // The TooManyTentsContradictionRule checks the col and row the cell is in - // Therefore, even if a cell(0, 0) is empty, it follows the contradiction rule because - // the row it is in follows the contradiciton rule. (And because cell(1, 0) has tent row tent total is 0) + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTents if the Top Tent is completely accounted for, but not the bottom + * Row Tent Counts: 1,0,0 + * Column Tent Counts: 0,1,0 + */ + @Test + public void TooManyTentsContradictionRule_TopAccount() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopAccount",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0,0); + TreeTentCell cell2 = board.getCell(1,0); + TreeTentCell cell3 = board.getCell(0,1); + TreeTentCell cell4 = board.getCell(1,1); + + Assert.assertNull(RULE.checkContradiction(board)); + + 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()) || point.equals(cell4.getLocation())) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { + Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + } + } + } + + /** + * @throws InvalidFileFormatException + * Tests for TooManyTents if the Bottom Tent is completely accounted for, but not the Top + * Row Tent Counts: 0,0,1 + * Column Tent Counts: 0,0,1 + */ + @Test + public void TooManyTentsContradictionRule_BottomAccount() throws InvalidFileFormatException{ + TestUtilities.importTestBoard("puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomAccount",treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + TreeTentCell cell1 = board.getCell(0,1); + TreeTentCell cell2 = board.getCell(2,1); + TreeTentCell cell3 = board.getCell(0,2); + TreeTentCell cell4 = board.getCell(2,2); + + Assert.assertNull(RULE.checkContradiction(board)); + + 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()) || point.equals(cell4.getLocation())) { + Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + } + else { Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i))); } } diff --git a/src/test/resources/puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrassJustRow b/src/test/resources/puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrassJustRow new file mode 100644 index 000000000..3e293d22f --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrassJustRow @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrassJustTent b/src/test/resources/puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrassJustTent new file mode 100644 index 000000000..cbd3662e6 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/FinishWithGrassDirectRule/FinishWithGrassJustTent @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsBothWays b/src/test/resources/puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsBothWays new file mode 100644 index 000000000..c4d58ef60 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/FinishWithTentsDirectRule/FinishWithTentsBothWays @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown new file mode 100644 index 000000000..cb19ab33f --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotDown @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft new file mode 100644 index 000000000..e70dc4be5 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotLeft @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight new file mode 100644 index 000000000..64ddf29db --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotRight @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpot b/src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp similarity index 100% rename from src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpot rename to src/test/resources/puzzles/treetent/rules/LastCampingSpotDirectRule/LastCampingSpotUp diff --git a/src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest b/src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest new file mode 100644 index 000000000..9ae8455e1 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TentOrGrassCaseRule/TentOrGrassTest @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column new file mode 100644 index 000000000..0f78702c4 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Column @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row new file mode 100644 index 000000000..c423b179b --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents2x2Row @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column new file mode 100644 index 000000000..d1e79a76e --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3Column @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn new file mode 100644 index 000000000..e71832f08 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents3x3DoubleColumn @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad new file mode 100644 index 000000000..ecc8988c6 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsDoubleBad @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsJustY similarity index 100% rename from src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTents rename to src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsJustY diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction new file mode 100644 index 000000000..2f609e161 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsNoContradiction @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent new file mode 100644 index 000000000..8ae51f0a3 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooFewTentsContradictionRule/TooFewTentsWithTent @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomAccount b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomAccount new file mode 100644 index 000000000..8474e916a --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomAccount @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsContradictionRuleColumn_Row b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomDown similarity index 93% rename from src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsContradictionRuleColumn_Row rename to src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomDown index 78e956c35..8051a5501 100644 --- a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsContradictionRuleColumn_Row +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomDown @@ -8,7 +8,7 @@ - + diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomMissDown b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomMissDown new file mode 100644 index 000000000..3cbb1cdb4 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomMissDown @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomMissRight b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomMissRight new file mode 100644 index 000000000..d22778c4e --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomMissRight @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomRight b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomRight new file mode 100644 index 000000000..aeb4cd148 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsBottomRight @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopAccount b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopAccount new file mode 100644 index 000000000..258e32d47 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopAccount @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopDown b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopDown new file mode 100644 index 000000000..58d4bbddf --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopDown @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopRight b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopRight new file mode 100644 index 000000000..dd5b7b935 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTopRight @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTotalFail b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTotalFail new file mode 100644 index 000000000..9fbb8b82f --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/TooManyTentsContradictionRule/TooManyTentsTotalFail @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file