@@ -13,6 +13,49 @@ import XCTest
13
13
import Algorithms
14
14
15
15
final class RotateTests : XCTestCase {
16
+ /// Tests `rotate(subrange:toStartAt:)` with an empty subrange
17
+ /// The order of elements are unchanged
18
+ func testRotateEmptySubrange( ) {
19
+ var numbers = [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ]
20
+ let oldStart = numbers. rotate ( subrange: 3 ..< 3 , toStartAt: 3 )
21
+ XCTAssertEqual ( numbers, [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ] )
22
+ XCTAssertEqual ( numbers [ oldStart] , 40 )
23
+ }
24
+
25
+ /// Tests `rotate(subrange:toStartAt:)` with an empty collection
26
+ func testRotateSubrangeOnEmptyCollection( ) {
27
+ var numbers = [ Int] ( )
28
+ let oldStart = numbers. rotate ( subrange: 0 ..< 0 , toStartAt: 0 )
29
+ XCTAssertEqual ( numbers, [ ] )
30
+ XCTAssertEqual ( oldStart, numbers. startIndex)
31
+ }
32
+
33
+ /// Tests `rotate(subrange:toStartAt:)` with the full range of the collection
34
+ func testRotateFullRange( ) {
35
+ var numbers = [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ]
36
+ let oldStart = numbers. rotate ( subrange: 0 ..< 8 , toStartAt: 1 )
37
+ XCTAssertEqual ( numbers, [ 20 , 30 , 40 , 50 , 60 , 70 , 80 , 10 ] )
38
+ XCTAssertEqual ( numbers [ oldStart] , 10 )
39
+ }
40
+
41
+ /// Tests the example given in `rotate(subrange:toStartAt:)`’s documentation
42
+ func testRotateSubrange( ) {
43
+ var numbers = [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ]
44
+ let oldStart = numbers. rotate ( subrange: 0 ..< 4 , toStartAt: 2 )
45
+ XCTAssertEqual ( numbers, [ 30 , 40 , 10 , 20 , 50 , 60 , 70 , 80 ] )
46
+ XCTAssertEqual ( numbers [ oldStart] , 10 )
47
+ }
48
+
49
+ /// Tests the example given in `rotate(toStartAt:)`’s documentation
50
+ func testRotateExample( ) {
51
+ var numbers = [ 10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 ]
52
+ let oldStart = numbers. rotate ( toStartAt: 3 )
53
+ XCTAssertEqual ( numbers, [ 40 , 50 , 60 , 70 , 80 , 10 , 20 , 30 ] )
54
+ XCTAssertEqual ( numbers [ oldStart] , 10 )
55
+ }
56
+
57
+ /// Tests `rotate(toStartAt:)` on collections of varying lengths, at different
58
+ /// starting points
16
59
func testRotate( ) {
17
60
for length in 0 ... 15 {
18
61
let a = Array ( 0 ..< length)
0 commit comments