Skip to content

Commit aef97dc

Browse files
authored
Fix typo incrementing instead of decrementing (#60)
1 parent 561b27b commit aef97dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/common/src/most_seen.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<T: Hash + Eq + Clone> MostSeen<T> {
124124

125125
// Item is in the map; not the best anyway. decrement count.
126126
if let Some(count) = self.others.get_mut(item) {
127-
*count += 1;
127+
*count = count.saturating_sub(1);
128128
}
129129
ChangeResult::NoChange
130130
}
@@ -248,5 +248,11 @@ mod test {
248248
assert!(res.has_changed());
249249
assert_eq!(a.best_count(), 2);
250250
assert_eq!(*a.best(), "First"); // First is now ahead
251+
252+
a.remove(&"Third"); // 0, or 2 with bug #595
253+
a.remove(&"Third"); // 0, or 4 with bug #595
254+
a.insert(&"Third"); // 1, or 5 with bug #595
255+
assert_eq!(a.best_count(), 2);
256+
assert_eq!(*a.best(), "First"); // First is still ahead
251257
}
252258
}

0 commit comments

Comments
 (0)