-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStackTest.swift
93 lines (51 loc) · 2.07 KB
/
StackTest.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
86
87
88
89
90
91
92
93
//
// StackTest.swift
// SwiftStructures
//
// Created by Wayne Bishop on 9/1/15.
// Copyright © 2015 Arbutus Software Inc. All rights reserved.
//
import XCTest
@testable import SwiftStructures
class StackTest: XCTestCase {
var numberList: Array<Int>!
override func setUp() {
super.setUp()
numberList = [8, 2, 10, 9, 1, 5]
}
//provides self-contained example of push function - essay example
func testPushStack() {
let myStack = Stack<Int>()
XCTAssertTrue(myStack.count == 0, "test failed: count not initialized..")
//build stack
for s in numberList {
myStack.push(withKey: s)
print("item: \(s) added..")
}
XCTAssertTrue(myStack.count == numberList.count, "test failed: stack count does not match..")
}
func testPopStack() {
//build stack - helper function
let myStack: Stack<Int> = self.buildStack()
if myStack.count == 0 {
XCTFail("test failed: no stack items available..")
}
for _ in stride(from: myStack.count, through: 0, by: -1) {
print("stack item is: \(String(describing: myStack.peek().key)). stack count: \(myStack.count)")
myStack.pop()
}
XCTAssertTrue(myStack.isEmpty(), "test failed: stack structured not emptied..")
}
//MARK: helper methods
func buildStack() -> Stack<Int>! {
let newStack: Stack<Int> = Stack<Int>()
XCTAssertTrue(newStack.count == 0, "test failed: count not initialized..")
//build stack
for s in numberList {
newStack.push(withKey: s)
print("item: \(s) added..")
}
print("stack count is: \(newStack.count)")
return newStack
}
}