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

Function TestRBTreeDelete

structure/tree/rbtree_test.go:48–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

46}
47
48func TestRBTreeDelete(t *testing.T) {
49 tree := bt.NewRB[int]()
50 var ok bool
51
52 nums := []int{10, 8, 88, 888, 4, 1<<63 - 1, -(1 << 62), 188, -188, 4, 88, 1 << 32}
53 tree.Push(nums...)
54
55 ok = tree.Delete(188)
56
57 if ret := tree.InOrder(); !ok || !sort.IntsAreSorted(ret) {
58 t.Errorf("Error with Delete: %v", ret)
59 }
60
61 ok = tree.Delete(188)
62 if ret := tree.InOrder(); ok || !sort.IntsAreSorted(ret) {
63 t.Errorf("Error with Delete: %v", ret)
64 }
65
66 ok = tree.Delete(1<<63 - 1)
67 if ret := tree.InOrder(); !ok || !sort.IntsAreSorted(ret) {
68 t.Errorf("Error with Delete: %v", ret)
69 }
70
71 ok = tree.Delete(4)
72 if ret := tree.InOrder(); !ok || !sort.IntsAreSorted(ret) {
73 t.Errorf("Error with Delete: %v", ret)
74 }
75
76 if ret, ok := tree.Max(); !ok || ret != (1<<32) {
77 t.Errorf("Error with Delete, max: %v, want: %v", ret, (1 << 32))
78 }
79
80 if ret, ok := tree.Min(); !ok || ret != -(1<<62) {
81 t.Errorf("Error with Delete, min: %v, want: %v", ret, (1 << 32))
82 }
83}
84
85func TestRBTree(t *testing.T) {
86 testcases := []int{100, 200, 1000, 10000}

Callers

nothing calls this directly

Calls 5

PushMethod · 0.65
DeleteMethod · 0.65
InOrderMethod · 0.65
MaxMethod · 0.65
MinMethod · 0.65

Tested by

no test coverage detected