[PersistentSet] Test & fix symmetricDifference

This commit is contained in:
Karoy Lorentey committed 2022-09-28 18:38:14 -07:00
1 parent d6b1e6c767
commit 876177dbb5
2 files changed
+16 -1

No files matched your search

@@ -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))
}
}
}
}