Skip to content

Commit 29cee65

Browse files
committed
Add unit tests for hashtable with classes as keys
1 parent 0c98d54 commit 29cee65

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Tests/HashtableTests/HashtableTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,24 @@ public void Hashtable_InsertNullKey()
677677
}, "No exception was thrown when adding a NULL key.");
678678
}
679679

680+
[TestMethod]
681+
public void Hashtable_ClassAsKey()
682+
{
683+
var hashtable = new Hashtable();
684+
685+
for (int i = 0; i < 100; i++)
686+
{
687+
SomeKey key = new SomeKey();
688+
689+
hashtable.Add(key, key.GetHashCode());
690+
}
691+
692+
foreach (var key in hashtable.Keys)
693+
{
694+
Assert.AreEqual(key.GetHashCode(), (int)hashtable[key]);
695+
}
696+
}
697+
680698
#region helper classes and methods
681699

682700
/// <summary>
@@ -783,6 +801,10 @@ public static Hashtable CreateStringHashtable(int count, int start = 0)
783801
return hashtable;
784802
}
785803

804+
public class SomeKey
805+
{
806+
}
807+
786808
private class Foo
787809
{
788810
public string StringValue { get; set; } = "Hello World";

0 commit comments

Comments
 (0)