From 7ec48d0d454499177b63bc5bd512a3a2d6baa839 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Tue, 19 Apr 2022 21:26:49 +0200 Subject: Refile for merging repos --- 2018-tower-defence/tests/monte_carlo_test.rs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 2018-tower-defence/tests/monte_carlo_test.rs (limited to '2018-tower-defence/tests/monte_carlo_test.rs') diff --git a/2018-tower-defence/tests/monte_carlo_test.rs b/2018-tower-defence/tests/monte_carlo_test.rs new file mode 100644 index 0000000..cec3256 --- /dev/null +++ b/2018-tower-defence/tests/monte_carlo_test.rs @@ -0,0 +1,34 @@ +extern crate zombot; +extern crate time; +use time::{PreciseTime, Duration}; + +use zombot::*; + +const STATE_PATH: &str = "tests/state0.json"; + +// there are assertions in the game engine, run when it's in debug mode +#[test] +fn it_does_a_normal_turn_successfully() { + let start_time = PreciseTime::now(); + let state = match input::json::read_bitwise_state_from_file(STATE_PATH) { + Ok(ok) => ok, + Err(error) => panic!("Error while parsing JSON file: {}", error) + }; + let max_time = Duration::milliseconds(200); + strategy::monte_carlo::choose_move(&state, start_time, max_time); + + assert!(start_time.to(PreciseTime::now()) < max_time + Duration::milliseconds(50)) +} + +#[test] +fn it_does_a_normal_tree_serach_turn_successfully() { + let start_time = PreciseTime::now(); + let state = match input::json::read_bitwise_state_from_file(STATE_PATH) { + Ok(ok) => ok, + Err(error) => panic!("Error while parsing JSON file: {}", error) + }; + let max_time = Duration::milliseconds(200); + strategy::monte_carlo_tree::choose_move(&state, start_time, max_time); + + assert!(start_time.to(PreciseTime::now()) < max_time + Duration::milliseconds(50)) +} -- cgit v1.2.3