|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | import XCTest
|
| 10 | +@testable import testAVL |
10 | 11 |
|
11 | 12 | class AVLTreeTests: XCTestCase {
|
12 | 13 |
|
@@ -68,6 +69,53 @@ class AVLTreeTests: XCTestCase {
|
68 | 69 | self.tree?.search(400)
|
69 | 70 | }
|
70 | 71 | }
|
| 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 | + |
71 | 119 | }
|
72 | 120 |
|
73 | 121 | extension AVLTree where Key : SignedIntegerType {
|
|
0 commit comments