Work around test failure on Windows

This commit is contained in:
Damien Elmes 2023-12-28 18:43:28 +10:00
parent e009325745
commit 1a1d4d5419

View File

@ -318,6 +318,16 @@ mod tests {
use crate::scheduler::fsrs::weights::tests::convert; use crate::scheduler::fsrs::weights::tests::convert;
use crate::scheduler::fsrs::weights::tests::revlog; use crate::scheduler::fsrs::weights::tests::revlog;
/// Floating point precision can vary between platforms, and each FSRS
/// update tends to result in small changes to these numbers, so we
/// round them.
fn assert_int_eq(actual: Option<FsrsMemoryState>, expected: Option<FsrsMemoryState>) {
let actual = actual.unwrap();
let expected = expected.unwrap();
assert_eq!(actual.stability.round(), expected.stability.round());
assert_eq!(actual.difficulty.round(), expected.difficulty.round());
}
#[test] #[test]
fn bypassed_learning_is_handled() -> Result<()> { fn bypassed_learning_is_handled() -> Result<()> {
// cards without any learning steps due to truncated history still have memory // cards without any learning steps due to truncated history still have memory
@ -337,24 +347,24 @@ mod tests {
0.9, 0.9,
)? )?
.unwrap(); .unwrap();
assert_eq!( assert_int_eq(
item.starting_state, item.starting_state.map(Into::into),
Some(MemoryState { Some(FsrsMemoryState {
stability: 99.999954, stability: 99.999954,
difficulty: 5.8158145 difficulty: 5.8158145,
}) }),
); );
let mut card = Card { let mut card = Card {
reps: 1, reps: 1,
..Default::default() ..Default::default()
}; };
card.set_memory_state(&fsrs, Some(item), 0.9)?; card.set_memory_state(&fsrs, Some(item), 0.9)?;
assert_eq!( assert_int_eq(
card.memory_state, card.memory_state,
Some(FsrsMemoryState { Some(FsrsMemoryState {
stability: 248.65057, stability: 248.65057,
difficulty: 5.782729 difficulty: 5.782729,
}) }),
); );
// but if there's only a single revlog entry, we'll fall back on current card // but if there's only a single revlog entry, we'll fall back on current card
// state // state
@ -373,12 +383,12 @@ mod tests {
card.ease_factor = 2000; card.ease_factor = 2000;
card.ctype = CardType::Review; card.ctype = CardType::Review;
card.set_memory_state(&fsrs, item, 0.9)?; card.set_memory_state(&fsrs, item, 0.9)?;
assert_eq!( assert_int_eq(
card.memory_state, card.memory_state,
Some(FsrsMemoryState { Some(FsrsMemoryState {
stability: 122.99994, stability: 122.99994,
difficulty: 7.4459267 difficulty: 7.4459267,
}) }),
); );
Ok(()) Ok(())
} }
@ -396,15 +406,15 @@ mod tests {
..Default::default() ..Default::default()
}; };
card.set_memory_state(&FSRS::new(Some(&[])).unwrap(), None, 0.9)?; card.set_memory_state(&FSRS::new(Some(&[])).unwrap(), None, 0.9)?;
assert_eq!( assert_int_eq(
card.memory_state, card.memory_state,
Some( Some(
MemoryState { MemoryState {
stability: 99.999954, stability: 99.999954,
difficulty: 9.963163 difficulty: 9.963163,
} }
.into() .into(),
) ),
); );
Ok(()) Ok(())
} }