Skip to content

Commit bf1de32

Browse files
committed
Add unit tests for reverse functions
1 parent dd564ca commit bf1de32

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Tests/SwiftAlgorithmsTests/RotateTests.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
import XCTest
13-
import Algorithms
13+
@testable import Algorithms
1414

1515
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+
1634
/// Tests `rotate(subrange:toStartAt:)` with an empty subrange
1735
/// The order of elements are unchanged
1836
func testRotateEmptySubrange() {

0 commit comments

Comments
 (0)