diff --git a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java index 50e2bb970..b7ec8eb02 100644 --- a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java +++ b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java @@ -27,6 +27,9 @@ public static void setUp() { treetent = new TreeTent(); } + // creates a 3x3 puzzle with no trees + // make the (1,1) tile GRASS + // checks if tiles logically follow the EmptyFieldDirectRule @Test public void EmptyFieldTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyField", treetent); @@ -34,28 +37,38 @@ public void EmptyFieldTest() throws InvalidFileFormatException { TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); + // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + // change the board's cells considering the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); - board.addModifiedData(cell1); + // confirm there is a logical following of the EmptyField rule Assert.assertNull(RULE.checkRule(transition)); + // only the cell above should change following the rule + TreeTentCell c; 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))); + c = board.getCell(k, i); + if (c.getLocation().equals(cell1.getLocation())) { + // logically follows + Assert.assertNull(RULE.checkRuleAt(transition, c)); } else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } } } + // creates a 3x3 puzzle with 4 trees + // trees are at (0,0), (2,0), (0,2), and (2,2) + // make the (1,1) tile GRASS. + // checks if tiles logically follow the EmptyFieldDirectRule @Test public void DiagonalTreeTest() throws InvalidFileFormatException { TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/DiagonalTree", treetent); @@ -63,26 +76,197 @@ public void DiagonalTreeTest() throws InvalidFileFormatException { TreeTransition transition = rootNode.getChildren().get(0); transition.setRule(RULE); + // get board state TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + //change the board's cells considering the EmptyField rule TreeTentCell cell1 = board.getCell(1, 1); cell1.setData(TreeTentType.GRASS); - board.addModifiedData(cell1); + // confirm there is a logical following of the EmptyField rule Assert.assertNull(RULE.checkRule(transition)); + // only the cell above should change following the rule + TreeTentCell c; 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))); + c = board.getCell(k, i); + if (c.getLocation().equals(cell1.getLocation())) { + // logically follows + Assert.assertNull(RULE.checkRuleAt(transition, c)); } else { - Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i))); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); } } } } + + // creates a 3x3 puzzle with 4 trees + // trees are at (0,1), (1,0), (1,2), and (2,1) + // make the (1,1) tile GRASS. + // checks if tiles don't logically follow the EmptyFieldDirectRule + @Test + public void EmptyFieldTestFail() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + // get board state + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + //change the board's cells considering breaking the EmptyField rule + TreeTentCell cell1 = board.getCell(1, 1); + cell1.setData(TreeTentType.GRASS); + board.addModifiedData(cell1); + + // confirm there is not a logical following of the EmptyField rule + Assert.assertNotNull(RULE.checkRule(transition)); + + // the cells should not follow the rule + TreeTentCell c; + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + c = board.getCell(j, i); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } + + // creates a 3x3 puzzle with 1 tree + // tree is at (1,0) + // make the (1,1) tile GRASS. + // checks if tiles don't logically follow the EmptyFieldDirectRule + @Test + public void EmptyFieldTestFailTop() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + // get board state + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + //change the board's cells considering breaking the EmptyField rule + TreeTentCell cell1 = board.getCell(1, 1); + cell1.setData(TreeTentType.GRASS); + board.addModifiedData(cell1); + + // confirm there is not a logical following of the EmptyField rule + Assert.assertNotNull(RULE.checkRule(transition)); + + // the cells should not follow the rule + TreeTentCell c; + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + c = board.getCell(j, i); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } + + // creates a 3x3 puzzle with 1 tree + // tree is at (1,2) + // make the (1,1) tile GRASS. + // checks if tiles don't logically follow the EmptyFieldDirectRule + @Test + public void EmptyFieldTestFailTopBottom() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + // get board state + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + //change the board's cells considering breaking the EmptyField rule + TreeTentCell cell1 = board.getCell(1, 1); + cell1.setData(TreeTentType.GRASS); + board.addModifiedData(cell1); + + // confirm there is not a logical following of the EmptyField rule + Assert.assertNotNull(RULE.checkRule(transition)); + + // the cells should not follow the rule + TreeTentCell c; + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + c = board.getCell(j, i); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } + + // creates a 3x3 puzzle with 1 tree + // tree is at (0,1) + // make the (1,1) tile GRASS. + // checks if tiles don't logically follow the EmptyFieldDirectRule + @Test + public void EmptyFieldTestFailLeft() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + // get board state + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + //change the board's cells considering breaking the EmptyField rule + TreeTentCell cell1 = board.getCell(1, 1); + cell1.setData(TreeTentType.GRASS); + board.addModifiedData(cell1); + + // confirm there is not a logical following of the EmptyField rule + Assert.assertNotNull(RULE.checkRule(transition)); + + // the cells should not follow the rule + TreeTentCell c; + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + c = board.getCell(j, i); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } + + // creates a 3x3 puzzle with 1 tree + // tree is at (2,1) + // make the (1,1) tile GRASS. + // checks if tiles don't logically follow the EmptyFieldDirectRule + @Test + public void EmptyFieldTestFailRight() throws InvalidFileFormatException { + TestUtilities.importTestBoard("puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight", treetent); + TreeNode rootNode = treetent.getTree().getRootNode(); + TreeTransition transition = rootNode.getChildren().get(0); + transition.setRule(RULE); + + // get board state + TreeTentBoard board = (TreeTentBoard) transition.getBoard(); + + //change the board's cells considering breaking the EmptyField rule + TreeTentCell cell1 = board.getCell(1, 1); + cell1.setData(TreeTentType.GRASS); + board.addModifiedData(cell1); + + // confirm there is not a logical following of the EmptyField rule + Assert.assertNotNull(RULE.checkRule(transition)); + + // the cells should not follow the rule + TreeTentCell c; + for (int i = 0; i < board.getWidth(); i++) { + for (int j = 0; j < board.getHeight(); j++) { + c = board.getCell(j, i); + // does not use the rule to logically follow + Assert.assertNotNull(RULE.checkRuleAt(transition, c)); + } + } + } } diff --git a/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail new file mode 100644 index 000000000..f826667e3 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom new file mode 100644 index 000000000..80deadaea --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft new file mode 100644 index 000000000..d19e01daf --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight new file mode 100644 index 000000000..bf3954964 --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop new file mode 100644 index 000000000..8eaa974ea --- /dev/null +++ b/src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file