2024-07-25 14:46:20 +02:00
|
|
|
use test_log::test; // set the log level with an envvar: `RUST_LOG=trace cargo test`
|
|
|
|
|
2024-07-23 11:22:50 +02:00
|
|
|
use wordle_analyzer::game::Game;
|
|
|
|
use wordle_analyzer::solve::{AnyBuiltinSolver, NaiveSolver, Solver, StupidSolver};
|
|
|
|
use wordle_analyzer::wlist::builtin::BuiltinWList;
|
|
|
|
use wordle_analyzer::wlist::WordList;
|
|
|
|
|
2024-08-03 20:16:26 +02:00
|
|
|
use rayon::prelude::*;
|
|
|
|
|
2024-07-23 11:22:50 +02:00
|
|
|
fn wordlist() -> impl WordList {
|
|
|
|
BuiltinWList::default()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_build_builtin_solvers() {
|
|
|
|
let wl = wordlist();
|
2024-07-24 12:00:43 +02:00
|
|
|
let _stupid_solver =
|
2024-07-23 11:22:50 +02:00
|
|
|
AnyBuiltinSolver::Stupid(StupidSolver::build(&wl).expect("could not build naive solver"));
|
2024-07-24 12:00:43 +02:00
|
|
|
let _naive_solver =
|
2024-07-23 11:22:50 +02:00
|
|
|
AnyBuiltinSolver::Naive(NaiveSolver::build(&wl).expect("could not build naive solver"));
|
|
|
|
}
|
2024-08-07 15:01:11 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_naive_win_games() -> anyhow::Result<()> {
|
|
|
|
let wl = wordlist();
|
|
|
|
let sl =
|
|
|
|
AnyBuiltinSolver::Naive(NaiveSolver::build(&wl).expect("could not build naive solver"));
|
|
|
|
let builder = Game::builder(&wl);
|
|
|
|
|
|
|
|
{ 0..50 }.into_par_iter().for_each(|_round| {
|
|
|
|
let mut game = builder.build().expect("could not make game");
|
|
|
|
sl.play(&mut game).expect("could not play game");
|
|
|
|
assert!(game.finished());
|
|
|
|
assert!(game.won());
|
|
|
|
});
|
|
|
|
Ok(())
|
|
|
|
}
|