Skip to content

Commit

Permalink
test: adding subject and main
Browse files Browse the repository at this point in the history
  • Loading branch information
amin authored and zanninso committed Jul 19, 2024
1 parent a89a441 commit caaa46a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
33 changes: 33 additions & 0 deletions subjects/java/checkpoints/valid-sudoku/ExerciseRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
public class ExerciseRunner {
public static void main(String[] args) {
ValidSudoku validSudoku = new ValidSudoku();

// Test case 1
char[][] board1 = {
{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board1 valid? " + validSudoku.isValidSudoku(board1)); // Expected output: true

// Test case 2
char[][] board2 = {
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board2 valid? " + validSudoku.isValidSudoku(board2)); // Expected output: false
}
}
71 changes: 71 additions & 0 deletions subjects/java/checkpoints/valid-sudoku/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Valid Sudoku

### Instructions

Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

1. Each row must contain the digits 1-9 without repetition.
2. Each column must contain the digits 1-9 without repetition.
3. Each of the nine 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition.

The Sudoku board could be partially filled, where empty cells are filled with the character '.'.

### Expected Class

```java
public class ValidSudoku {
public boolean isValidSudoku(char[][] board) {
// Implementation to determine if the Sudoku board is valid
}
}
```

### Usage

Here is a possible `ExerciseRunner.java` to test your class:

```java
public class ExerciseRunner {
public static void main(String[] args) {
ValidSudoku validSudoku = new ValidSudoku();

// Test case 1
char[][] board1 = {
{'5', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board1 valid? " + validSudoku.isValidSudoku(board1)); // Expected output: true

// Test case 2
char[][] board2 = {
{'8', '3', '.', '.', '7', '.', '.', '.', '.'},
{'6', '.', '.', '1', '9', '5', '.', '.', '.'},
{'.', '9', '8', '.', '.', '.', '.', '6', '.'},
{'8', '.', '.', '.', '6', '.', '.', '.', '3'},
{'4', '.', '.', '8', '.', '3', '.', '.', '1'},
{'7', '.', '.', '.', '2', '.', '.', '.', '6'},
{'.', '6', '.', '.', '.', '.', '2', '8', '.'},
{'.', '.', '.', '4', '1', '9', '.', '.', '5'},
{'.', '.', '.', '.', '8', '.', '.', '7', '9'}
};
System.out.println("Is board2 valid? " + validSudoku.isValidSudoku(board2)); // Expected output: false
}
}
```

### Expected Output

```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Is board1 valid? true
Is board2 valid? false
$
```

0 comments on commit caaa46a

Please sign in to comment.