Skip to content

Commit 13970de

Browse files
committed
data identical tests
1 parent bee9e58 commit 13970de

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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")
5058
private 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")

0 commit comments

Comments
 (0)