2024-07-25 14:46:20 +02:00
|
|
|
use test_log::test; // set the log level with an envvar: `RUST_LOG=trace cargo test`
|
|
|
|
|
|
|
|
use wordle_analyzer::game::evaluation::Evaluation;
|
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;
|
2024-07-24 11:54:02 +02:00
|
|
|
use wordle_analyzer::wlist::word::{Word, WordData};
|
2024-07-23 11:22:50 +02:00
|
|
|
use wordle_analyzer::wlist::WordList;
|
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_naive_play_predetermined_game() -> anyhow::Result<()> {
|
|
|
|
let wl = wordlist();
|
|
|
|
let sl =
|
|
|
|
AnyBuiltinSolver::Naive(NaiveSolver::build(&wl).expect("could not build naive solver"));
|
|
|
|
let mut game = Game::build(5, false, 6, &wl, false)?;
|
|
|
|
game.set_solution(Some(("nines".into(), 0.002))); // The accuracy is made up but shouldn't
|
|
|
|
// matter
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("which")
|
|
|
|
);
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("their")
|
|
|
|
);
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("being")
|
|
|
|
);
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("since")
|
|
|
|
);
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("lines")
|
|
|
|
);
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("mines")
|
|
|
|
);
|
|
|
|
sl.make_a_move(&mut game)?;
|
|
|
|
assert_eq!(
|
|
|
|
game.responses().last().unwrap().guess(),
|
|
|
|
&Word::from("wines")
|
|
|
|
);
|
|
|
|
|
|
|
|
// naive is at the moment too bad to solve "nines"
|
|
|
|
assert!(game.finished());
|
|
|
|
assert!(!game.won());
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
#[test]
|
2024-07-25 14:46:20 +02:00
|
|
|
fn test_naive_play_predetermined_game_manually() -> anyhow::Result<()> {
|
2024-07-24 11:54:02 +02:00
|
|
|
let wl = wordlist();
|
|
|
|
let sl =
|
|
|
|
AnyBuiltinSolver::Naive(NaiveSolver::build(&wl).expect("could not build naive solver"));
|
|
|
|
// we don't insert the solution yet,
|
|
|
|
// pretend that a user inputs guesses manually
|
|
|
|
let mut game = Game::build(5, false, 6, &wl, false)?;
|
|
|
|
let _actual_solution: Option<WordData> = Some(("nines".into(), 0.002));
|
2024-07-25 14:46:20 +02:00
|
|
|
let mut next_guess: Word;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("which"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "xxfxx")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("their"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "xxffx")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("being"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "xfffx")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("since"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "fcfxf")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("lines"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("mines"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
next_guess = sl.guess_for(&game)?;
|
|
|
|
assert_eq!(next_guess, Word::from("wines"));
|
2024-07-25 14:46:20 +02:00
|
|
|
game.guess(
|
2024-08-07 14:44:56 +02:00
|
|
|
&next_guess.clone(),
|
2024-07-25 14:46:20 +02:00
|
|
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
|
|
|
)?;
|
2024-07-24 11:54:02 +02:00
|
|
|
|
|
|
|
// naive is at the moment too bad to solve "nines"
|
|
|
|
assert!(game.finished());
|
|
|
|
assert!(!game.won());
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|