diff --git a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift b/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift index 8641627a..56e9966f 100644 --- a/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift +++ b/Sources/PersistentCollections/PersistentSet/PersistentSet+SetAlgebra symmetricDifference.swift @@ -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) } } diff --git a/Tests/PersistentCollectionsTests/PersistentSet Tests.swift b/Tests/PersistentCollectionsTests/PersistentSet Tests.swift index 1d90a922..bbc131ff 100644 --- a/Tests/PersistentCollectionsTests/PersistentSet Tests.swift +++ b/Tests/PersistentCollectionsTests/PersistentSet Tests.swift @@ -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)) + } + } + } }