-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQueueTest.swift
83 lines (50 loc) · 1.83 KB
/
QueueTest.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
//
// QueueTest.swift
// SwiftStructures
//
// Created by Wayne Bishop on 8/5/15.
// Copyright (c) 2015 Arbutus Software Inc. All rights reserved.
//
import XCTest
@testable import SwiftStructures
class QueueTest: XCTestCase {
var numberList: Array<Int>!
override func setUp() {
super.setUp()
numberList = [8, 2, 10, 9, 7, 5]
}
/*
notes: This test class mimics the basic functionality of adding and removing queue items.
The "times" closure expression used is a custom implementation and is not part
of the core library.
*/
//test the deQueueing process
func testDeQueue() {
let q: Queue<Int>! = buildQueue()
XCTAssertNotNil(q, "queue instance not present..")
//deQueue list items..
numberList.count.times { (s: Int) -> Void in
print("the queued item is \(q.peek() as Int?)")
print ("count is: \(q.count)")
_ = q.deQueue()
}
//check for queued items
XCTAssertTrue(q.count == 0, "deQueue process failed..")
XCTAssertTrue(q.isEmpty(), "queue isEmpty() process failed..")
}
//MARK: helper methods
func buildQueue() -> Queue<Int>! {
let newq: Queue<Int>! = Queue<Int>()
XCTAssertTrue(newq.count == 0, "new queue instance not created..")
//build queue
for s in numberList {
newq.enQueue(s)
print("count is: \(newq.count)")
}
//check equality
if newq.count != numberList.count {
XCTFail("queue build failed..")
}
return newq
}
}