generated from PlexSheep/rs-base
test(game): test the evaluation
cargo devel CI / cargo CI (push) Failing after 1m50s
Details
cargo devel CI / cargo CI (push) Failing after 1m50s
Details
This commit is contained in:
parent
567d02d48b
commit
05197181d0
|
@ -0,0 +1,57 @@
|
||||||
|
use wordle_analyzer::error::GameError;
|
||||||
|
use wordle_analyzer::game::evaluation::Evaluation;
|
||||||
|
use wordle_analyzer::game::response::GuessResponse;
|
||||||
|
use wordle_analyzer::wlist::builtin::BuiltinWList;
|
||||||
|
use wordle_analyzer::wlist::WordList;
|
||||||
|
|
||||||
|
use wordle_analyzer::wlist::word::Word;
|
||||||
|
use wordle_analyzer::{self, game};
|
||||||
|
|
||||||
|
fn wordlist() -> impl WordList {
|
||||||
|
BuiltinWList::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_eval_simple() -> anyhow::Result<()> {
|
||||||
|
let wl = wordlist();
|
||||||
|
let builder = game::Game::builder(&wl)
|
||||||
|
.length(5)
|
||||||
|
.max_steps(6)
|
||||||
|
.solution(Some(wl.get_word(&Word::from("crate")).unwrap()))
|
||||||
|
.precompute(false);
|
||||||
|
|
||||||
|
let mut game = builder.build()?;
|
||||||
|
let guess = Word::from("slate");
|
||||||
|
game.guess(&guess, None)?;
|
||||||
|
assert_eq!(
|
||||||
|
*game.last_response().unwrap().evaluation(),
|
||||||
|
Evaluation::build(&guess, "xxccc")?
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_eval_reoccuring_char() -> anyhow::Result<()> {
|
||||||
|
let wl = wordlist();
|
||||||
|
let builder = game::Game::builder(&wl)
|
||||||
|
.solution(Some(wl.get_word(&Word::from("nines")).unwrap()))
|
||||||
|
.precompute(false);
|
||||||
|
|
||||||
|
let mut game = builder.build()?;
|
||||||
|
let guess = Word::from("pines");
|
||||||
|
game.guess(&guess, None)?;
|
||||||
|
assert_eq!(
|
||||||
|
*game.last_response().unwrap().evaluation(),
|
||||||
|
Evaluation::build(&guess, "xcccc")?
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut game = builder.build()?;
|
||||||
|
let guess = Word::from("sides");
|
||||||
|
game.guess(&guess, None)?;
|
||||||
|
assert_eq!(
|
||||||
|
*game.last_response().unwrap().evaluation(),
|
||||||
|
Evaluation::build(&guess, "xcxcc")?
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -36,22 +36,17 @@ fn test_naive_play_predetermined_game() -> anyhow::Result<()> {
|
||||||
sl.make_a_move(&mut game)?;
|
sl.make_a_move(&mut game)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
game.responses().last().unwrap().guess(),
|
game.responses().last().unwrap().guess(),
|
||||||
&Word::from("their")
|
&Word::from("first")
|
||||||
);
|
);
|
||||||
sl.make_a_move(&mut game)?;
|
sl.make_a_move(&mut game)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
game.responses().last().unwrap().guess(),
|
game.responses().last().unwrap().guess(),
|
||||||
&Word::from("being")
|
&Word::from("lives")
|
||||||
);
|
);
|
||||||
sl.make_a_move(&mut game)?;
|
sl.make_a_move(&mut game)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
game.responses().last().unwrap().guess(),
|
game.responses().last().unwrap().guess(),
|
||||||
&Word::from("since")
|
&Word::from("sides")
|
||||||
);
|
|
||||||
sl.make_a_move(&mut game)?;
|
|
||||||
assert_eq!(
|
|
||||||
game.responses().last().unwrap().guess(),
|
|
||||||
&Word::from("lines")
|
|
||||||
);
|
);
|
||||||
sl.make_a_move(&mut game)?;
|
sl.make_a_move(&mut game)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -61,12 +56,16 @@ fn test_naive_play_predetermined_game() -> anyhow::Result<()> {
|
||||||
sl.make_a_move(&mut game)?;
|
sl.make_a_move(&mut game)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
game.responses().last().unwrap().guess(),
|
game.responses().last().unwrap().guess(),
|
||||||
&Word::from("wines")
|
&Word::from("pines")
|
||||||
|
);
|
||||||
|
sl.make_a_move(&mut game)?;
|
||||||
|
assert_eq!(
|
||||||
|
game.responses().last().unwrap().guess(),
|
||||||
|
&Word::from("nines")
|
||||||
);
|
);
|
||||||
|
|
||||||
// naive is at the moment too bad to solve "nines"
|
|
||||||
assert!(game.finished());
|
assert!(game.finished());
|
||||||
assert!(!game.won());
|
assert!(game.won());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -85,55 +84,54 @@ fn test_naive_play_predetermined_game_manually() -> anyhow::Result<()> {
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("which"));
|
assert_eq!(next_guess, Word::from("which"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xxfxx")?),
|
Some(Evaluation::build(&next_guess, "xxfxx")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("their"));
|
assert_eq!(next_guess, Word::from("first"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xxffx")?),
|
Some(Evaluation::build(&next_guess, "xcxfx")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("being"));
|
assert_eq!(next_guess, Word::from("lives"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xfffx")?),
|
Some(Evaluation::build(&next_guess, "xcxcc")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("since"));
|
assert_eq!(next_guess, Word::from("sides"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "fcfxf")?),
|
Some(Evaluation::build(&next_guess, "xcxcc")?),
|
||||||
)?;
|
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
|
||||||
assert_eq!(next_guess, Word::from("lines"));
|
|
||||||
game.guess(
|
|
||||||
next_guess.clone(),
|
|
||||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("mines"));
|
assert_eq!(next_guess, Word::from("mines"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
next_guess = sl.guess_for(&game)?;
|
next_guess = sl.guess_for(&game)?;
|
||||||
assert_eq!(next_guess, Word::from("wines"));
|
assert_eq!(next_guess, Word::from("pines"));
|
||||||
game.guess(
|
game.guess(
|
||||||
next_guess.clone(),
|
&next_guess.clone(),
|
||||||
Some(Evaluation::build(&next_guess, "xcccc")?),
|
Some(Evaluation::build(&next_guess, "xcccc")?),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// naive is at the moment too bad to solve "nines"
|
next_guess = sl.guess_for(&game)?;
|
||||||
|
assert_eq!(next_guess, Word::from("nines"));
|
||||||
|
game.guess(
|
||||||
|
&next_guess.clone(),
|
||||||
|
Some(Evaluation::build(&next_guess, "ccccc")?),
|
||||||
|
)?;
|
||||||
|
|
||||||
assert!(game.finished());
|
assert!(game.finished());
|
||||||
assert!(!game.won());
|
assert!(game.won());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue