Skip to content

Commit

Permalink
Merge pull request #678 from Relurk1/master
Browse files Browse the repository at this point in the history
Complete Nurikabe test suite
  • Loading branch information
jac-oblong authored Nov 17, 2023
2 parents d749c84 + 9ac7253 commit deadd83
Show file tree
Hide file tree
Showing 50 changed files with 1,296 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions bin/main/edu/rpi/legup/log4j2.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Logging level
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=Legup.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
# Logging level
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=Legup.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from top left to bottom right)
*/
@Test
public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions1", nurikabe);
Expand Down Expand Up @@ -62,6 +65,9 @@ public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions1Test() thr
}
}

/**
* Tests the Black Between Regions direct rule for regions that are diagonal to each other (diagonal going from bottom left to top right)
*/
@Test
public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/DiagonalBlackBetweenRegions2", nurikabe);
Expand Down Expand Up @@ -94,6 +100,9 @@ public void BlackBetweenRegionsDirectRule_DiagonalBlackBetweenRegions2Test() thr
}
}

/**
* Tests the Black Between Regions direct rule for regions that are horizontally opposite each other
*/
@Test
public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/HorizontalBlackBetweenRegions", nurikabe);
Expand Down Expand Up @@ -123,6 +132,9 @@ public void BlackBetweenRegionsDirectRule_HorizontalBlackBetweenRegionsTest() th
}
}

/**
* Tests the Black Between Regions direct rule for regions that are vertically opposite each other
*/
@Test
public void BlackBetweenRegionsDirectRule_VerticalBlackBetweenRegionsTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBetweenRegionsDirectRule/VerticalBlackBetweenRegions", nurikabe);
Expand Down Expand Up @@ -151,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 @@ -27,6 +27,9 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black BottleNeck direct rule for a bottleneck in the center of the board
*/
@Test
public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/SimpleBlackBottleNeck", nurikabe);
Expand Down Expand Up @@ -54,4 +57,64 @@ public void BlackBottleNeckDirectRule_TwoSurroundBlackTest() throws InvalidFileF
}
}
}


/**
* Tests the Black BottleNeck direct rule for a bottleneck in the corner of the board
*/
@Test
public void BlackBottleNeckDirectRule_CornerBottleneck() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/CornerBottleNeck", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

board.addModifiedData(cell);

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


/**
* Tests the Black BottleNeck direct rule for a false bottleneck
*/
@Test
public void BlackBottleNeckDirectRule_FalseBottleneck() throws InvalidFileFormatException{
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackBottleNeckDirectRule/FalseBottleNeck", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

NurikabeBoard board = (NurikabeBoard)transition.getBoard();
NurikabeCell cell = board.getCell(0,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)));
}
}
}
}


50 changes: 37 additions & 13 deletions src/test/java/puzzles/nurikabe/rules/BlackOrWhiteCaseRuleTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package puzzles.nurikabe.rules;

import edu.rpi.legup.model.gameboard.Board;
import edu.rpi.legup.puzzle.nurikabe.NurikabeBoard;
import edu.rpi.legup.puzzle.nurikabe.NurikabeCell;
import edu.rpi.legup.puzzle.nurikabe.NurikabeType;
import edu.rpi.legup.puzzle.nurikabe.rules.BlackOrWhiteCaseRule;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import edu.rpi.legup.model.tree.TreeNode;
Expand All @@ -12,11 +16,13 @@
import edu.rpi.legup.puzzle.nurikabe.rules.TooFewSpacesContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;

import java.util.ArrayList;

import java.awt.*;

public class BlackOrWhiteCaseRuleTest {

private static final TooFewSpacesContradictionRule RULE = new TooFewSpacesContradictionRule();
private static final BlackOrWhiteCaseRule RULE = new BlackOrWhiteCaseRule();
private static Nurikabe nurikabe;

@BeforeClass
Expand All @@ -25,27 +31,45 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black Or White case rule by ensuring that it results in two children, that contain a modified cell that is either black or white
*/
@Test
public void TooFewSpacesContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/TooFewSpacesContradictionRule/TwoSurroundBlack", nurikabe);
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackOrWhiteCaseRule/SimpleBlackOrWhite", nurikabe);
TreeNode rootNode = nurikabe.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

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

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
Point location = new Point(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(location)) {
Assert.assertNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
}
else {
Assert.assertNotNull(RULE.checkRuleAt(transition, board.getCell(k, i)));
NurikabeCell cell = board.getCell(0,0);
ArrayList<Board> cases = RULE.getCases(board,cell);

Assert.assertEquals(2,cases.size());

NurikabeBoard caseBoard = (NurikabeBoard) cases.get(0);
NurikabeBoard caseBoard2 = (NurikabeBoard) cases.get(1);

NurikabeType board1Type = caseBoard.getCell(0,0).getType();
NurikabeType board2Type = caseBoard2.getCell(0,0).getType();

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

for(int i=0; i<caseBoard.getHeight(); i++){
for(int k=0; k<caseBoard.getWidth(); k++){
Point point = new Point(k,i);
if(point.equals(caseBoard.getCell(k,i).getLocation())){
continue;
}
Assert.assertTrue(caseBoard.getCell(k,i).equals(caseBoard2.getCell(k,i)));
}
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static void setUp() {
nurikabe = new Nurikabe();
}

/**
* Tests the Black Square contradiction rule for a black square in the middle of the board
*/
@Test
public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFileFormatException {
TestUtilities.importTestBoard("puzzles/nurikabe/rules/BlackSquareContradictionRule/SimpleBlackSquare", nurikabe);
Expand Down Expand Up @@ -53,4 +56,56 @@ public void BlackSquareContradictionRule_TwoSurroundBlackTest() throws InvalidFi
}
}
}

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

NurikabeBoard board = (NurikabeBoard) transition.getBoard();
NurikabeCell cell1 = board.getCell(2,2);
NurikabeCell cell2 = board.getCell(2,3);
NurikabeCell cell3 = board.getCell(3,2);
NurikabeCell cell4 = board.getCell(3,3);

Assert.assertNull(RULE.checkContradiction((NurikabeBoard) transition.getBoard()));
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.assertNull(RULE.checkRuleAt(transition,board.getCell(k,i)));
}
else{
Assert.assertNotNull(RULE.checkRuleAt(transition,board.getCell(k,i)));
}
}
}
}

/**
* 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)));
}
}
}
}
Loading

0 comments on commit deadd83

Please sign in to comment.