Skip to content

Commit

Permalink
Add a test for inserting an empty collection in the middle
Browse files Browse the repository at this point in the history
  • Loading branch information
karwa committed Sep 9, 2023
1 parent f22e597 commit adebb7b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Tests/SwiftAlgorithmsTests/ReplaceSubrangeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,23 @@ final class ReplaceSubrangeTests: XCTestCase {

func testInsert() {

let base = 0..<10
let i = base.index(base.startIndex, offsetBy: 5)
let result = base.lazy.replacingSubrange(i..<i, with: 20..<25)
XCTAssertEqualCollections(result, [0, 1, 2, 3, 4, 20, 21, 22, 23, 24, 5, 6, 7, 8, 9])
IndexValidator().validate(result, expectedCount: 15)
// Inserting: non-empty
do {
let base = 0..<10
let i = base.index(base.startIndex, offsetBy: 5)
let result = base.lazy.replacingSubrange(i..<i, with: 20..<25)
XCTAssertEqualCollections(result, [0, 1, 2, 3, 4, 20, 21, 22, 23, 24, 5, 6, 7, 8, 9])
IndexValidator().validate(result, expectedCount: 15)
}

// Inserting: empty
do {
let base = 0..<10
let i = base.index(base.startIndex, offsetBy: 5)
let result = base.lazy.replacingSubrange(i..<i, with: EmptyCollection())
XCTAssertEqualCollections(result, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
IndexValidator().validate(result, expectedCount: 10)
}
}

func testReplace() {
Expand Down

0 comments on commit adebb7b

Please sign in to comment.