@@ -454,6 +454,23 @@ public void Test_NegativeHashKey_ReturnsCorrectValue()
454
454
Assert . That ( hashTable [ new NegativeHashKey ( 1 ) ] , Is . EqualTo ( 1 ) ) ;
455
455
}
456
456
457
+ [ Test ]
458
+ public void Resize_HandlesNegativeHashCodeCorrectly ( )
459
+ {
460
+ // Arrange
461
+ var hashTable = new HashTable < NegativeHashKey , string > ( 2 ) ;
462
+
463
+ // Act
464
+ hashTable . Add ( new NegativeHashKey ( 1 ) , "A" ) ;
465
+ hashTable . Add ( new NegativeHashKey ( 2 ) , "B" ) ;
466
+ hashTable . Add ( new NegativeHashKey ( 3 ) , "C" ) ;
467
+
468
+ // Assert
469
+ Assert . That ( hashTable [ new NegativeHashKey ( 1 ) ] , Is . EqualTo ( "A" ) ) ;
470
+ Assert . That ( hashTable [ new NegativeHashKey ( 2 ) ] , Is . EqualTo ( "B" ) ) ;
471
+ Assert . That ( hashTable [ new NegativeHashKey ( 3 ) ] , Is . EqualTo ( "C" ) ) ;
472
+ }
473
+
457
474
[ Test ]
458
475
public void Add_ShouldTriggerResize_WhenThresholdExceeded ( )
459
476
{
@@ -462,14 +479,14 @@ public void Add_ShouldTriggerResize_WhenThresholdExceeded()
462
479
var hashTable = new HashTable < int , string > ( initialCapacity ) ;
463
480
464
481
// Act
465
- for ( var i = 1 ; i <= 4 ; i ++ ) // Start keys from 1 to avoid default(TKey) = 0 issue
482
+ for ( var i = 1 ; i <= 32 ; i ++ )
466
483
{
467
484
hashTable . Add ( i , $ "Value{ i } ") ;
468
485
}
469
486
470
487
// Assert
471
- hashTable . Capacity . Should ( ) . BeGreaterThan ( initialCapacity ) ; // Ensure resizing occurred
472
- hashTable . Count . Should ( ) . Be ( 4 ) ; // Verify count reflects number of added items
488
+ hashTable . Capacity . Should ( ) . BeGreaterThan ( initialCapacity ) ;
489
+ hashTable . Count . Should ( ) . Be ( 32 ) ;
473
490
}
474
491
475
492
0 commit comments