mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
[PersistentSet] Test & fix symmetricDifference
This commit is contained in:
1 parent
d6b1e6c767
commit
876177dbb5
2 files changed
+16
-1
No files matched your search
+3
-1
@@ -27,6 +27,8 @@ extension PersistentSet {
|
||||
@inlinable
|
||||
public func symmetricDifference(_ other: __owned Self) -> Self {
|
||||
// FIXME: Do this with a structural merge.
|
||||
self.subtracting(self.intersection(other))
|
||||
let a = self.subtracting(other)
|
||||
let b = other.subtracting(self)
|
||||
return a.union(b)
|
||||
}
|
||||
}
|
||||
@@ -337,4 +337,17 @@ class PersistentSetTests: CollectionTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func test_symmetricDifference_exhaustive() {
|
||||
withEverySubset("a", of: testItems) { a in
|
||||
let x = PersistentSet(a)
|
||||
let u = Set(a)
|
||||
expectEqualSets(x.symmetricDifference(x), [])
|
||||
withEverySubset("b", of: testItems) { b in
|
||||
let y = PersistentSet(b)
|
||||
let v = Set(b)
|
||||
expectEqualSets(x.symmetricDifference(y), u.symmetricDifference(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user