File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments