Skip to content

Commit

Permalink
Fix warning and error on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
youming-lin committed Sep 13, 2017
1 parent 8e0c79c commit 5b1b9b2
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright IBM Corporation 2016
* Copyright IBM Corporation 2016, 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,20 +19,37 @@ import Glibc
@testable import KituraNetTests

// http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift
extension MutableCollection where Indices.Iterator.Element == Index {
mutating func shuffle() {
let c = count
guard c > 1 else { return }

srand(UInt32(time(nil)))
for (firstUnshuffled , unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swap(&self[firstUnshuffled], &self[i])
#if swift(>=3.2)
extension MutableCollection {
mutating func shuffle() {
let c = count
guard c > 1 else { return }

srand(UInt32(time(nil)))
for (firstUnshuffled , unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swapAt(firstUnshuffled, i)
}
}
}
}
#else
extension MutableCollection where Indices.Iterator.Element == Index {
mutating func shuffle() {
let c = count
guard c > 1 else { return }

srand(UInt32(time(nil)))
for (firstUnshuffled , unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swap(&self[firstUnshuffled], &self[i])
}
}
}
#endif

extension Sequence {
func shuffled() -> [Iterator.Element] {
Expand All @@ -43,16 +60,16 @@ extension Sequence {
}

XCTMain([
testCase(ClientE2ETests.allTests.shuffled()),
testCase(ClientRequestTests.allTests.shuffled()),
testCase(FastCGIProtocolTests.allTests.shuffled()),
testCase(FastCGIRequestTests.allTests.shuffled()),
testCase(HTTPResponseTests.allTests.shuffled()),
testCase(LargePayloadTests.allTests.shuffled()),
testCase(LifecycleListenerTests.allTests.shuffled()),
testCase(MiscellaneousTests.allTests.shuffled()),
testCase(MonitoringTests.allTests.shuffled()),
testCase(ParserTests.allTests.shuffled()),
testCase(SocketManagerTests.allTests.shuffled()),
testCase(UpgradeTests.allTests.shuffled())
].shuffled())
testCase(ClientE2ETests.allTests.shuffled()),
testCase(ClientRequestTests.allTests.shuffled()),
testCase(FastCGIProtocolTests.allTests.shuffled()),
testCase(FastCGIRequestTests.allTests.shuffled()),
testCase(HTTPResponseTests.allTests.shuffled()),
testCase(LargePayloadTests.allTests.shuffled()),
testCase(LifecycleListenerTests.allTests.shuffled()),
testCase(MiscellaneousTests.allTests.shuffled()),
testCase(MonitoringTests.allTests.shuffled()),
testCase(ParserTests.allTests.shuffled()),
testCase(SocketManagerTests.allTests.shuffled()),
testCase(UpgradeTests.allTests.shuffled())
].shuffled())

0 comments on commit 5b1b9b2

Please sign in to comment.