-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStructureTest.swift
106 lines (63 loc) · 2.84 KB
/
StructureTest.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
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// StructuresTest.swift
// SwiftStructures
//
// Created by Wayne Bishop on 9/17/14.
// Copyright (c) 2014 Arbutus Software Inc. All rights reserved.
//
import UIKit
import XCTest
@testable import SwiftStructures
class StructureTest: XCTestCase {
//MARK: Node objects
func testNode() {
let testNode = Node<Int>()
XCTAssertNotNil(testNode, "instance not initialized..")
XCTAssertNil(testNode.key, "key not initialized..")
XCTAssertNil(testNode.next, "next instance not initialized..")
}
func testLLNode() {
let testLLNode: LLNode<Int> = LLNode<Int>()
XCTAssertNotNil(testLLNode, "instance not initialized..")
XCTAssertNil(testLLNode.key, "key not initialized..")
XCTAssertNil(testLLNode.next, "next node propety not initialized..")
XCTAssertNil(testLLNode.previous, "previous node propety not initialized..")
}
//MARK: Graph objects
func testVertex() {
let testVertex: Vertex = Vertex()
XCTAssertNotNil(testVertex, "instance not intialized..")
XCTAssertFalse(testVertex.visited, "visited property not intialized..")
//downcast to test for membership
let neigborList: AnyObject = testVertex.neighbors as AnyObject
if !(neigborList is Array<Edge>) {
XCTFail("neighborlist does not include array list of edges..")
}
}
func testEdge() {
let edgeTest: Edge = Edge()
XCTAssertNotNil(edgeTest, "instance not initialized..")
XCTAssertEqual(edgeTest.weight, 0, "edge weight not initialized..")
let testVertex: AnyObject = edgeTest.neighbor as AnyObject
if !(testVertex is Vertex) {
XCTFail("edge vertex not intialized..")
}
}
func testPath() {
let pathTest: Path = Path()
XCTAssertNotNil(pathTest, "instance not initialized..")
XCTAssertNil(pathTest.previous, "path previous property not initialized..")
XCTAssertTrue(pathTest.total == 0, "path total property not initialized..")
let testVertex: AnyObject = pathTest.destination as AnyObject
if !(testVertex is Vertex) {
XCTFail("destination vertex not intialized..")
}
}
func testBSNode() {
let testNode = BSNode<Int>()
XCTAssertNotNil(testNode, "instance not initialized..")
XCTAssertNil(testNode.key, "key property not initialized..")
XCTAssertNil(testNode.left, "left property not initialized..")
XCTAssertNil(testNode.right, "right property not initialized..")
}
}