55 [ TestFixture ]
66 public class UnsafeDictionaryTests
77 {
8+ [ Test ]
9+ public void TestEnumerator ( )
10+ {
11+ UnsafeDictionary < uint , int > dict = default ;
12+ dict [ 1 ] = 10 ;
13+ dict [ 2 ] = 20 ;
14+ dict [ 3 ] = 30 ;
15+
16+ IEnumerator < KeyValuePair < uint , int > > enumerator = dict . GetEnumerator ( ) ;
17+
18+ // Act
19+ var result = new List < KeyValuePair < uint , int > > ( ) ;
20+ while ( enumerator . MoveNext ( ) )
21+ {
22+ result . Add ( enumerator . Current ) ;
23+ }
24+
25+ // Assert
26+ var expected = new List < KeyValuePair < uint , int > >
27+ {
28+ new KeyValuePair < uint , int > ( 1 , 10 ) ,
29+ new KeyValuePair < uint , int > ( 2 , 20 ) ,
30+ new KeyValuePair < uint , int > ( 3 , 30 )
31+ } ;
32+
33+ Assert . That ( result , Is . EquivalentTo ( expected ) ) ;
34+
35+ dict . Release ( ) ;
36+ }
37+
38+ [ Test ]
39+ public void TestKeyValueEnumerator ( )
40+ {
41+ // Arrange
42+ UnsafeDictionary < uint , int > dict = new UnsafeDictionary < uint , int > ( ) ;
43+
44+ // Populate the dictionary with data
45+ dict [ 1 ] = 10 ;
46+ dict [ 2 ] = 20 ;
47+ dict [ 3 ] = 30 ;
48+
49+ // Act & Assert for Key Enumerator
50+ IEnumerator < uint > keyEnumerator = dict . Keys . GetEnumerator ( ) ;
51+ var keyResult = new List < uint > ( ) ;
52+ while ( keyEnumerator . MoveNext ( ) )
53+ {
54+ keyResult . Add ( keyEnumerator . Current ) ;
55+ }
56+
57+ var expectedKeys = new List < uint > { 1 , 2 , 3 } ;
58+ Assert . That ( keyResult , Is . EquivalentTo ( expectedKeys ) ) ;
59+
60+ // Act & Assert for Value Enumerator
61+ IEnumerator < int > valueEnumerator = dict . Values . GetEnumerator ( ) ;
62+ var valueResult = new List < int > ( ) ;
63+ while ( valueEnumerator . MoveNext ( ) )
64+ {
65+ valueResult . Add ( valueEnumerator . Current ) ;
66+ }
67+
68+ var expectedValues = new List < int > { 10 , 20 , 30 } ;
69+ Assert . That ( valueResult , Is . EquivalentTo ( expectedValues ) ) ;
70+
71+ // Clean up
72+ dict . Release ( ) ;
73+ }
74+
875 [ Test ]
976 public void TestInitialAdd ( )
1077 {
@@ -64,7 +131,7 @@ public void TestRemoveKey()
64131
65132 dict . Remove ( 1 ) ;
66133
67- Assert . IsFalse ( dict . ContainsKey ( 1 ) ) ;
134+ Assert . That ( dict . ContainsKey ( 1 ) , Is . False ) ;
68135 Assert . That ( dict [ 2 ] , Is . EqualTo ( 3 ) ) ;
69136
70137 foreach ( var item in dict )
@@ -83,7 +150,7 @@ public void TestRemoveNonExistentKey()
83150 Assert . DoesNotThrow ( ( ) => dict . Remove ( 2 ) ) ;
84151
85152 Assert . That ( dict [ 1 ] , Is . EqualTo ( 2 ) ) ;
86- Assert . IsFalse ( dict . ContainsKey ( 2 ) ) ;
153+ Assert . That ( dict . ContainsKey ( 2 ) , Is . False ) ;
87154
88155 foreach ( var item in dict )
89156 {
@@ -96,7 +163,7 @@ public void TestRemoveNonExistentKey()
96163 public void TestEmptyDictionary ( )
97164 {
98165 UnsafeDictionary < uint , int > dict = default ;
99- Assert . IsEmpty ( dict ) ;
166+ Assert . That ( dict , Is . Empty ) ;
100167
101168 foreach ( var item in dict )
102169 {
@@ -120,7 +187,7 @@ public void TestReleaseResources()
120187 dict [ 2 ] = 3 ;
121188
122189 // Since dictionary is reallocated, previous values should not exist
123- Assert . IsFalse ( dict . ContainsKey ( 1 ) ) ;
190+ Assert . That ( dict . ContainsKey ( 1 ) , Is . False ) ;
124191 Assert . That ( dict [ 2 ] , Is . EqualTo ( 3 ) ) ;
125192
126193 foreach ( var item in dict )
@@ -129,7 +196,7 @@ public void TestReleaseResources()
129196 }
130197
131198 // Verify that the dictionary's capacity and size have been updated correctly
132- Assert . Greater ( dict . Capacity , 0 ) ;
199+ Assert . That ( dict . Capacity , Is . EqualTo ( 3 ) ) ;
133200 Assert . That ( dict . Size , Is . EqualTo ( 1 ) ) ;
134201
135202 // Release the dictionary again
0 commit comments