// RUN: %target-run-simple-swift | FileCheck %s // Generate all possible permutes. func _permuteInternal( elem: Int, _ size : Int, inout _ perm : [Int], inout _ visited : [Bool], _ verify : ([Int]) -> () ) { if (elem == size) { verify(perm) return } for i in 0.. ()) { var perm = [Int](count: size, repeatedValue: 0) var visited = [Bool](count: size, repeatedValue: false) _permuteInternal(0, size, &perm, &visited, verify) } // A simple random number generator. func randomize(size : Int, _ verify : ([Int]) -> ()) { var arr : [Int] = [] var N = 1 var M = 1 for i in 0.. () = { println($0) } //CHECK: [0, 1, 2] //CHECK: [0, 2, 1] //CHECK: [1, 0, 2] //CHECK: [1, 2, 0] //CHECK: [2, 0, 1] //CHECK: [2, 1, 0] permute(3, printer) // Now, let's verify the sort. let sort_verifier : ([Int]) -> () = { var y = sorted($0) for i in 0.. y[i+1]) { println("Error: \(y)") return } } } //CHECK-NOT: Error! permute(2, sort_verifier) permute(6, sort_verifier) permute(7, sort_verifier) //CHECK: Test1 - Done println("Test1 - Done") // Now, let's verify the sort. let partition_verifier : ([Int]) -> () = { var y = $0 // Partition() returns the index to the pivot value. let idx = partition(&y, 0.. y[idx] { print("Error!\n") return } } // Check that all of the elements in the second partition are greater or // equal to the pivot value. for i in idx..