File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
DataStructures.Tests/Hashing Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,23 @@ public void Remove_TriggersResizeDown()
192
192
Assert . That ( hashTable . Capacity , Is . EqualTo ( 40 ) ) ;
193
193
}
194
194
195
+ [ Test ]
196
+ public void Remove_TriggersResizeDown_MinimumOfDefaultCapacity ( )
197
+ {
198
+ var hashTable = new HashTable < int , string > ( 4 ) ;
199
+ for ( var i = 1 ; i <= 50 ; i ++ )
200
+ {
201
+ hashTable . Add ( i , $ "Value{ i } ") ;
202
+ }
203
+
204
+ for ( var i = 1 ; i <= 48 ; i ++ )
205
+ {
206
+ hashTable . Remove ( i ) ;
207
+ }
208
+
209
+ Assert . That ( hashTable . Capacity , Is . EqualTo ( 16 ) ) ;
210
+ }
211
+
195
212
[ Test ]
196
213
public void ContainsValue_ReturnsFalse_WhenValueDoesNotExist ( )
197
214
{
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ public void Clear()
286
286
public void Resize ( )
287
287
{
288
288
var newCapacity = size <= threshold / 2
289
- ? Math . Min ( capacity / 2 , DefaultCapacity )
289
+ ? Math . Max ( capacity / 2 , DefaultCapacity )
290
290
: capacity * 2 ;
291
291
var newEntries = new Entry < TKey , TValue > [ newCapacity ] ;
292
292
You can’t perform that action at this time.
0 commit comments