Skip to content

Commit e0d9dc8

Browse files
Include unit tests for entry()
1 parent 3f996a3 commit e0d9dc8

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

crates/udd-sketch/src/lib.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ mod tests {
674674
}
675675
}
676676

677+
use crate::SketchHashKey::Invalid;
677678
use quickcheck::*;
678679

679680
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)]
@@ -685,6 +686,63 @@ mod tests {
685686
}
686687
}
687688

689+
#[test]
690+
fn test_entry_insertion_order() {
691+
let mut map = SketchHashMap {
692+
map: HashMap::new(),
693+
head: Invalid,
694+
};
695+
696+
map.entry(SketchHashKey::Negative(i64::MIN)).count += 5;
697+
map.entry(SketchHashKey::Negative(10)).count += 1;
698+
map.entry(SketchHashKey::Positive(i64::MAX - 100)).count += 17;
699+
map.entry(SketchHashKey::Zero).count += 7;
700+
map.entry(SketchHashKey::Positive(-10)).count += 11;
701+
map.entry(SketchHashKey::Negative(-10)).count += 3;
702+
map.entry(SketchHashKey::Positive(10)).count += 13;
703+
704+
let keys: Vec<_> = map.iter().collect::<Vec<_>>();
705+
assert_eq!(
706+
keys,
707+
vec![
708+
(SketchHashKey::Negative(10), 1),
709+
(SketchHashKey::Negative(-10), 3),
710+
(SketchHashKey::Negative(i64::MIN), 5),
711+
(SketchHashKey::Zero, 7),
712+
(SketchHashKey::Positive(-10), 11),
713+
(SketchHashKey::Positive(10), 13),
714+
(SketchHashKey::Positive(i64::MAX - 100), 17),
715+
]
716+
);
717+
718+
// We add some things before the current head, insert some new ones,
719+
// add some to the end, and again inbetween some others
720+
map.entry(SketchHashKey::Negative(i64::MAX)).count += 3;
721+
map.entry(SketchHashKey::Negative(-10)).count += 23;
722+
map.entry(SketchHashKey::Positive(10)).count += 123;
723+
map.entry(SketchHashKey::Positive(9)).count += 29;
724+
map.entry(SketchHashKey::Positive(11)).count += 31;
725+
map.entry(SketchHashKey::Positive(i64::MAX)).count += 8;
726+
727+
let keys: Vec<_> = map.iter().collect::<Vec<_>>();
728+
assert_eq!(
729+
keys,
730+
vec![
731+
(SketchHashKey::Negative(i64::MAX), 3),
732+
(SketchHashKey::Negative(10), 1),
733+
(SketchHashKey::Negative(-10), 26), // 3 + 23
734+
(SketchHashKey::Negative(i64::MIN), 5),
735+
(SketchHashKey::Zero, 7),
736+
(SketchHashKey::Positive(-10), 11),
737+
(SketchHashKey::Positive(9), 29),
738+
(SketchHashKey::Positive(10), 136), // 13 + 123
739+
(SketchHashKey::Positive(11), 31),
740+
(SketchHashKey::Positive(i64::MAX - 100), 17),
741+
(SketchHashKey::Positive(i64::MAX), 8),
742+
]
743+
);
744+
}
745+
688746
#[quickcheck]
689747
// Use multiple hashsets as input to allow a small number of duplicate values without getting ridiculous levels of duplication (as quickcheck is inclined to create)
690748
fn fuzzing_test(

0 commit comments

Comments
 (0)