Skip to content

Commit a0ff640

Browse files
committed
add storage specific intersectInPlace() tests
1 parent 101d698 commit a0ff640

File tree

1 file changed

+87
-9
lines changed

1 file changed

+87
-9
lines changed

validation-test/stdlib/Set.swift

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3164,31 +3164,109 @@ SetTestSuite.test("∩") {
31643164
expectEqual(Set<Int>(), Set<Int>() s1)
31653165
}
31663166

3167-
SetTestSuite.test("intersectInPlace") {
3168-
var s1 = Set([1010, 2020, 3030])
3169-
let s2 = Set([4040, 5050, 6060])
3170-
var s3 = Set([1010, 2020, 3030, 4040, 5050, 6060])
3171-
var s4 = Set([1010, 2020, 3030])
3167+
SetTestSuite.test("intersectInPlace.Native.Native") {
3168+
var s1 = getCOWFastSet([1010, 2020, 3030])
3169+
let s2 = getCOWFastSet([4040, 5050, 6060])
3170+
var s3 = getCOWFastSet([1010, 2020, 3030, 4040, 5050, 6060])
3171+
var s4 = getCOWFastSet([1010, 2020, 3030])
31723172

31733173
let identity1 = unsafeBitCast(s1, Int.self)
31743174
s1.intersectInPlace(s4)
31753175
expectEqual(s1, s4)
31763176
expectEqual(identity1, unsafeBitCast(s1, Int.self))
31773177

31783178
s4.intersectInPlace(s2)
3179-
expectEqual(Set<Int>(), s4)
3179+
expectEqual(getCOWFastSet([]), s4)
31803180

31813181
let identity2 = unsafeBitCast(s3, Int.self)
31823182
s3.intersectInPlace(s2)
31833183
expectEqual(s3, s2)
31843184
expectTrue(s1.isDisjointWith(s3))
31853185
expectNotEqual(identity1, unsafeBitCast(s3, Int.self))
31863186

3187-
var s5 = Set<Int>()
3187+
var s5 = getCOWFastSet([])
31883188
s5.intersectInPlace(s5)
3189-
expectEqual(s5, Set<Int>())
3189+
expectEqual(s5, getCOWFastSet([]))
31903190
s5.intersectInPlace(s1)
3191-
expectEqual(s5, Set<Int>())
3191+
expectEqual(s5, getCOWFastSet([]))
3192+
}
3193+
3194+
SetTestSuite.test("intersectInPlace.Native.BridgedVerbatim") {
3195+
var s1 = getNativeBridgedVerbatimSet([1010, 2020, 3030])
3196+
var s3 = getNativeBridgedVerbatimSet([1010, 2020, 3030, 4040, 5050, 6060])
3197+
var s4 = getNativeBridgedVerbatimSet([1010, 2020, 3030])
3198+
3199+
let bvs2 = getBridgedVerbatimSet([4040, 5050, 6060])
3200+
var bvs4 = getBridgedVerbatimSet([1010, 2020, 3030])
3201+
3202+
let identity1 = unsafeBitCast(s1, Int.self)
3203+
s1.intersectInPlace(bvs4)
3204+
expectEqual(s1, bvs4)
3205+
expectEqual(identity1, unsafeBitCast(s1, Int.self))
3206+
3207+
s4.intersectInPlace(bvs2)
3208+
expectEqual(Set<Int>(), s4)
3209+
3210+
let identity2 = unsafeBitCast(s3, Int.self)
3211+
s3.intersectInPlace(bvs2)
3212+
expectEqual(s3, bvs2)
3213+
expectTrue(s1.isDisjointWith(s3))
3214+
expectNotEqual(identity1, unsafeBitCast(s3, Int.self))
3215+
}
3216+
3217+
3218+
SetTestSuite.test("intersectInPlace.BridgedVerbatim.BridgedVerbatim") {
3219+
var bvs1 = getBridgedVerbatimSet([1010, 2020, 3030])
3220+
let bvs2 = getBridgedVerbatimSet([4040, 5050, 6060])
3221+
var bvs3 = getBridgedVerbatimSet([1010, 2020, 3030, 4040, 5050, 6060])
3222+
var bvs4 = getBridgedVerbatimSet([1010, 2020, 3030])
3223+
3224+
let identity1 = unsafeBitCast(bvs1, Int.self)
3225+
bvs1.intersectInPlace(bvs4)
3226+
expectEqual(bvs1, bvs4)
3227+
expectEqual(identity1, unsafeBitCast(bvs1, Int.self))
3228+
3229+
bvs4.intersectInPlace(bvs2)
3230+
expectEqual(getBridgedVerbatimSet([]), bvs4)
3231+
3232+
let identity2 = unsafeBitCast(bvs3, Int.self)
3233+
bvs3.intersectInPlace(bvs2)
3234+
expectEqual(bvs3, bvs2)
3235+
expectTrue(bvs1.isDisjointWith(bvs3))
3236+
expectNotEqual(identity1, unsafeBitCast(bvs3, Int.self))
3237+
3238+
var bvs5 = getBridgedVerbatimSet([])
3239+
bvs5.intersectInPlace(bvs5)
3240+
expectEqual(bvs5, getBridgedVerbatimSet([]))
3241+
bvs5.intersectInPlace(bvs1)
3242+
expectEqual(bvs5, getBridgedVerbatimSet([]))
3243+
}
3244+
3245+
SetTestSuite.test("intersectInPlace.BridgedNonverbatim.BridgedNonverbatim") {
3246+
var bnvs1 = getBridgedNonverbatimSet([1010, 2020, 3030])
3247+
let bnvs2 = getBridgedNonverbatimSet([4040, 5050, 6060])
3248+
var bnvs3 = getBridgedNonverbatimSet([1010, 2020, 3030, 4040, 5050, 6060])
3249+
var bnvs4 = getBridgedNonverbatimSet([1010, 2020, 3030])
3250+
3251+
let identity1 = unsafeBitCast(bnvs1, Int.self)
3252+
bnvs1.intersectInPlace(bnvs4)
3253+
expectEqual(bnvs1, bnvs4)
3254+
expectEqual(identity1, unsafeBitCast(bnvs1, Int.self))
3255+
3256+
bnvs4.intersectInPlace(bnvs2)
3257+
expectEqual(getBridgedNonverbatimSet([]), bnvs4)
3258+
3259+
let identity2 = unsafeBitCast(bnvs3, Int.self)
3260+
bnvs3.intersectInPlace(bnvs2)
3261+
expectEqual(bnvs3, bnvs2)
3262+
expectTrue(bnvs1.isDisjointWith(bnvs3))
3263+
expectNotEqual(identity1, unsafeBitCast(bnvs3, Int.self))
3264+
3265+
var bnvs5 = getBridgedNonverbatimSet([])
3266+
bnvs5.intersectInPlace(bnvs5)
3267+
expectEqual(bnvs5, getBridgedNonverbatimSet([]))
3268+
bnvs5.intersectInPlace(bnvs1)
3269+
expectEqual(bnvs5, getBridgedNonverbatimSet([]))
31923270
}
31933271

31943272
SetTestSuite.test("∩=") {

0 commit comments

Comments
 (0)