make test
This commit is contained in:
@@ -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
@@ -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}");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user