File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
1
2
using System . Linq ;
2
3
using DataStructures . Bag ;
3
4
using FluentAssertions ;
@@ -122,4 +123,31 @@ public void Count_ShouldReturnCorrectCount()
122
123
// Act & Assert
123
124
bag . Count . Should ( ) . Be ( 3 ) ;
124
125
}
126
+
127
+ [ Test ]
128
+ public void IEnumerableGetEnumerator_YieldsAllItemsWithCorrectMultiplicity ( )
129
+ {
130
+ // Arrange
131
+ var bag = new Bag < string >
132
+ {
133
+ "apple" ,
134
+ "banana" ,
135
+ "apple"
136
+ } ;
137
+ var genericBag = bag as System . Collections . IEnumerable ;
138
+
139
+ // Act
140
+ var enumerator = genericBag . GetEnumerator ( ) ;
141
+ var items = new List < object > ( ) ;
142
+ while ( enumerator . MoveNext ( ) )
143
+ {
144
+ items . Add ( enumerator . Current ! ) ;
145
+ }
146
+
147
+ // Assert
148
+ items . Count ( i => ( string ) i == "apple" ) . Should ( ) . Be ( 2 ) ;
149
+ items . Count ( i => ( string ) i == "banana" ) . Should ( ) . Be ( 1 ) ;
150
+ items . Count . Should ( ) . Be ( 3 ) ;
151
+ items . Should ( ) . BeEquivalentTo ( [ "apple" , "apple" , "banana" ] ) ;
152
+ }
125
153
}
Original file line number Diff line number Diff line change @@ -102,8 +102,5 @@ public IEnumerator<T> GetEnumerator()
102
102
/// <summary>
103
103
/// Returns an enumerator that iterates through the bag.
104
104
/// </summary>
105
- IEnumerator IEnumerable . GetEnumerator ( )
106
- {
107
- return GetEnumerator ( ) ;
108
- }
105
+ IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
109
106
}
You can’t perform that action at this time.
0 commit comments