add rudimentary tests for solvability of generated sudokus
This commit is contained in:
parent
90dabbdfda
commit
0ec07636a2
@ -91,7 +91,7 @@ pub fn generate_sudoku(difficulty: Difficulty) -> Board {
|
|||||||
/// TODO: currently empty cells needs to be recreated
|
/// TODO: currently empty cells needs to be recreated
|
||||||
/// on each recursive call, and are randomized anew
|
/// on each recursive call, and are randomized anew
|
||||||
/// each time, which is an unnecessary overhead.
|
/// each time, which is an unnecessary overhead.
|
||||||
fn solve_random(board: &mut Board) -> Result<(), ()> {
|
pub fn solve_random(board: &mut Board) -> Result<(), ()> {
|
||||||
let mut empty_cells: Vec<(usize, usize)> = Vec::new();
|
let mut empty_cells: Vec<(usize, usize)> = Vec::new();
|
||||||
|
|
||||||
let mut rows: Vec<usize> = (0..9).collect::<Vec<_>>();
|
let mut rows: Vec<usize> = (0..9).collect::<Vec<_>>();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use crate::{generate_sudoku, Board, Difficulty};
|
use crate::{generator::*, Board};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generated_sudoku_uniqueness() {
|
fn generated_sudoku_uniqueness() {
|
||||||
@ -30,3 +30,33 @@ fn generated_sudoku_uniqueness() {
|
|||||||
iterations - uniques.len()
|
iterations - uniques.len()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn generated_sudoku_solvability_small() {
|
||||||
|
use Difficulty::*;
|
||||||
|
|
||||||
|
let iterations = 20;
|
||||||
|
|
||||||
|
for difficulty in [Easy, Mid, Hard, Expert] {
|
||||||
|
for _ in 0..iterations {
|
||||||
|
let mut sudoku = generate_sudoku(difficulty);
|
||||||
|
solve_random(&mut sudoku).expect("Generated sudoku not solvable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[ignore]
|
||||||
|
fn generated_sudoku_solvability_large() {
|
||||||
|
use Difficulty::*;
|
||||||
|
|
||||||
|
let iterations = 400;
|
||||||
|
|
||||||
|
for difficulty in [Easy, Mid, Hard, Expert] {
|
||||||
|
for _ in 0..iterations {
|
||||||
|
let mut sudoku = generate_sudoku(difficulty);
|
||||||
|
solve_random(&mut sudoku).expect("Generated sudoku not solvable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user