File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ using Test
4
4
5
5
@testset " TreeDataStructures.jl" begin
6
6
@testset " AVLTree" begin
7
+ # insert
7
8
tree = AVLTree {Int,Int} ()
8
9
tree[2 ] = 20
9
10
tree[1 ] = 10
@@ -24,6 +25,37 @@ using Test
24
25
@test tree[3 ] isa Float64
25
26
@test tree[3 ] == 30.0
26
27
28
+ # update values
29
+ tree = AVLTree {Int,Int} ()
30
+ tree[2 ] = 20
31
+ tree[1 ] = 10
32
+ tree[3 ] = 30
33
+ @test tree[2 ] == 20
34
+ @test tree[1 ] == 10
35
+ @test tree[3 ] == 30
36
+ tree[2 ] = 22
37
+ tree[1 ] = 11
38
+ tree[3 ] = 33
39
+ @test tree[2 ] == 22
40
+ @test tree[1 ] == 11
41
+ @test tree[3 ] == 33
42
+
43
+ # delete
44
+ tree = AVLTree {Int,Int} ()
45
+ tree[2 ] = 20
46
+ tree[1 ] = 10
47
+ tree[3 ] = 30
48
+ delete! (tree, 3 )
49
+ @test ! isnothing (tree. root)
50
+ @test ! isnothing (tree. root. left)
51
+ @test isnothing (tree. root. right)
52
+ delete! (tree, 1 )
53
+ @test ! isnothing (tree. root)
54
+ @test isnothing (tree. root. left)
55
+ @test isnothing (tree. root. right)
56
+ delete! (tree, 2 )
57
+ @test isnothing (tree. root)
58
+
27
59
# tree that accept any types
28
60
tree = AVLTree ()
29
61
tree[2 ] = ' A'
You can’t perform that action at this time.
0 commit comments