forked from neojski/paper-naive-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue neojski#21 - improved sudoku generator with test.
- Loading branch information
Showing
2 changed files
with
177 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package bullshit_paper; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
||
public class SudokuGeneratorTest { | ||
|
||
private final SudokuGenerator generator = new SudokuGenerator(); | ||
|
||
|
||
@Test | ||
public void testThereAreNoDuplicatesInRows() { | ||
Sudoku sudoku = generator.generate(); | ||
Boolean duplicate = false; | ||
|
||
for(int i=0; i<9; i++){ | ||
Set<Integer> set = new HashSet<Integer>(); | ||
int value; | ||
for(int j=0; j<9; j++){ | ||
if((value = sudoku.get(i, j))!=0){ | ||
if(set.contains(value)){ | ||
duplicate = false; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Anitka
via email
Author
Collaborator
|
||
break; | ||
} | ||
set.add(value); | ||
} | ||
} | ||
if(!duplicate) break; | ||
} | ||
|
||
Assert.assertFalse(duplicate); | ||
} | ||
|
||
@Test | ||
public void testThereAreNoDuplicatesInColumns() { | ||
Sudoku sudoku = generator.generate(); | ||
Boolean duplicate = false; | ||
|
||
for(int i=0; i<9; i++){ | ||
Set<Integer> set = new HashSet<Integer>(); | ||
int value; | ||
for(int j=0; j<9; j++){ | ||
if((value = sudoku.get(j, i))!=0){ | ||
if(set.contains(value)){ | ||
duplicate = false; | ||
break; | ||
} | ||
set.add(value); | ||
} | ||
} | ||
if(!duplicate) break; | ||
} | ||
|
||
Assert.assertFalse(duplicate); | ||
} | ||
|
||
@Test | ||
public void testThereAreNoDuplicatesInSquares() { | ||
Sudoku sudoku = generator.generate(); | ||
Boolean duplicate = false; | ||
int c = 0; | ||
int r = 0; | ||
int value; | ||
|
||
for(int i=0; i<9; i++){ | ||
Set<Integer> set = new HashSet<Integer>(); | ||
c = 0; | ||
for(int k=r; k<r+3; k++){ | ||
for(int j=c; j<c+3; j++){ | ||
if((value = sudoku.get(i, j))!=0){ | ||
if(set.contains(value)){ | ||
duplicate = false; | ||
break; | ||
} | ||
set.add(value); | ||
} | ||
} | ||
c++; | ||
} | ||
r+=3; | ||
} | ||
|
||
Assert.assertFalse(duplicate); | ||
} | ||
|
||
} | ||
|
||
|
duplicate = true
, chyba.