File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Tests/FoundationEssentialsTests Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,14 @@ extension Data {
4646 }
4747}
4848
49+ func createSomeData( _ length: Int ) -> Data {
50+ var d = Data ( repeating: 42 , count: length)
51+ // Set a byte to be another value just so we know we have a unique pointer to the backing
52+ // For maximum inefficiency in the not equal case, set the last byte
53+ d [ length - 1 ] = UInt8 . random ( in: UInt8 . min..< UInt8 . max)
54+ return d
55+ }
56+
4957@Suite ( " Data " )
5058private final class DataTests {
5159
@@ -197,6 +205,16 @@ private final class DataTests {
197205 #expect( d1 == d2, " Data should be equal " )
198206 }
199207
208+ @Test func identical( ) {
209+ let d1 = createSomeData ( 1024 * 8 )
210+ let d2 = createSomeData ( 1024 * 8 )
211+
212+ #expect( d1. isIdentical ( to: d1) , " Data should be identical " )
213+ #expect( d2. isIdentical ( to: d2) , " Data should be identical " )
214+ #expect( !( d1. isIdentical ( to: d2) ) , " Data should be identical " )
215+ #expect( !( d2. isIdentical ( to: d1) ) , " Data should be identical " )
216+ }
217+
200218 @Test func dataInSet( ) {
201219 let d1 = dataFrom ( " Hello " )
202220 let d2 = dataFrom ( " Hello " )
You can’t perform that action at this time.
0 commit comments