@@ -197,3 +197,29 @@ func moreIndexChecks(_ startingBitRange: EmbeddedIteratorDirection) async throws
197
197
}
198
198
#expect( manualIndices. elementsEqual ( collectionIndices) )
199
199
}
200
+
201
+ @Test ( " Element swapping " , arguments: EmbeddedIteratorDirection . allCases)
202
+ func elementSwap( _ startingBitRange: EmbeddedIteratorDirection ) async throws {
203
+ var collection = EmbeddedIntegerCollection < UInt32 , UInt8 > (
204
+ iteratingFrom: startingBitRange
205
+ )
206
+ let firstIndex = collection. startIndex
207
+ let secondIndex = collection. index ( after: firstIndex)
208
+ let thirdIndex = collection. index ( after: secondIndex)
209
+ let fourthIndex = collection. index ( after: thirdIndex)
210
+ assert ( collection. index ( after: fourthIndex) == collection. endIndex)
211
+ collection [ firstIndex] = 0x40
212
+ collection [ secondIndex] = 0x41
213
+ collection [ thirdIndex] = 0x42
214
+ collection [ fourthIndex] = 0x43
215
+
216
+ #expect( collection. elementsEqual ( [ 0x40 , 0x41 , 0x42 , 0x43 ] ) )
217
+ collection. swapAt ( secondIndex, secondIndex)
218
+ #expect( collection. elementsEqual ( [ 0x40 , 0x41 , 0x42 , 0x43 ] ) )
219
+ collection. swapAt ( firstIndex, thirdIndex)
220
+ #expect( collection. elementsEqual ( [ 0x42 , 0x41 , 0x40 , 0x43 ] ) )
221
+ collection. swapAt ( firstIndex, thirdIndex)
222
+ #expect( collection. elementsEqual ( [ 0x40 , 0x41 , 0x42 , 0x43 ] ) )
223
+ collection. swapAt ( fourthIndex, secondIndex)
224
+ #expect( collection. elementsEqual ( [ 0x40 , 0x43 , 0x42 , 0x41 ] ) )
225
+ }
0 commit comments