MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / TestAVLPush

Function TestAVLPush

structure/tree/avl_test.go:11–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestAVLPush(t *testing.T) {
12 t.Run("LLRotation-Test", func(t *testing.T) {
13 tree := bt.NewAVL[int]()
14 tree.Push(5, 4, 3)
15
16 root := tree.Root
17 if root.Key() != 4 {
18 t.Errorf("Root should have value = 4, not %v", root.Key())
19 }
20 if root.Height() != 2 {
21 t.Errorf("Height of Root should be = 2, not %d", root.Height())
22 }
23
24 if root.Left().Key() != 3 {
25 t.Errorf("Left child should have value = 3")
26 }
27 if root.Left().(*bt.AVLNode[int]).Height() != 1 {
28 t.Errorf("Height of Left child should be 1")
29 }
30
31 if root.Right().Key() != 5 {
32 t.Errorf("Right child should have value = 5")
33 }
34 if root.Right().(*bt.AVLNode[int]).Height() != 1 {
35 t.Errorf("Height of Right should be 1")
36 }
37 })
38
39 t.Run("LRRotation-Test", func(t *testing.T) {
40 tree := bt.NewAVL[int]()
41 tree.Push(5, 3, 4)
42
43 root := tree.Root
44 if root.Key() != 4 {
45 t.Errorf("Root should have value = 4, not %v", root.Key())
46 }
47 if root.Height() != 2 {
48 t.Errorf("Height of Root should be = 2, not %d", root.Height())
49 }
50
51 if root.Left().Key() != 3 {
52 t.Errorf("Left child should have value = 3")
53 }
54 if root.Left().(*bt.AVLNode[int]).Height() != 1 {
55 t.Errorf("Height of Left child should be 1")
56 }
57
58 if root.Right().Key() != 5 {
59 t.Errorf("Right child should have value = 5")
60 }
61 if root.Right().(*bt.AVLNode[int]).Height() != 1 {
62 t.Errorf("Height of Right should be 1")
63 }
64 })
65
66 t.Run("RRRotation-Test", func(t *testing.T) {
67 tree := bt.NewAVL[int]()
68 tree.Push(3)

Callers

nothing calls this directly

Calls 5

HeightMethod · 0.80
PushMethod · 0.65
KeyMethod · 0.65
LeftMethod · 0.65
RightMethod · 0.65

Tested by

no test coverage detected