Skip to content

Commit

Permalink
add: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayllyz committed May 1, 2023
1 parent 82eef74 commit b4c478d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit b4c478d

Please sign in to comment.