Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Nurikabe test suite #678

Merged
merged 12 commits into from
Nov 17, 2023
Prev Previous commit
Changes and additions to test suite
This commit includes:
- A change for readability made in the case rule, replacing Integer objects with NurikabeType
- Adding false test cases where necessary
- Updating test cases where necessary
  • Loading branch information
Relurk1 committed Nov 14, 2023
commit 9ac7253f2b35a65af08597e09f0ad91e9dda1b9e
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 163,28 @@ public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() thro
}
}
}

/**
* Tests the Black Between Regions direct rule for a false application of the rule, where a black tile is enclosed by one region
*/
@Test
public void BlackBetweenRegionsDirectRule_FalseBlackBetweenRegionsTest() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/FalseBlackBetweenRegions",nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
NurikabeCell cell = board.getCell(1,1);
cell.setData(NurikabeType.BLACK.toValue());
board.addModifiedData(cell);

Assert.assertNotNull(RULE.checkRule(transition));

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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 50,12 @@ public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidF
NurikabeBoard caseBoard = (NurikabeBoard) cases.get(0);
NurikabeBoard caseBoard2 = (NurikabeBoard) cases.get(1);

Integer v1 = new Integer(0);
Integer v2 = new Integer(-1);
NurikabeType board1Type = caseBoard.getCell(0,0).getType();
NurikabeType board2Type = caseBoard2.getCell(0,0).getType();

Assert.assertTrue((caseBoard.getCell(0,0).getData().equals(v1) || caseBoard.getCell(0,0).equals(v2)) &&
(caseBoard2.getCell(0,0).getData().equals(v1) || caseBoard2.getCell(0,0).getData().equals(v2)));
Assert.assertFalse(caseBoard.getCell(0,0).getData().equals(caseBoard2.getCell(0,0).getData()));
Assert.assertTrue((board1Type.equals(NurikabeType.BLACK) || board1Type.equals(NurikabeType.WHITE)) &&
(board2Type.equals(NurikabeType.BLACK) || board2Type.equals(NurikabeType.WHITE)));
Assert.assertFalse(board1Type.equals(board2Type));

Assert.assertEquals(caseBoard.getHeight(),caseBoard2.getHeight(), board.getHeight());
Assert.assertEquals(caseBoard.getWidth(),caseBoard2.getWidth(), board.getWidth());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 85,27 @@ public void BlackSquareContradictionRule_CornerSquareTest() throws InvalidFileFo
Assert.assertNotNull(RULE.checkRuleAt(transition,board.getCell(k,i)));
}
}
System.out.println();
}
}

/**
* Tests the Black Square contradiction rule for a false contradiction
*/
@Test
public void BlackSquareContradictionRule_FalseBlackSquareTest() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/FalseBlackSquare", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();

Assert.assertNotNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard()));

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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,7 @@ public static void setUp() {
*/
@Test
public void CornerBlackContradictionRule_SimpleCornerBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe);
TestUtilities.importTestBoard("puzzles/nurikabe/rules/CornerBlackDirectRule/SimpleCornerBlack", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
NurikabeBoard board = (NurikabeBoard) transition.getBoard();
Expand All @@ -43,12 43,12 @@ public void CornerBlackContradictionRule_SimpleCornerBlackTest() throws InvalidF
cell.setData(NurikabeType.BLACK.toValue());
board.addModifiedData(cell);

Assert.assertNotNull(RULE.checkRule(transition));
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(cell)) {
if(point.equals(cell.getLocation())) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Expand All @@ -57,4 57,28 @@ public void CornerBlackContradictionRule_SimpleCornerBlackTest() throws InvalidF
}
}
}

/**
* Tests the Corner Black direct rule for a false application of the rule
*/
@Test
public void CornerBlackContradictionRule_FalseCornerBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/CornerBlackDirectRule/FalseCornerBlack", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
NurikabeBoard board = (NurikabeBoard) transition.getBoard();
transition.setRule(RULE);

NurikabeCell cell = board.getCell(2, 0);
cell.setData(NurikabeType.BLACK.toValue());
board.addModifiedData(cell);

Assert.assertNotNull(RULE.checkRule(transition));

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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 117,27 @@ public void FillinBlackDirectRule_CornerTest2() throws InvalidFileFormatExceptio
}
}
}

/**
* Tests the Fillin Black direct rule for a false application of the rule
*/
@Test
public void FillinBlackDirectRule_FalseTest() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/FillinBlackDirectRule/FalseFillinBlack", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
NurikabeCell cell = board.getCell(1, 1);
cell.setData(NurikabeType.BLACK.toValue());
board.addModifiedData(cell);

Assert.assertNotNull(RULE.checkRule(transition));
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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 115,30 @@ public void FillinWhiteDirectRule_CornerTest2() throws InvalidFileFormatExceptio
}
}
}

