7
7
using nanoFramework . TestFramework ;
8
8
using System ;
9
9
using System . Collections ;
10
+ using System . Diagnostics ;
10
11
11
12
namespace NFUnitTests
12
13
{
@@ -21,6 +22,15 @@ public void SetupTests()
21
22
{
22
23
// need this empty method to get everything setup in the class
23
24
// otherwise the 1st test will incur in that time penalty thus not proving an accurate execution time
25
+
26
+ Hashtable ht = new Hashtable ( ) ;
27
+
28
+ for ( ulong i = 1 ; i <= 100 ; i ++ )
29
+ {
30
+ SomeKey se = new SomeKey ( ) ;
31
+ Debug . WriteLine ( $ "Adding element no { i } ") ;
32
+ ht . Add ( se , i ) ;
33
+ }
24
34
}
25
35
26
36
[ TestMethod ]
@@ -677,6 +687,20 @@ public void Hashtable_InsertNullKey()
677
687
} , "No exception was thrown when adding a NULL key." ) ;
678
688
}
679
689
690
+ [ TestMethod ]
691
+ public void Hashtable_ClassAsKey ( )
692
+ {
693
+ Hashtable ht = CreateClassHashtable ( 10 ) ;
694
+
695
+ foreach ( var key in ht . Keys )
696
+ {
697
+ Assert . AreEqual ( $ "Value_{ key . GetHashCode ( ) } ", ht [ key ] as string ) ;
698
+ }
699
+
700
+
701
+
702
+ }
703
+
680
704
#region helper classes and methods
681
705
682
706
/// <summary>
@@ -783,6 +807,26 @@ public static Hashtable CreateStringHashtable(int count, int start = 0)
783
807
return hashtable ;
784
808
}
785
809
810
+ public static Hashtable CreateClassHashtable ( int count , int start = 0 )
811
+ {
812
+ var hashtable = new Hashtable ( ) ;
813
+
814
+ for ( int i = start ; i < start + count ; i ++ )
815
+ {
816
+ var key = new SomeKey ( ) ;
817
+ string value = "Value_" + key . GetHashCode ( ) ;
818
+
819
+ hashtable . Add ( key , value ) ;
820
+ }
821
+
822
+ return hashtable ;
823
+ }
824
+
825
+ public class SomeKey
826
+ {
827
+
828
+ }
829
+
786
830
private class Foo
787
831
{
788
832
public string StringValue { get ; set ; } = "Hello World" ;
0 commit comments