-
Notifications
You must be signed in to change notification settings - Fork 0
/
Contents.swift
60 lines (48 loc) · 1.43 KB
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//: Playground - noun: a place where people can play
import UIKit
import XCTest
func bubbleSort(_ arr: inout [Int]) -> [Int] {
for _ in 0 ..< arr.count - 1 {
for j in 0 ..< arr.count - 1 {
if arr[j] > arr[j + 1] {
arr.swapAt(j, j + 1)
}
}
}
return arr
}
class BubbleSortTests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testCase1BubbleSort() {
var arr = [4, 3, 2, 1]
XCTAssertEqual(Array(1 ... 4), bubbleSort(&arr))
}
func testCase2BubbleSort() {
var arr = [6, 3, 5, 4, 1, 2]
XCTAssertEqual(Array(1 ... 6), bubbleSort(&arr))
}
func testCase3BubbleSort() {
var arr = [4, 5, 3, 6, 1, 2]
XCTAssertEqual(Array(1 ... 6), bubbleSort(&arr))
}
func testCase4BubbleSort() {
var arr = [6, 3, 5, 1]
XCTAssertEqual([1, 3, 5, 6], bubbleSort(&arr))
}
}
class TestObserver: NSObject, XCTestObservation {
func testCase(_ testCase: XCTestCase,
didFailWithDescription description: String,
inFile filePath: String?,
atLine lineNumber: Int) {
assertionFailure(description, line: UInt(lineNumber))
}
}
let testObserver = TestObserver()
XCTestObservationCenter.shared.addTestObserver(testObserver)
BubbleSortTests.defaultTestSuite.run()