Created
November 25, 2017 10:20
-
-
Save adriantofan/fec9299349fc5c021d1eb2ac50e27192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension NSMutableOrderedSet { | |
struct rb { | |
static func insertSorted<T>(element: T, inTo set:NSMutableOrderedSet, isLessThan: (_ lhs:T,_ rhs:T) -> Bool){ | |
for i in 0 ..< set.count { | |
let x = set[i] as! T | |
if !isLessThan(x,element) { | |
set.insert(element, at: i) | |
return | |
} | |
} | |
set.insert(element, at: set.count) | |
} | |
} | |
} | |
import Foundation | |
@testable import RideBot | |
import Quick | |
import Nimble | |
import SwiftCheck | |
fileprivate let compare = { (_ lhs:Double,_ rhs:Double) -> Bool in | |
return lhs < rhs | |
} | |
class NSMutableOrderedSetSpec: QuickSpec { | |
override func spec() { | |
fit("keeps a NSMutableOrdered set sorted"){ | |
property("adding elements in a set keeps them sorted") <- forAll { (l : ArrayOf<Double>) in | |
let set = NSMutableOrderedSet() | |
let xs = l.getArray | |
for x in xs { | |
NSMutableOrderedSet.rb.insertSorted(element: x, inTo: set, isLessThan: compare) | |
} | |
let elements = set.array as! [Double] | |
return elements == elements.sorted() && xs.count == elements.count | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment