From cf72a8194e5aea711ac89f580425fa0ec31c25cf Mon Sep 17 00:00:00 2001
From: Kevin-771 <70790256+Kevin-771@users.noreply.github.com>
Date: Tue, 10 Oct 2023 16:55:21 -0400
Subject: [PATCH 1/3] EmptyFieldTest
added test to EmptyFieldTest
added comments to tests in EmptyFieldTest
---
.../rules/EmptyFieldDirectRuleTest.java | 72 ++++++++++++++++---
.../rules/EmptyFieldDirectRule/EmptyFieldFail | 23 ++++++
2 files changed, 85 insertions(+), 10 deletions(-)
create mode 100644 src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFail
diff --git a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
index 50e2bb970..c40bf5903 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,65 @@ 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 center 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));
+ }
+ }
+ }
}
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
From ef8d09e02ff48ded15523f5d23f803accea4cafe Mon Sep 17 00:00:00 2001
From: Kevin-771 <70790256+Kevin-771@users.noreply.github.com>
Date: Tue, 10 Oct 2023 17:11:06 -0400
Subject: [PATCH 2/3] editted comments
---
.../java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
index c40bf5903..fa9706cd6 100644
--- a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
+++ b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
@@ -106,7 +106,7 @@ public void DiagonalTreeTest() throws InvalidFileFormatException {
// creates a 3x3 puzzle with 4 trees
// trees are at (0,1), (1,0), (1,2), and (2,1)
- // make the center tile GRASS.
+ // make the (1,1) tile GRASS.
// checks if tiles don't logically follow the EmptyFieldDirectRule
@Test
public void EmptyFieldTestFail() throws InvalidFileFormatException {
From f9cb9cf041bd3ab21f36bc8fa48f8bb2e9d809a3 Mon Sep 17 00:00:00 2001
From: Kevin-771 <70790256+Kevin-771@users.noreply.github.com>
Date: Tue, 10 Oct 2023 17:28:16 -0400
Subject: [PATCH 3/3] added more tests
---
.../rules/EmptyFieldDirectRuleTest.java | 132 ++++++++++++++++++
.../EmptyFieldDirectRule/EmptyFieldFailBottom | 20 +++
.../EmptyFieldDirectRule/EmptyFieldFailLeft | 20 +++
.../EmptyFieldDirectRule/EmptyFieldFailRight | 20 +++
.../EmptyFieldDirectRule/EmptyFieldFailTop | 20 +++
5 files changed, 212 insertions(+)
create mode 100644 src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailBottom
create mode 100644 src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailLeft
create mode 100644 src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailRight
create mode 100644 src/test/resources/puzzles/treetent/rules/EmptyFieldDirectRule/EmptyFieldFailTop
diff --git a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
index fa9706cd6..b7ec8eb02 100644
--- a/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
+++ b/src/test/java/puzzles/treetent/rules/EmptyFieldDirectRuleTest.java
@@ -136,5 +136,137 @@ public void EmptyFieldTestFail() throws InvalidFileFormatException {
}
}
}
+
+ // 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/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