Test: Simple row populate test
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub struct Playfield {
|
||||
size: usize,
|
||||
pub fields: Vec<Vec<Field>>,
|
||||
open_fields: Vec<u32>,
|
||||
pub open_fields: Vec<usize>,
|
||||
}
|
||||
|
||||
impl Playfield {
|
||||
@@ -11,7 +12,7 @@ impl Playfield {
|
||||
Self {
|
||||
size,
|
||||
fields: vec![vec![Field::default(); size]; size],
|
||||
open_fields: Vec::<u32>::new(),
|
||||
open_fields: Vec::new(),
|
||||
}
|
||||
}
|
||||
pub fn new(field: &String, size: usize) -> Playfield {
|
||||
@@ -34,10 +35,12 @@ impl Playfield {
|
||||
|
||||
for row in 0..self.size {
|
||||
for col in 0..self.size {
|
||||
let index = row * self.size + col;
|
||||
let field = &mut self.fields[row][col];
|
||||
let char_field = chars.get(row * self.size + col).unwrap();
|
||||
let char_field = chars.get(index).unwrap();
|
||||
|
||||
if *char_field == "0" {
|
||||
self.open_fields.push(index);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -75,7 +78,7 @@ pub struct Field {
|
||||
impl Field {
|
||||
fn default() -> Field {
|
||||
Self {
|
||||
possible_values: Vec::<u32>::new(),
|
||||
possible_values: Vec::new(),
|
||||
value: None,
|
||||
}
|
||||
}
|
||||
@@ -88,7 +91,7 @@ mod tests {
|
||||
impl Field {
|
||||
fn new(value: u32) -> Field {
|
||||
Self {
|
||||
possible_values: Vec::<u32>::new(),
|
||||
possible_values: Vec::new(),
|
||||
value: Some(value),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
struct SudokuSolver {
|
||||
playfield: Playfield
|
||||
}
|
||||
|
||||
impl SudokuSolver {
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user