forked from kodecocodes/swift-algorithm-club
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeNodeTests.swift
88 lines (69 loc) · 2.26 KB
/
TreeNodeTests.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
//
// TreeNodeTest.swift
// AVLTreeTests
//
// Created by Barbara Rodeker on 2/19/16.
// Copyright © 2016 Swift Algorithm Club. All rights reserved.
//
import XCTest
class TreeNodeTests: XCTestCase {
var root: TreeNode<String, String>?
var left: TreeNode<String, String>?
var right: TreeNode<String, String>?
func testSwift4() {
// last checked with Xcode 9.0b4
#if swift(>=4.0)
print("Hello, Swift 4!")
#endif
}
override func setUp() {
super.setUp()
left = TreeNode<String, String>(key: "Name", payload: "Left")
right = TreeNode<String, String>(key: "Name", payload: "Right")
root = TreeNode<String, String>(key: "Name", payload: "Root", leftChild: left, rightChild: right, parent: nil, height: 0)
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testSingleNodeCreationNOPayload() {
let treeNode = TreeNode<String, String>(key: "Building")
XCTAssertNil(treeNode.payload, "Payload for this case should be nil")
}
func testSingleNodeCreationWithPayload() {
XCTAssertNotNil(self.root!, "Payload for this case should not be nil")
}
func testIsRoot() {
XCTAssertTrue(self.root!.isRoot)
}
func testNotIsLeaf() {
XCTAssertFalse(self.root!.isLeaf, "root node is not leaf")
}
func testNotIsLeftChild() {
XCTAssertFalse(self.root!.isLeftChild, "root node is not left child")
}
func testNotIsRightChild() {
XCTAssertFalse(self.root!.isRightChild, "root node is not right child")
}
func testIsLeftChild() {
XCTAssertTrue(self.left!.isLeftChild)
}
func testIsRightChild() {
XCTAssertTrue(self.right!.isRightChild)
}
func isLeaf() {
XCTAssertTrue(self.left!.isLeaf)
}
func testHasAnyChild() {
XCTAssertTrue(self.root!.hasAnyChild)
}
func testNotHasAnyChild() {
XCTAssertFalse(self.left!.hasAnyChild)
}
func testHasBothChildren() {
XCTAssertTrue(self.root!.hasBothChildren)
}
func testNotHasBothChildren() {
XCTAssertFalse(self.left!.hasBothChildren)
}
}