Skip to content

Commit adebb7b

Browse files
committed
Add a test for inserting an empty collection in the middle
1 parent f22e597 commit adebb7b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Tests/SwiftAlgorithmsTests/ReplaceSubrangeTests.swift

+17-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,23 @@ final class ReplaceSubrangeTests: XCTestCase {
9494

9595
func testInsert() {
9696

97-
let base = 0..<10
98-
let i = base.index(base.startIndex, offsetBy: 5)
99-
let result = base.lazy.replacingSubrange(i..<i, with: 20..<25)
100-
XCTAssertEqualCollections(result, [0, 1, 2, 3, 4, 20, 21, 22, 23, 24, 5, 6, 7, 8, 9])
101-
IndexValidator().validate(result, expectedCount: 15)
97+
// Inserting: non-empty
98+
do {
99+
let base = 0..<10
100+
let i = base.index(base.startIndex, offsetBy: 5)
101+
let result = base.lazy.replacingSubrange(i..<i, with: 20..<25)
102+
XCTAssertEqualCollections(result, [0, 1, 2, 3, 4, 20, 21, 22, 23, 24, 5, 6, 7, 8, 9])
103+
IndexValidator().validate(result, expectedCount: 15)
104+
}
105+
106+
// Inserting: empty
107+
do {
108+
let base = 0..<10
109+
let i = base.index(base.startIndex, offsetBy: 5)
110+
let result = base.lazy.replacingSubrange(i..<i, with: EmptyCollection())
111+
XCTAssertEqualCollections(result, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
112+
IndexValidator().validate(result, expectedCount: 10)
113+
}
102114
}
103115

104116
func testReplace() {

0 commit comments

Comments
 (0)