/**
* Tests the Fillin White direct rule for a false application of the rule
*/
@Test
public void FillinWhiteDirectRule_FalseTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/FillinWhiteDirectRule/FalseFillinWhite", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
NurikabeCell cell = board.getCell(1,1);
cell.setData(NurikabeType.WHITE.toValue());
board.addModifiedData(cell);

Assert.assertNotNull(RULE.checkRule(transition));

Point location = new Point(1, 1);
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)));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 27,7 @@ public static void setUp() {
}

/**
* Tests the Isolate Black contradiction rule for a black squares in the corner, separated by a diagonal of white squares
* Tests the Isolate Black contradiction rule for a black square in the corner, separated by a diagonal of white squares
*/
@Test
public void IsolateBlackContradictionRule_SimpleIsolateBlackTest() throws InvalidFileFormatException {
Expand Down Expand Up @@ -85,4 85,24 @@ public void IsolateBlackContradictionRule_DiagonalBlackTest() throws InvalidFile
}
}
}

/**
* Tests the Isolate Black contradiction rule for a false contradiction
*/
@Test
public void IsolateBlackContradictionRule_FalseIsolateBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/IsolateBlackContradictionRule/FalseIsolateBlack",nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();

Assert.assertNotNull(RULE.checkRule(transition));
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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import org.codehaus.jackson.annotate.JsonTypeInfo;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -30,7 31,7 @@ public static void setUp() {
*/
@Test
public void NoNumberContradictionRule_NoNumberSurroundBlack() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberSurroundBlack", nurikabe);
TestUtilities.importTestBoard("puzzles/nurikabe/rules/NoNumberContradictionRule/SimpleNoNumber", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand All @@ -53,15 54,32 @@ public void NoNumberContradictionRule_NoNumberSurroundBlack() throws InvalidFile
}

/**
* Tests the No Number contradiction rule for multiple white regions not completely enclosed by black squares
* Tests the No Number contradiction rule for a false contradiction
*/
@Test
public void NoNumberContradictionRule_NoNumberReachable() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/NoNumberContradictionRule/NoNumberReachable", nurikabe);
public void NoNumberContradictionRule_FalseNoNumber() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

Assert.assertNotNull(RULE.checkRule(transition));
NurikabeBoard board = (NurikabeBoard) transition.getBoard();
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)));
}
}
}

@Test
public void NoNumberContradictionRule_FalseNoNumber2() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/NoNumberContradictionRule/FalseNoNumber2", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

Assert.assertNotNull(RULE.checkRule(transition));
NurikabeBoard board = (NurikabeBoard) transition.getBoard();
for (int i = 0; i < board.getHeight(); i ) {
for (int k = 0; k < board.getWidth(); k ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 146,24 @@ public void PreventBlackSquareDirectRule_TopRightWhiteBlackSquareTest() throws I
}
}
}

/**
* Tests the Prevent Black Square direct rule for a false contradiction
*/
@Test
public void PreventBlackSquareDirectRule_FalseTest() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/PreventBlackSquareDirectRule/FalseBlackSquare", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();


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)));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 99,26 @@ public void SurroundRegionDirectRule_SurroundRegionBlackInCornerTest() throws In
}
}
}


/**
* Tests the Surround Region direct rule for a false application of the rule
*/
@Test
public void SurroundRegionDirectRule_FalseSurroundRegionBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/SurroundRegionDirectRule/FalseSurroundRegion", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();

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)));
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 81,27 @@ public void TooFewSpacesContradictionRule_InsufficientSpaceTest() throws Invalid
}
}
}

/**
* Tests the Too Few Spaces contradiction rule for a false contradiction
*/
@Test
public void TooFewSpacesContradictionRule_FalseTooFewSpaces() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/FalseTooFewSpaces", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
NurikabeCell cell1 = board.getCell(1,1);


Assert.assertNotNull(RULE.checkContradiction((NurikabeBoard)transition.getBoard()));
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)));
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
import org.codehaus.jackson.annotate.JsonTypeInfo;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -73,4 74,28 @@ public void TooManySpacesContradictionRule_ExtraDiagonalSpace() throws InvalidFi
}
}
}

/**
* Tests the Too Many Spaces contradiction rule for a contradiction.with multiple numbers, wherein one of the numbers is larger than the region
*/
@Test
public void TooManySpacesContradictionRule_MultipleNumberRegion() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooManySpacesContradictionRule/MultipleNumberRegion", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard) transition.getBoard();

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(board.getCell(2,1).getLocation())){
Assert.assertNull(RULE.checkRuleAt(transition,board.getCell(k,i)));
}
}
}

}
}
Loading
Loading