We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 66c83d0 + 13ec9b0 commit 54328aeCopy full SHA for 54328ae
Swiftz/ArrayExt.swift
@@ -77,9 +77,11 @@ public func find<T>(list : [T], f : (T -> Bool)) -> T? {
77
/// splitAt(0, [1,2,3]) == ([],[1,2,3])
78
public func splitAt<T>(index : Int, list : [T]) -> ([T], [T]) {
79
switch index {
80
- case 0..<list.count:
+ case 0..<list.count:
81
return (Array(list[0..<index]), Array(list[index..<list.count]))
82
- case _:
+ case list.count...Int.max:
83
+ return (list, [T]())
84
+ default:
85
return ([T](), [T]())
86
}
87
SwiftzTests/ArrayExtSpec.swift
@@ -70,15 +70,19 @@ class ArrayExtSpec : XCTestCase {
70
XCTAssert(found == 4, "Should be found")
71
72
73
-
+
74
func testSplitAt() {
75
let withArray = [1,2,3,4]
76
let tuple = splitAt(2,withArray)
XCTAssert(tuple.0 == [1,2] && tuple.1 == [3,4], "Should be equal")
XCTAssert(splitAt(0,withArray).0 == Array() && splitAt(0, withArray).1 == [1,2,3,4], "Should be equal")
+ XCTAssert(splitAt(1,withArray).0 == [1] && splitAt(1, withArray).1 == [2,3,4], "Should be equal")
+ XCTAssert(splitAt(3,withArray).0 == [1,2,3] && splitAt(3, withArray).1 == [4], "Should be equal")
+ XCTAssert(splitAt(4,withArray).0 == [1,2,3,4] && splitAt(4, withArray).1 == Array(), "Should be equal")
+ XCTAssert(splitAt(5,withArray).0 == [1,2,3,4] && splitAt(5, withArray).1 == Array(), "Should be equal")
XCTAssert(withArray == [1,2,3,4], "Should be equal(immutablility test)")
88
0 commit comments