Skip to content

Commit 35a8012

Browse files
Increase tolerance to make tests more stable
1 parent 64e4dce commit 35a8012

File tree

1 file changed

+16
-3
lines changed
  • minesweeper/src/minesweeper_logic

1 file changed

+16
-3
lines changed

minesweeper/src/minesweeper_logic/game.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ mod test {
160160
let absolute_tolerance = expected_value * tolerance;
161161
if expected_value >= 0.0 {
162162
assert!(expected_value - absolute_tolerance < value);
163-
assert!(expected_value + absolute_tolerance > value);
163+
assert!(
164+
expected_value + absolute_tolerance > value,
165+
"{:.1} + {:.1} == {:.1} > {:.1}",
166+
expected_value / 1_000_000.0,
167+
absolute_tolerance / 1_000_000.0,
168+
(expected_value + absolute_tolerance) / 1_000_000.0,
169+
value / 1_000_000.0
170+
);
164171
} else {
165172
assert!(expected_value - absolute_tolerance > value);
166173
assert!(expected_value + absolute_tolerance < value);
@@ -290,17 +297,23 @@ mod test {
290297
assert_eq!(OpenResult::WINNER, open_info.result);
291298

292299
let expected_first_checkpoint = Duration::from_millis(SLEEPING_MILLIS).as_nanos() as f64;
293-
check_close_to(expected_first_checkpoint, elapsed_first_checkpoint, 0.1);
300+
const HUGE_TOLERANCE_DUE_TO_TINY_SLEEP_TIME: f64 = 0.5;
301+
check_close_to(
302+
expected_first_checkpoint,
303+
elapsed_first_checkpoint,
304+
HUGE_TOLERANCE_DUE_TO_TINY_SLEEP_TIME,
305+
);
294306

295307
thread::sleep(Duration::from_millis(SLEEPING_MILLIS));
296308

297309
let expected_game_time = end_time - start_time;
298310
let actual_game_time = game.get_elapsed();
299311

312+
const BIG_TOLERANCE_DUE_TO_TINY_SLEEP_TIME: f64 = 0.3;
300313
check_close_to(
301314
expected_game_time.as_nanos() as f64,
302315
actual_game_time.as_nanos() as f64,
303-
0.1,
316+
BIG_TOLERANCE_DUE_TO_TINY_SLEEP_TIME,
304317
);
305318

306319
assert_eq!(actual_game_time, game.get_elapsed());

0 commit comments

Comments
 (0)