fix tinylfu test flake

The TinyLFU test was failing for changes unrelated to anything in the tinyufo
crate. This changes the test to stop that! What was occurring was expected
behavior, so the test is what's changing instead of any internal logic.

What was happening were hash collisions in the bloom filter used by the
estimator. Instead of asserting that we'd always start counting from 0, we now
allow for this in the test by `get()`ing first, then comparing relative
values. For the final comparisons, we check that values are greater-than or
equal-to their lower bound as determined by the number of `incr()`s we called on
their keys.
This commit is contained in:
Matthew Gumport 2024-04-10 13:49:10 -07:00 committed by Yuchen Wu
parent 99cb79bf2b
commit 01c69659c8
2 changed files with 18 additions and 13 deletions

2
.bleep
View file

@ -1 +1 @@
802590d7d04730c3e93f9c2335175990eee1fb92
d87a50338cb6483a3b0cbfe73d3b0491a336b7a2

View file

@ -183,20 +183,25 @@ mod tests {
assert_eq!(tiny.incr(1), 2);
assert_eq!(tiny.get(1), 2);
assert_eq!(tiny.get(2), 0);
assert_eq!(tiny.incr(2), 1);
assert_eq!(tiny.incr(2), 2);
assert_eq!(tiny.get(2), 2);
// Might have hash collisions for the others, need to
// get() before can assert on the incr() value.
let two = tiny.get(2);
assert_eq!(tiny.incr(2), two + 1);
assert_eq!(tiny.incr(2), two + 2);
assert_eq!(tiny.get(2), two + 2);
assert_eq!(tiny.incr(3), 1);
assert_eq!(tiny.incr(3), 2);
assert_eq!(tiny.incr(3), 3);
assert_eq!(tiny.incr(3), 4);
let three = tiny.get(3);
assert_eq!(tiny.incr(3), three + 1);
assert_eq!(tiny.incr(3), three + 2);
assert_eq!(tiny.incr(3), three + 3);
assert_eq!(tiny.incr(3), three + 4);
// 8 incr(), now reset
// 8 incr(), now resets on next incr
// can only assert they are greater than or equal
// to the incr() we do per key.
assert_eq!(tiny.incr(3), 3);
assert_eq!(tiny.incr(1), 2);
assert_eq!(tiny.incr(2), 2);
assert!(tiny.incr(3) >= 3); // had 4, reset to 2, added another.
assert!(tiny.incr(1) >= 2); // had 2, reset to 1, added another.
assert!(tiny.incr(2) >= 2); // had 2, reset to 1, added another.
}
}