mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
[Capsule] Add special case iterator test
This commit is contained in:
1 parent
3803970073
commit
b489a6e786
1 file changed
+31
-3
@@ -135,13 +135,16 @@ final class CapsuleSmokeTests: CollectionTestCase {
|
||||
var map3: HashMap<CollidableInt, String> = map2
|
||||
for index in 0..<upperBound {
|
||||
map3[CollidableInt(index)] = nil
|
||||
|
||||
expectEqual(map3.cachedSize, inferSize(map3))
|
||||
if map3.cachedSize != inferSize(map3) {
|
||||
assertionFailure()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print("Populated `map3`")
|
||||
|
||||
// Assertion currently fails, likely due to a concurrency issue when updating
|
||||
// the `cachedSize` when deleting. The map content itself is correct, but the
|
||||
// size doesn't reflect it.
|
||||
expectEqual(map3.count, 0)
|
||||
}
|
||||
|
||||
@@ -343,6 +346,31 @@ final class CapsuleSmokeTests: CollectionTestCase {
|
||||
|
||||
expectEqual(res1, res3)
|
||||
}
|
||||
|
||||
func inferSize<Key, Value>(_ map: HashMap<Key, Value>) -> Int {
|
||||
var size = 0
|
||||
|
||||
for _ in map {
|
||||
size += 1
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
func testIteratorEnumeratesAll() {
|
||||
let map1: HashMap<CollidableInt, String> = [
|
||||
CollidableInt(11, 1) : "a",
|
||||
CollidableInt(12, 1) : "a",
|
||||
CollidableInt(32769) : "b"
|
||||
]
|
||||
|
||||
var map2: HashMap<CollidableInt, String> = [:]
|
||||
for (key, value) in map1 {
|
||||
map2[key] = value
|
||||
}
|
||||
|
||||
expectEqual(map1, map2)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate final class CollidableInt : CustomStringConvertible, Equatable, Hashable {
|
||||
|
||||
Reference in new issue
Block a user