make test

This commit is contained in:
2026-05-15 08:38:47 -07:00
parent 2d0fb8f0c1
commit 30f2fec61b
2 changed files with 33 additions and 0 deletions
+3
View File
@@ -1,6 +1,9 @@
pub mod card_game; pub mod card_game;
pub mod klondike; pub mod klondike;
#[cfg(test)]
mod test;
pub type Rng = rand::rngs::ThreadRng; pub type Rng = rand::rngs::ThreadRng;
// test readme // test readme
+30
View File
@@ -0,0 +1,30 @@
#[test]
fn test_klondike() {
use crate::Rng;
use crate::card_game::{Game, Session};
use crate::klondike::Klondike;
// create game session
let seed = Rng::default();
let game = Klondike::new(seed.clone(), Default::default());
let mut session = Session::new(seed, game);
// is winnable
let is_winnable = session.is_winnable().is_some();
// play game
while let Some(instruction) = session.possible_instructions().next() {
session.process_instruction(instruction);
}
// did win
let is_win = session.is_win();
// print session history
for (i, instruction) in session.history().iter().enumerate() {
println!("move {i} = {instruction:?}");
}
println!("is_winnable = {is_winnable}");
println!("is_win = {is_win}");
}