Test: convert index

This commit is contained in:
Jonas Zeunert
2024-02-20 00:54:36 +01:00
parent 2e6d9bb96c
commit b762a2da92
2 changed files with 26 additions and 1 deletions

View File

@@ -55,6 +55,10 @@ impl Playfield {
pub fn get_column(&self, index: usize) -> Vec<Field> {
self.fields.iter().map(|row| row[index].clone()).collect()
}
pub fn get_field(&self, row: usize, col: usize) -> &Field {
&self.fields[row][col]
}
pub fn convert_index(&self, index: usize) -> (usize, usize) {}
}
impl fmt::Display for Playfield {
@@ -117,6 +121,25 @@ mod tests {
assert_eq!(column_3, expected_3);
}
}
mod convert_index {
use super::*;
#[test]
fn simple() {
let playfield = Playfield::new(&"1 2 3 0 0 0 0 0 0".to_string(), 3);
let (row_1, col_1) = playfield.convert_index(0);
assert_eq!(row_1, 0);
assert_eq!(col_1, 0);
let (row_2, col_2) = playfield.convert_index(4);
assert_eq!(row_2, 1);
assert_eq!(col_2, 1);
let (row_2, col_2) = playfield.convert_index(9);
assert_eq!(row_2, 2);
assert_eq!(col_2, 2);
}
}
mod parse {
use super::super::*;

View File

@@ -13,7 +13,9 @@ impl SudokuSolver {
playfield: playfield.clone(),
}
}
pub fn solve(&self) -> Playfield {
pub fn solve(&mut self) -> Playfield {
self.populate_possible_values();
return self.playfield.clone();
}