Skip to content

Commit

Permalink
More Tests for RepeatedNumbers
Browse files Browse the repository at this point in the history
Added another test for RepeatedNumbers contradiction rule and fixed previous error.
  • Loading branch information
EggyMath committed Apr 9, 2024
1 parent 077505d commit 70de0d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import edu.rpi.legup.puzzle.sudoku.Sudoku;
import edu.rpi.legup.puzzle.sudoku.SudokuBoard;
import edu.rpi.legup.puzzle.sudoku.SudokuCell;
import edu.rpi.legup.puzzle.sudoku.rules.LastNumberForCellDirectRule;
import edu.rpi.legup.puzzle.sudoku.rules.RepeatedNumberContradictionRule;
import edu.rpi.legup.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
Expand All @@ -25,7 +24,7 @@ public static void setUp() {
@Test
public void RepeatedNumberContradictionRule_GlobalTest() throws InvalidFileFormatException {
//Import board and create transition
TestUtilities.importTestBoard("puzzles/sudoku/rules/RepeatedNumberContradictionRule/BlankBoard", sudoku);
TestUtilities.importTestBoard("puzzles/sudoku/rules/RepeatedNumberContradictionRule/BlankBoard7", sudoku);
TreeNode rootNode = sudoku.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);
Expand All @@ -37,8 +36,9 @@ public void RepeatedNumberContradictionRule_GlobalTest() throws InvalidFileForma
//Set cell
int x = i / 9;
int y = i % 9;
if(x == 0 && y == 0)
if(x == 0 && y == 0) {
continue;
}
SudokuCell cell = board.getCell(x, y);
cell.setData(7);

Expand All @@ -50,6 +50,33 @@ public void RepeatedNumberContradictionRule_GlobalTest() throws InvalidFileForma
}
cell.setData(0);
}
//Import board and create transition
TestUtilities.importTestBoard("puzzles/sudoku/rules/RepeatedNumberContradictionRule/BlankBoard4", sudoku);
rootNode = sudoku.getTree().getRootNode();
transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

//Loop through every cell
for(int i = 0; i < 81; i++){
//Reset board
SudokuBoard board = (SudokuBoard) transition.getBoard();
//Set cell
int x = i / 9;
int y = i % 9;
if((x == 3 && y == 0) || (x == 6 && y == 8)) {
continue;
}
SudokuCell cell = board.getCell(x, y);
cell.setData(4);

//Test the case
if((x == 3 || y == 0 || x == 6 || y == 8) || (x > 2 && x < 6 && y < 3) || (x > 5 && y > 5)){
Assert.assertNull(RULE.checkRuleAt(transition, cell));
} else {
Assert.assertNotNull(RULE.checkRuleAt(transition, cell));
}
cell.setData(0);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup>
<puzzle name="Sudoku">
<board size="9">
<cells>
<cell value="4" x="3" y="0"/>
<cell value="4" x="6" y="8"/>
</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>

0 comments on commit 70de0d7

Please sign in to comment.