-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathQueueTests.swift
executable file
·69 lines (57 loc) · 1.62 KB
/
QueueTests.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
import Foundation
import XCTest
class QueueTest: XCTestCase {
func testEmpty() {
var queue = Queue<Int>()
XCTAssertTrue(queue.isEmpty)
XCTAssertEqual(queue.count, 0)
XCTAssertEqual(queue.front, nil)
XCTAssertNil(queue.dequeue())
}
func testOneElement() {
var queue = Queue<Int>()
queue.enqueue(123)
XCTAssertFalse(queue.isEmpty)
XCTAssertEqual(queue.count, 1)
XCTAssertEqual(queue.front, 123)
let result = queue.dequeue()
XCTAssertEqual(result, 123)
XCTAssertTrue(queue.isEmpty)
XCTAssertEqual(queue.count, 0)
XCTAssertEqual(queue.front, nil)
}
func testTwoElements() {
var queue = Queue<Int>()
queue.enqueue(123)
queue.enqueue(456)
XCTAssertFalse(queue.isEmpty)
XCTAssertEqual(queue.count, 2)
XCTAssertEqual(queue.front, 123)
let result1 = queue.dequeue()
XCTAssertEqual(result1, 123)
XCTAssertFalse(queue.isEmpty)
XCTAssertEqual(queue.count, 1)
XCTAssertEqual(queue.front, 456)
let result2 = queue.dequeue()
XCTAssertEqual(result2, 456)
XCTAssertTrue(queue.isEmpty)
XCTAssertEqual(queue.count, 0)
XCTAssertEqual(queue.front, nil)
}
func testMakeEmpty() {
var queue = Queue<Int>()
queue.enqueue(123)
queue.enqueue(456)
XCTAssertNotNil(queue.dequeue())
XCTAssertNotNil(queue.dequeue())
XCTAssertNil(queue.dequeue())
queue.enqueue(789)
XCTAssertEqual(queue.count, 1)
XCTAssertEqual(queue.front, 789)
let result = queue.dequeue()
XCTAssertEqual(result, 789)
XCTAssertTrue(queue.isEmpty)
XCTAssertEqual(queue.count, 0)
XCTAssertEqual(queue.front, nil)
}
}