move tests to klondike
This commit is contained in:
@@ -9,6 +9,11 @@ rand = { version = "0.10.1", default-features = false, features = ["std_rng"] }
|
||||
serde = { version = "1.0.228", default-features = false, optional = true }
|
||||
serde_derive = { version = "1.0.228", default-features = false, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
rmp-serde = "1.3.1"
|
||||
serde = { version = "1.0.228", default-features = false }
|
||||
serde_json = "1.0.149"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ pub type Rng = rand::rngs::StdRng;
|
||||
|
||||
use card_game::{Card, Game, Pile, Rank, Stack};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
// test readme
|
||||
#[doc = include_str!("../README.md")]
|
||||
#[cfg(doctest)]
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
use card_game::Session;
|
||||
use crate::Klondike;
|
||||
|
||||
#[test]
|
||||
fn test_is_winnable() {
|
||||
// is winnable
|
||||
let solution_result = Session::new_default(Klondike::with_seed(124)).solve();
|
||||
if let Ok(Some(solution)) = solution_result {
|
||||
let win_moves = solution.clean_solution();
|
||||
// for (i, ins) in win_moves.into_iter().enumerate() {
|
||||
// println!("{i} = {:?}", ins.instruction());
|
||||
// }
|
||||
println!("Game is winnable with {} moves", win_moves.len());
|
||||
} else {
|
||||
println!("Game is not winnable");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_json() {
|
||||
let mut session = Session::new_default(Klondike::with_seed(124));
|
||||
let solution_result = session.solve();
|
||||
if let Ok(Some(solution)) = solution_result {
|
||||
for snapshot in solution.clean_solution() {
|
||||
session.process_instruction(snapshot.instruction().clone());
|
||||
}
|
||||
}
|
||||
let serialized = serde_json::to_string(&session).unwrap();
|
||||
println!("serialized = {serialized}");
|
||||
let round_trip_session: Session<Klondike> = serde_json::from_str(&serialized).unwrap();
|
||||
let serialized2 = serde_json::to_string(&round_trip_session).unwrap();
|
||||
assert_eq!(serialized, serialized2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rmp() {
|
||||
let mut session = Session::new_default(Klondike::with_seed(124));
|
||||
let solution_result = session.solve();
|
||||
if let Ok(Some(solution)) = solution_result {
|
||||
for snapshot in solution.clean_solution() {
|
||||
session.process_instruction(snapshot.instruction().clone());
|
||||
}
|
||||
}
|
||||
let serialized = rmp_serde::to_vec(&session).unwrap();
|
||||
println!("serialized.len() = {}", serialized.len());
|
||||
let round_trip_session: Session<Klondike> = rmp_serde::from_slice(&serialized).unwrap();
|
||||
let serialized2 = rmp_serde::to_vec(&round_trip_session).unwrap();
|
||||
assert_eq!(serialized, serialized2);
|
||||
}
|
||||
Reference in New Issue
Block a user