Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension _BTree {
@inlinable
@inline(__always)
public mutating func removeLast(_ k: Int) {
assert(0 <= k && k < self.count, "Can't remove more items from a collection than it contains")
assert(0 <= k && k <= self.count, "Can't remove more items from a collection than it contains")
for _ in 0..<k {
self.removeLast()
}
Expand Down Expand Up @@ -95,7 +95,7 @@ extension _BTree {
@inlinable
@inline(__always)
public mutating func removeFirst(_ k: Int) {
assert(0 <= k && k < self.count, "Can't remove more items from a collection than it contains")
assert(0 <= k && k <= self.count, "Can't remove more items from a collection than it contains")
for _ in 0..<k {
self.removeFirst()
}
Expand Down
24 changes: 24 additions & 0 deletions Tests/SortedCollectionsTests/BTree/BTree+Deletion Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,29 @@ final class NodeDeletionTests: CollectionTestCase {
}
}
}

func test_removeAllWithRemoveFirst() {
withEvery("size", in: [1, 2, 4, 8, 16, 32, 64, 128, 512]) { size in
btreeOfSize(size) { tree, _ in
expectEqual(tree.count, size)

tree.removeFirst(size)

expectEqual(tree.count, 0)
}
}
}

func test_removeAllWithRemoveLast() {
withEvery("size", in: [1, 2, 4, 8, 16, 32, 64, 128, 512]) { size in
btreeOfSize(size) { tree, _ in
expectEqual(tree.count, size)

tree.removeLast(size)

expectEqual(tree.count, 0)
}
}
}
}
#endif