Test: Simple row populate test

This commit is contained in:
Jonas Zeunert
2024-02-19 18:28:21 +01:00
parent 0ef4449e43
commit 4199084e6b
3 changed files with 34 additions and 23 deletions

View File

@@ -1,10 +1,11 @@
use crate::playfield::Field;
use crate::playfield::Playfield;
pub struct SudokuSolver {
playfield: Playfield,
}
impl SudokuSolver {
impl<'a> SudokuSolver {
pub fn new(playfield: &Playfield) -> SudokuSolver {
Self {
playfield: playfield.clone(),
@@ -15,27 +16,41 @@ impl SudokuSolver {
}
fn populate_possible_values(&self) {
for row in &self.playfield.fields {
for field in row {
if field.value.is_some() {
continue;
}
}
}
for open_field in &self.playfield.open_fields {}
}
fn possible_values_from_row(&self, row: Vec<Field>) -> Vec<u32> {}
}
#[cfg(test)]
mod tests {
use crate::sudoku_solver::SudokuSolver;
use crate::Playfield;
fn create_test_playfield(input: &str, size: usize) -> Playfield {
Playfield::new(&input.to_string(), size)
}
mod solve {
use super::super::*;
use super::*;
#[test]
fn simple() {
let playfield = Playfield::new(&"1 2 3 2 3 1 3 1 0".to_string(), 3);
let expected = Playfield::new(&"1 2 3 2 3 1 3 1 2".to_string(), 3);
let playfield = create_test_playfield("1 2 3 2 3 1 3 1 0", 3);
let expected = create_test_playfield("1 2 3 2 3 1 3 1 2", 3);
let solved = SudokuSolver::new(&playfield).solve();
assert_eq!(solved, expected);
}
}
mod populate_possible_values {
mod possible_values_from_row {
use super::super::*;
#[test]
fn simple() {
let playfield = create_test_playfield("1 2 0 1 2 0 1 2 0", 3);
let expected = vec![3];
let possible_values =
SudokuSolver::new(&playfield).possible_values_from_row(playfield.fields[0]);
assert_eq!(possible_values, expected);
}
}
}
}