Skip to content

Commit aca840d

Browse files
committed
Add unit tests for documented examples of rotate functions
1 parent 52e1e0e commit aca840d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Tests/SwiftAlgorithmsTests/RotateTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ import XCTest
1313
import Algorithms
1414

1515
final class RotateTests: XCTestCase {
16+
func testRotateSubrangeExample() {
17+
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
18+
let oldStart = numbers.rotate(subrange: 0..<4, toStartAt: 2)
19+
XCTAssertEqual(numbers, [30, 40, 10, 20, 50, 60, 70, 80])
20+
XCTAssertEqual(numbers[oldStart], 10)
21+
}
22+
23+
func testRotateExample() {
24+
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
25+
let oldStart = numbers.rotate(toStartAt: 3)
26+
XCTAssertEqual(numbers, [40, 50, 60, 70, 80, 10, 20, 30])
27+
XCTAssertEqual(numbers[oldStart], 10)
28+
}
29+
1630
func testRotate() {
1731
for length in 0...15 {
1832
let a = Array(0..<length)

0 commit comments

Comments
 (0)