Skip to content

Commit f7ae2c5

Browse files
committed
Range tweaks & tests
1 parent 487de0a commit f7ae2c5

File tree

6 files changed

+380
-51
lines changed

6 files changed

+380
-51
lines changed

Source/Integer_Extensions.swift

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,59 +54,95 @@ public extension Int32 {
5454
// Range Operators
5555

5656
public func ... (a: Int32, b: Int32) -> Range/*<Int32>*/ {
57-
return Range/*<Int32>*/(a, b, closed: true)
57+
if b < a {
58+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: true, reversed: true)
59+
} else {
60+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: true, reversed: false)
61+
}
5862
}
5963

6064
public func ... (a: Int64, b: Int32) -> Range/*<Int64>*/ {
61-
return Range/*<Int64>*/(a, b, closed: true)
65+
if b < a {
66+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: true, reversed: true)
67+
} else {
68+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: true, reversed: false)
69+
}
6270
}
6371

6472
public func ... (a: Int32, b: Int64) -> Range/*<Int64>*/ {
65-
return Range/*<Int64>*/(a, b, closed: true)
73+
if b < a {
74+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: true, reversed: true)
75+
} else {
76+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: true, reversed: false)
77+
}
6678
}
6779

6880
public func ..< (a: Int32, b: Int32) -> Range/*<Int32>*/ {
69-
return Range/*<Int64>*//*<Int32>*/(a, b, closed: false)
81+
if b < a {
82+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: false, reversed: true)
83+
} else {
84+
return Range/*<Int64>*/(a, b, upperBoundClosed: false, lowerBoundClosed: true)
85+
}
7086
}
7187

7288
public func ..< (a: Int64, b: Int32) -> Range/*<Int64>*/ {
73-
return Range/*<Int64>*/(a, b, closed: false)
89+
if b < a {
90+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: false, reversed: true)
91+
} else {
92+
return Range/*<Int64>*/(a, b, upperBoundClosed: false, lowerBoundClosed: true)
93+
}
7494
}
7595

7696
public func ..< (a: Int32, b: Int64) -> Range/*<Int64>*/ {
77-
return Range/*<Int64>*/(a, b, closed: false)
97+
if b < a {
98+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: false, reversed: true)
99+
} else {
100+
return Range/*<Int64>*/(a, b, upperBoundClosed: false, lowerBoundClosed: true)
101+
}
78102
}
79103

80104
public func >.. (a: Int32, b: Int32) -> Range/*<Int32>*/ {
81-
return Range/*<Int64>*//*<Int32>*/(b, a, closed: false, reversed: true)
105+
if b < a {
106+
return Range/*<Int64>*/(b, a, upperBoundClosed: false, lowerBoundClosed: true, reversed: true)
107+
} else {
108+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: false, reversed: false)
109+
}
82110
}
83111

84112
public func >.. (a: Int64, b: Int32) -> Range/*<Int64>*/ {
85-
return Range/*<Int64>*/(b, a, closed: false, reversed: true)
113+
if b < a {
114+
return Range/*<Int64>*/(b, a, upperBoundClosed: false, lowerBoundClosed: true, reversed: true)
115+
} else {
116+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: false, reversed: false)
117+
}
86118
}
87119

88120
public func >.. (a: Int32, b: Int64) -> Range/*<Int64>*/ {
89-
return Range/*<Int64>*/(b, a, closed: false, reversed: true)
121+
if b < a {
122+
return Range/*<Int64>*/(b, a, upperBoundClosed: false, lowerBoundClosed: true, reversed: true)
123+
} else {
124+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: false, reversed: false)
125+
}
90126
}
91127

92128
public prefix func ... (b: Int32) -> Range/*<Int32>*/ {
93-
return Range/*<Int32>*/(nil, b, closed: true)
129+
return Range/*<Int32>*/(nil, b, upperBoundClosed: true, lowerBoundClosed: true)
94130
}
95131

