|
| 1 | +// |
| 2 | +// SortsTests.swift |
| 3 | +// SortsTests |
| 4 | +// |
| 5 | +// Created by Wenru Dong on 2018/10/14. |
| 6 | +// Copyright © 2018年 Wenru Dong. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import XCTest |
| 10 | + |
| 11 | +class SortsTests: XCTestCase { |
| 12 | + |
| 13 | + override func setUp() { |
| 14 | + super.setUp() |
| 15 | + // Put setup code here. This method is called before the invocation of each test method in the class. |
| 16 | + } |
| 17 | + |
| 18 | + override func tearDown() { |
| 19 | + // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 20 | + super.tearDown() |
| 21 | + } |
| 22 | + |
| 23 | + func testMergeSort() { |
| 24 | + var a1 = [1, 1, 1, 1] |
| 25 | + mergeSort(&a1) |
| 26 | + XCTAssertEqual(a1, [1, 1, 1, 1]) |
| 27 | + |
| 28 | + var a2 = [4, 3, 2, 1] |
| 29 | + mergeSort(&a2) |
| 30 | + XCTAssertEqual(a2, [1, 2, 3, 4]) |
| 31 | + |
| 32 | + var a3 = [3, 6, 9, 7, 8, -1, 9, 3, -2, 0] |
| 33 | + mergeSort(&a3) |
| 34 | + XCTAssertEqual(a3, [-2, -1, 0, 3, 3, 6, 7, 8, 9, 9]) |
| 35 | + } |
| 36 | + |
| 37 | + func testQuickSort() { |
| 38 | + var a1 = [1, 1, 1, 1] |
| 39 | + quickSort(&a1) |
| 40 | + XCTAssertEqual(a1, [1, 1, 1, 1]) |
| 41 | + |
| 42 | + var a2 = [4, 3, 2, 1] |
| 43 | + quickSort(&a2) |
| 44 | + XCTAssertEqual(a2, [1, 2, 3, 4]) |
| 45 | + |
| 46 | + var a3 = [3, 6, 9, 7, 8, -1, 9, 3, -2, 0] |
| 47 | + quickSort(&a3) |
| 48 | + XCTAssertEqual(a3, [-2, -1, 0, 3, 3, 6, 7, 8, 9, 9]) |
| 49 | + } |
| 50 | + |
| 51 | + func testPerformanceExample() { |
| 52 | + // This is an example of a performance test case. |
| 53 | + self.measure { |
| 54 | + // Put the code you want to measure the time of here. |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | +} |
0 commit comments