Skip to content

Commit

Permalink
Merge branch 'sudoku' of https://github.com/Bram-Hub/LEGUP into sudoku
Browse files Browse the repository at this point in the history
  • Loading branch information
kchiu1 committed Apr 9, 2024
2 parents ceab905 + f764c37 commit 8809416
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ gradle-app.setting
gradle/wrapper/gradle-wrapper.properties

# Visual Studio Code configs
.vscode/*
.vscode/*
src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Legup version="2.0.0">
<puzzle name="Sudoku">
<board size="9">
<cells>
<cell value="1" x="0" y="3"/>
<cell value="2" x="1" y="3"/>
<cell value="3" x="2" y="3"/>
<cell value="4" x="0" y="4"/>
<cell value="5" x="1" y="4"/>
<cell value="6" x="2" y="4"/>
<cell value="7" x="0" y="5"/>
<cell value="8" x="1" y="5"/>

</cells>
</board>
</puzzle>
<solved isSolved="false" lastSaved="--"/>
</Legup>
5 changes: 5 additions & 0 deletions src/test/java/legup/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import puzzles.battleship.rules.*;
import puzzles.lightup.rules.*;
import puzzles.nurikabe.rules.*;
import puzzles.sudoku.rules.LastNumberForCellDirectRuleRegionTest;
import puzzles.treetent.rules.*;

/**
Expand Down Expand Up @@ -93,6 +94,10 @@ public static void main(String[] args) {
printTestResults(result35);
Result result36 = JUnitCore.runClasses(TentOrGrassCaseRuleTest.class);
printTestResults(result36);

//Sudoku Tests
Result result37 = JUnitCore.runClasses(LastNumberForCellDirectRuleRegionTest.class);
printTestResults(result37);
}

private static void printTestResults(Result result) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package puzzles.sudoku.rules;

import edu.rpi.legup.model.tree.TreeNode;
import edu.rpi.legup.model.tree.TreeTransition;
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.save.InvalidFileFormatException;
import legup.MockGameBoardFacade;
import legup.TestUtilities;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class LastNumberForCellDirectRuleRegionTest {
private static final LastNumberForCellDirectRule RULE = new LastNumberForCellDirectRule();
private static Sudoku sudoku;
@BeforeClass
public static void setUp() {
MockGameBoardFacade.getInstance();
sudoku = new Sudoku();
}
@Test
public void LastNumberForCellDirectRule_FullRegionTest() throws InvalidFileFormatException {
//Import board and create transition
TestUtilities.importTestBoard("puzzles/sudoku/rules/LastNumberForCellDirectRule/FullRegion", sudoku);
TreeNode rootNode = sudoku.getTree().getRootNode();
TreeTransition transition = rootNode.getChildren().get(0);
transition.setRule(RULE);

for(int i = 1; i < 10; i++){
//Reset board
SudokuBoard board = (SudokuBoard) transition.getBoard();
//Set cell
SudokuCell cell1 = board.getCell(2, 5);
cell1.setData(i);
board.addModifiedData(cell1);

//Test the case
if(i == 9) {
Assert.assertNull(RULE.checkRuleAt(transition, cell1));
} else {
Assert.assertNotNull(RULE.checkRuleAt(transition, cell1));
}
}

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

0 comments on commit 8809416

Please sign in to comment.