From b4c478db02bab1758c0778d259880110eabbff72 Mon Sep 17 00:00:00 2001 From: Antony David Date: Mon, 1 May 2023 22:59:24 +0200 Subject: [PATCH] add: unit test --- src/main.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6b27fc5..973ee0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,3 +103,29 @@ async fn main() -> std::io::Result<()> { .run() .await } + +#[cfg(test)] +mod tests { + use crate::{sudoku::generate, sudoku::resolv_backtrack}; + + #[test] + fn board_valid() { + const BOARD_SIZE: usize = 9; + let board = generate(BOARD_SIZE, 1); + assert_eq!(board.len(), 9); + + let mut hm = std::collections::HashMap::new(); + for i in 0..BOARD_SIZE { + for j in 0..BOARD_SIZE { + if hm.contains_key(&board[i][j]) { + assert!(false); + } + if board[i][j] != 0 { + hm.insert(board[i][j], true); + } + } + hm.clear(); + } + assert_eq!(resolv_backtrack(&mut board.clone(), 0, 0), true); + } +}