-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenumTest.swift
85 lines (47 loc) · 2.04 KB
/
enumTest.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// enumTest.swift
// SwiftStructures
//
// Created by Wayne Bishop on 4/25/16.
// Copyright © 2016 Arbutus Software Inc. All rights reserved.
//
import XCTest
@testable import SwiftStructures
/*
notes: this test class adopts the Sortable protocol. as a result,
the isSorted function originates from the protocol extension.
*/
class enumsTest: XCTestCase, Sortable {
let list = Algorithm.Elements([8, 2, 10, 9, 7, 5])
override func setUp() {
super.setUp()
}
//model for insertion sort algorithm
func testInsertModel() {
let model = Algorithm.InsertionSort(list)
self.buildEnumModel(withModel: model)
}
//model for insertion sort (with text)
func testInsertTextModel() {
let textList = Algorithm.Elements(["Dog", "Cat", "Dinasour", "Lion", "Cheetah", "Elephant", "Aardvark"])
let model = Algorithm.InsertionSort(textList)
self.buildEnumModel(withModel: model)
}
//model for bubble sort algorithm
func testBubbleModel() {
let model = Algorithm.BubbleSort(list)
self.buildEnumModel(withModel: model)
}
//model for selection sort algorithm
func testSelectionModel() {
let model = Algorithm.SelectionSort(list)
self.buildEnumModel(withModel: model)
}
//MARK: Helper Function
//helper function - test enum model
func buildEnumModel<T: Comparable>(withModel model: Algorithm<T>) {
let enumModel = EnumModel()
let results = enumModel.evaluate(withModel: model)
XCTAssertTrue(self.isSorted(results!), "list values incorrectly sorted..")
}
}