diff options
Diffstat (limited to 'tinyufo/src/lib.rs')
-rw-r--r-- | tinyufo/src/lib.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/tinyufo/src/lib.rs b/tinyufo/src/lib.rs index 248f729..805373e 100644 --- a/tinyufo/src/lib.rs +++ b/tinyufo/src/lib.rs @@ -686,14 +686,22 @@ mod tests { assert_eq!(cache.peek_queue(2), Some(SMALL)); assert_eq!(cache.peek_queue(3), Some(SMALL)); - let evicted = cache.put(4, 4, 1); + let evicted = cache.put(4, 4, 2); assert_eq!(evicted.len(), 1); - assert_eq!(evicted[0].data, 2); + assert_eq!(evicted[0].weight, 2); assert_eq!(cache.peek_queue(1), Some(MAIN)); - // 2 is evicted because 1 is in main - assert_eq!(cache.peek_queue(2), None); - assert_eq!(cache.peek_queue(3), Some(SMALL)); - assert_eq!(cache.peek_queue(4), Some(SMALL)); + // either 2, 3, or 4 was evicted. Check evicted for which. + let mut remaining = vec![2, 3, 4]; + remaining.remove( + remaining + .iter() + .position(|x| *x == evicted[0].data) + .unwrap(), + ); + assert_eq!(cache.peek_queue(evicted[0].key), None); + for k in remaining { + assert_eq!(cache.peek_queue(k), Some(SMALL)); + } } } |