Skip to content

Commit 1a1d4d5

Browse files
committed
Work around test failure on Windows
1 parent e009325 commit 1a1d4d5

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

rslib/src/scheduler/fsrs/memory_state.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ mod tests {
318318
use crate::scheduler::fsrs::weights::tests::convert;
319319
use crate::scheduler::fsrs::weights::tests::revlog;
320320

321+
/// Floating point precision can vary between platforms, and each FSRS
322+
/// update tends to result in small changes to these numbers, so we
323+
/// round them.
324+
fn assert_int_eq(actual: Option<FsrsMemoryState>, expected: Option<FsrsMemoryState>) {
325+
let actual = actual.unwrap();
326+
let expected = expected.unwrap();
327+
assert_eq!(actual.stability.round(), expected.stability.round());
328+
assert_eq!(actual.difficulty.round(), expected.difficulty.round());
329+
}
330+
321331
#[test]
322332
fn bypassed_learning_is_handled() -> Result<()> {
323333
// cards without any learning steps due to truncated history still have memory
@@ -337,24 +347,24 @@ mod tests {
337347
0.9,
338348
)?
339349
.unwrap();
340-
assert_eq!(
341-
item.starting_state,
342-
Some(MemoryState {
350+
assert_int_eq(
351+
item.starting_state.map(Into::into),
352+
Some(FsrsMemoryState {
343353
stability: 99.999954,
344-
difficulty: 5.8158145
345-
})
354+
difficulty: 5.8158145,
355+
}),
346356
);
347357
let mut card = Card {
348358
reps: 1,
349359
..Default::default()
350360
};
351361
card.set_memory_state(&fsrs, Some(item), 0.9)?;
352-
assert_eq!(
362+
assert_int_eq(
353363
card.memory_state,
354364
Some(FsrsMemoryState {
355365
stability: 248.65057,
356-
difficulty: 5.782729
357-
})
366+
difficulty: 5.782729,
367+
}),
358368
);
359369
// but if there's only a single revlog entry, we'll fall back on current card
360370
// state
@@ -373,12 +383,12 @@ mod tests {
373383
card.ease_factor = 2000;
374384
card.ctype = CardType::Review;
375385
card.set_memory_state(&fsrs, item, 0.9)?;
376-
assert_eq!(
386+
assert_int_eq(
377387
card.memory_state,
378388
Some(FsrsMemoryState {
379389
stability: 122.99994,
380-
difficulty: 7.4459267
381-
})
390+
difficulty: 7.4459267,
391+
}),
382392
);
383393
Ok(())
384394
}
@@ -396,15 +406,15 @@ mod tests {
396406
..Default::default()
397407
};
398408
card.set_memory_state(&FSRS::new(Some(&[])).unwrap(), None, 0.9)?;
399-
assert_eq!(
409+
assert_int_eq(
400410
card.memory_state,
401411
Some(
402412
MemoryState {
403413
stability: 99.999954,
404-
difficulty: 9.963163
414+
difficulty: 9.963163,
405415
}
406-
.into()
407-
)
416+
.into(),
417+
),
408418
);
409419
Ok(())
410420
}

0 commit comments

Comments
 (0)