Skip to content

Commit 87dc391

Browse files
More test cases for AVLTree
1 parent f0d833a commit 87dc391

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

AVL Tree/Tests/AVLTreeTests.swift

+48
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import XCTest
10+
@testable import testAVL
1011

1112
class AVLTreeTests: XCTestCase {
1213

@@ -68,6 +69,53 @@ class AVLTreeTests: XCTestCase {
6869
self.tree?.search(400)
6970
}
7071
}
72+
73+
func testMinimumOnPopulatedTree() {
74+
self.tree?.autopopulateWithNodes(500)
75+
let min = self.tree?.root?.minimum()
76+
XCTAssertNotNil(min, "Minimum function not working")
77+
}
78+
79+
func testMinimumOnSingleTreeNode() {
80+
let treeNode = TreeNode(key: 1, payload: "A")
81+
let min = treeNode.minimum()
82+
83+
XCTAssertNotNil(min, "Minimum on single node should be returned")
84+
XCTAssertEqual(min?.payload,treeNode.payload)
85+
}
86+
87+
func testSuccessorOfRoot() {
88+
self.tree?.autopopulateWithNodes(10)
89+
let successor = self.tree?.root?.successor()
90+
XCTAssertNotNil(successor, "Succesor of root, non-empty tree, not found")
91+
}
92+
93+
func testSuccessorOfMinimum() {
94+
self.tree?.autopopulateWithNodes(10)
95+
96+
let minimum = self.tree?.root?.minimum()
97+
XCTAssertNotNil(minimum, "Minimum should exist here")
98+
99+
let successor = minimum!.successor()
100+
XCTAssertNotNil(successor, "Succesor of minimum, non-empty tree, not found")
101+
}
102+
103+
func testSuccessorSingleNode() {
104+
let singleNode = TreeNode(key: 1, payload: "A")
105+
let successor = singleNode.successor()
106+
XCTAssertNil(successor, "Empty node should not have succesor")
107+
}
108+
109+
func testDeleteExistentKey() {
110+
self.tree?.delete(1)
111+
XCTAssertNil(self.tree?.search(1), "Key should not exist anymore")
112+
}
113+
114+
func testDeleteNOTExistentKey() {
115+
self.tree?.delete(1056)
116+
XCTAssertNil(self.tree?.search(1056), "Key should not exist")
117+
}
118+
71119
}
72120

73121
extension AVLTree where Key : SignedIntegerType {

0 commit comments

Comments
 (0)