@@ -15,78 +15,78 @@ import XCTest
15
15
final class ChainTests : XCTestCase {
16
16
// intentionally does not depend on `Chain.index(_:offsetBy:)` in order to
17
17
// avoid making assumptions about the code being tested
18
- func index< A, B> ( atOffset offset: Int , in chain: Chain < A , B > ) -> Chain < A , B > . Index {
18
+ func index< A, B> ( atOffset offset: Int , in chain: Chain2 < A , B > ) -> Chain2 < A , B > . Index {
19
19
offset < chain. base1. count
20
20
? . init( first: chain. base1. index ( chain. base1. startIndex, offsetBy: offset) )
21
21
: . init( second: chain. base2. index ( chain. base2. startIndex, offsetBy: offset - chain. base1. count) )
22
22
}
23
23
24
24
func testChainSequences( ) {
25
- let run = ( 1 ... ) . prefix ( 10 ) . chained ( with : 20 ... )
25
+ let run = chain ( ( 1 ... ) . prefix ( 10 ) , 20 ... )
26
26
XCTAssertEqualSequences ( run. prefix ( 20 ) , Array ( 1 ... 10 ) + ( 20 ..< 30 ) )
27
27
}
28
28
29
29
func testChainForwardCollection( ) {
30
30
let s1 = Set ( 0 ... 10 )
31
31
let s2 = Set ( 20 ... 30 )
32
- let c = s1 . chained ( with : s2)
32
+ let c = chain ( s1 , s2)
33
33
XCTAssertEqualSequences ( c, Array ( s1) + Array( s2) )
34
34
}
35
35
36
36
func testChainBidirectionalCollection( ) {
37
37
let s1 = " ABCDEFGHIJ "
38
38
let s2 = " klmnopqrstuv "
39
- let c = s1 . chained ( with : s2)
39
+ let c = chain ( s1 , s2)
40
40
41
41
XCTAssertEqualSequences ( c, " ABCDEFGHIJklmnopqrstuv " )
42
42
XCTAssertEqualSequences ( c. reversed ( ) , " ABCDEFGHIJklmnopqrstuv " . reversed ( ) )
43
- XCTAssertEqualSequences ( s1. reversed ( ) . chained ( with : s2) , " JIHGFEDCBAklmnopqrstuv " )
43
+ XCTAssertEqualSequences ( chain ( s1. reversed ( ) , s2) , " JIHGFEDCBAklmnopqrstuv " )
44
44
}
45
45
46
46
func testChainIndexOffsetBy( ) {
47
47
let s1 = " abcde "
48
48
let s2 = " VWXYZ "
49
- let chain = s1 . chained ( with : s2)
49
+ let c = chain ( s1 , s2)
50
50
51
- for (startOffset, endOffset) in product ( 0 ... chain . count, 0 ... chain . count) {
52
- let start = index ( atOffset: startOffset, in: chain )
53
- let end = index ( atOffset: endOffset, in: chain )
51
+ for (startOffset, endOffset) in product ( 0 ... c . count, 0 ... c . count) {
52
+ let start = index ( atOffset: startOffset, in: c )
53
+ let end = index ( atOffset: endOffset, in: c )
54
54
let distance = endOffset - startOffset
55
- XCTAssertEqual ( chain . index ( start, offsetBy: distance) , end)
55
+ XCTAssertEqual ( c . index ( start, offsetBy: distance) , end)
56
56
}
57
57
}
58
58
59
59
func testChainIndexOffsetByLimitedBy( ) {
60
60
let s1 = " abcd "
61
61
let s2 = " XYZ "
62
- let chain = s1 . chained ( with : s2)
62
+ let c = chain ( s1 , s2)
63
63
64
- for (startOffset, limitOffset) in product ( 0 ... chain . count, 0 ... chain . count) {
65
- let start = index ( atOffset: startOffset, in: chain )
66
- let limit = index ( atOffset: limitOffset, in: chain )
64
+ for (startOffset, limitOffset) in product ( 0 ... c . count, 0 ... c . count) {
65
+ let start = index ( atOffset: startOffset, in: c )
66
+ let limit = index ( atOffset: limitOffset, in: c )
67
67
68
68
// verifies that the target index corresponding to each offset in `range`
69
69
// can or cannot be reached from `start` using
70
- // `chain .index(start, offsetBy: _, limitedBy: limit)`, depending on the
70
+ // `c .index(start, offsetBy: _, limitedBy: limit)`, depending on the
71
71
// value of `beyondLimit`
72
72
func checkTargetRange( _ range: ClosedRange < Int > , beyondLimit: Bool ) {
73
73
for targetOffset in range {
74
74
let distance = targetOffset - startOffset
75
75
76
76
XCTAssertEqual (
77
- chain . index ( start, offsetBy: distance, limitedBy: limit) ,
78
- beyondLimit ? nil : index ( atOffset: targetOffset, in: chain ) )
77
+ c . index ( start, offsetBy: distance, limitedBy: limit) ,
78
+ beyondLimit ? nil : index ( atOffset: targetOffset, in: c ) )
79
79
}
80
80
}
81
81
82
82
// forward
83
83
if limit >= start {
84
84
// the limit has an effect
85
85
checkTargetRange ( startOffset... limitOffset, beyondLimit: false )
86
- checkTargetRange ( ( limitOffset + 1 ) ... ( chain . count + 1 ) , beyondLimit: true )
86
+ checkTargetRange ( ( limitOffset + 1 ) ... ( c . count + 1 ) , beyondLimit: true )
87
87
} else {
88
88
// the limit has no effect
89
- checkTargetRange ( startOffset... chain . count, beyondLimit: false )
89
+ checkTargetRange ( startOffset... c . count, beyondLimit: false )
90
90
}
91
91
92
92
// backward
@@ -102,42 +102,38 @@ final class ChainTests: XCTestCase {
102
102
}
103
103
104
104
func testChainIndexOffsetAcrossBoundary( ) {
105
- let chain = " abc " . chained ( with : " XYZ " )
105
+ let c = chain ( " abc " , " XYZ " )
106
106
107
107
do {
108
- let i = chain . index ( chain . startIndex, offsetBy: 3 , limitedBy: chain . startIndex)
108
+ let i = c . index ( c . startIndex, offsetBy: 3 , limitedBy: c . startIndex)
109
109
XCTAssertNil ( i)
110
110
}
111
111
112
112
do {
113
- let i = chain . index ( chain . startIndex, offsetBy: 4 )
114
- let j = chain . index ( i, offsetBy: - 2 )
115
- XCTAssertEqual ( chain [ j] , " c " )
113
+ let i = c . index ( c . startIndex, offsetBy: 4 )
114
+ let j = c . index ( i, offsetBy: - 2 )
115
+ XCTAssertEqual ( c [ j] , " c " )
116
116
}
117
117
118
118
do {
119
- let i = chain . index ( chain . startIndex, offsetBy: 3 )
120
- let j = chain . index ( i, offsetBy: - 1 , limitedBy: i)
119
+ let i = c . index ( c . startIndex, offsetBy: 3 )
120
+ let j = c . index ( i, offsetBy: - 1 , limitedBy: i)
121
121
XCTAssertNil ( j)
122
122
}
123
123
}
124
124
125
125
func testChainDistanceFromTo( ) {
126
126
let s1 = " abcde "
127
127
let s2 = " VWXYZ "
128
- let chain = s1 . chained ( with : s2)
128
+ let c = chain ( s1 , s2)
129
129
130
- XCTAssertEqual ( chain . count, s1. count + s2. count)
130
+ XCTAssertEqual ( c . count, s1. count + s2. count)
131
131
132
- for (startOffset, endOffset) in product ( 0 ... chain . count, 0 ... chain . count) {
133
- let start = index ( atOffset: startOffset, in: chain )
134
- let end = index ( atOffset: endOffset, in: chain )
132
+ for (startOffset, endOffset) in product ( 0 ... c . count, 0 ... c . count) {
133
+ let start = index ( atOffset: startOffset, in: c )
134
+ let end = index ( atOffset: endOffset, in: c )
135
135
let distance = endOffset - startOffset
136
- XCTAssertEqual ( chain . distance ( from: start, to: end) , distance)
136
+ XCTAssertEqual ( c . distance ( from: start, to: end) , distance)
137
137
}
138
138
}
139
-
140
- func testChainLazy( ) {
141
- XCTAssertLazy ( [ 1 , 2 , 3 ] . lazy. chained ( with: [ 4 , 5 , 6 ] ) )
142
- }
143
139
}
0 commit comments