96132
public prefix func ..< (b: Int32) -> Range/*<Int32>*/ {
97-
return Range/*<Int64>*//*<Int32>*/(nil, b, closed: false)
133+
return Range/*<Int64>*//*<Int32>*/(nil, b, upperBoundClosed: false, lowerBoundClosed: true)
98134
}
99135

100136
public postfix func >.. (b: Int32) -> Range/*<Int32>*/ {
101-
return Range/*<Int64>*//*<Int32>*/(b, nil, closed: false, reversed: true)
137+
return Range/*<Int64>*//*<Int32>*/(b, nil, upperBoundClosed: false, lowerBoundClosed: true, reversed: true)
102138
}
103139

104140
public postfix func ... (a: Int32) -> Range/*<Int64>*/ {
105-
return Range/*<Int64>*/(a, nil, closed: true)
141+
return Range/*<Int64>*/(a, nil, upperBoundClosed: true, lowerBoundClosed: true)
106142
}
107143

108144
//public postfix func ..< (a: Int32) -> Range/*<Int32>*/ {
109-
//return Range/*<Int64>*//*<Int32>*/(a, nil, closed: false)
145+
//return Range/*<Int64>*//*<Int32>*/(a, nil, upperBoundClosed: false)
110146
//}
111147
}
112148

@@ -160,35 +196,47 @@ public extension Int64 {//: Equatable, Comparable, ForwardIndexType {
160196
// Range Operators
161197

162198
public func ... (a: Int64, b: Int64) -> Range/*<Int64>*/ {
163-
return Range/*<Int64>*/(a, b, closed: true)
199+
if b < a {
200+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: true, reversed: true)
201+
} else {
202+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: true, reversed: false)
203+
}
164204
}
165205

166206
public func ..< (a: Int64, b: Int64) -> Range/*<Int64>*/ {
167-
return Range/*<Int64>*/(a, b, closed: false)
207+
if b < a {
208+
return Range/*<Int64>*/(b, a, upperBoundClosed: true, lowerBoundClosed: false, reversed: true)
209+
} else {
210+
return Range/*<Int64>*/(a, b, upperBoundClosed: false, lowerBoundClosed: true)
211+
}
168212
}
169213

170214
public func >.. (a: Int64, b: Int64) -> Range/*<Int64>*/ {
171-
return Range/*<Int64>*/(b, a, closed: false, reversed: true)
215+
if b < a {
216+
return Range/*<Int64>*/(b, a, upperBoundClosed: false, lowerBoundClosed: true, reversed: true)
217+
} else {
218+
return Range/*<Int64>*/(a, b, upperBoundClosed: true, lowerBoundClosed: false, reversed: false)
219+
}
172220
}
173221

174222
public prefix func ... (b: Int64) -> Range/*<Int64>*/ {
175-
return Range/*<Int64>*/(nil, b, closed: true)
223+
return Range/*<Int64>*/(nil, b, upperBoundClosed: true, lowerBoundClosed: true)
176224
}
177225

178226
public prefix func ..< (b: Int64) -> Range/*<Int64>*/ {
179-
return Range/*<Int64>*/(nil, b, closed: false)
227+
return Range/*<Int64>*/(nil, b, upperBoundClosed: false, lowerBoundClosed: true)
180228
}
181229

182230
public postfix func >.. (b: Int64) -> Range/*<Int64>*/ {
183-
return Range/*<Int64>*/(b, nil, closed: false, reversed: true)
231+
return Range/*<Int64>*/(nil, b, upperBoundClosed: false, lowerBoundClosed: true, reversed: true)
184232
}
185233

186234
public postfix func ... (a: Int64) -> Range/*<Int64>*/ {
187-
return Range/*<Int64>*/(a, nil, closed: true)
235+
return Range/*<Int64>*/(a, nil, upperBoundClosed: true, lowerBoundClosed: true)
188236
}
189237

190238
//public postfix func ..< (a: Int64) -> Range/*<Int64>*/ {
191-
//return Range/*<Int64>*/(a, nil, closed: false)
239+
//return Range/*<Int64>*/(a, nil, upperBoundClosed: false)
192240
//}
193241

194242
// Strideable

0 commit comments

Comments
 (0)