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