|
10 | 10 | //===----------------------------------------------------------------------===//
|
11 | 11 |
|
12 | 12 | import XCTest
|
13 |
| -import Algorithms |
| 13 | +@testable import Algorithms |
14 | 14 |
|
15 | 15 | final class RotateTests: XCTestCase {
|
| 16 | + /// Tests the example given in `_reverse(subrange:until:)`’s documentation |
| 17 | + func testUnderscoreReverse() { |
| 18 | + var input = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"] |
| 19 | + let limit: Int = 4 |
| 20 | + let (lower, upper) = input._reverse(subrange: input.startIndex..<input.endIndex, until: input.startIndex.advanced(by: limit)) |
| 21 | + let expected = ["p", "o", "n", "m", "e", "f", "g", "h", "i", "j", "k", "l", "d", "c", "b", "a"] |
| 22 | + XCTAssertEqual(input, expected) |
| 23 | + XCTAssertEqual(lower, input.startIndex.advanced(by: limit)) |
| 24 | + XCTAssertEqual(upper, input.endIndex.advanced(by: -limit)) |
| 25 | + } |
| 26 | + |
| 27 | + /// Tests the example given in `reverse(subrange:)`’s documentation |
| 28 | + func testReverse() { |
| 29 | + var numbers = [10, 20, 30, 40, 50, 60, 70, 80] |
| 30 | + numbers.reverse(subrange: 0..<4) |
| 31 | + XCTAssertEqual(numbers, [40, 30, 20, 10, 50, 60, 70, 80]) |
| 32 | + } |
| 33 | + |
16 | 34 | /// Tests `rotate(subrange:toStartAt:)` with an empty subrange
|
17 | 35 | /// The order of elements are unchanged
|
18 | 36 | func testRotateEmptySubrange() {
|
|
0 commit comments