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

Function TestTreeGetOrHas

structure/tree/tree_test.go:12–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestTreeGetOrHas(t *testing.T) {
13 helper := func(tree TestTree[int], nums []int) {
14 tree.Push(nums...)
15 for _, num := range nums {
16 if !tree.Has(num) {
17 t.Errorf("Error with Has or Push method")
18 }
19 }
20
21 min, _ := tree.Min()
22 max, _ := tree.Max()
23
24 if _, ok := tree.Get(min - 1); ok {
25 t.Errorf("Error with Get method")
26 }
27
28 if _, ok := tree.Get(max + 1); ok {
29 t.Errorf("Error with Get method")
30 }
31 }
32
33 lens := []int{100, 1_000, 10_000, 100_000}
34 for _, ll := range lens {
35 nums := rand.Perm(ll)
36 t.Run("Test Binary Search Tree", func(t *testing.T) {
37 bsTree := bt.NewBinarySearch[int]()
38 helper(bsTree, nums)
39 })
40
41 t.Run("Test Red-Black Tree", func(t *testing.T) {
42 rbTree := bt.NewRB[int]()
43 helper(rbTree, nums)
44 })
45
46 t.Run("Test AVL Tree", func(t *testing.T) {
47 avlTree := bt.NewAVL[int]()
48 helper(avlTree, nums)
49 })
50 }
51}
52
53func TestTreePreOrder(t *testing.T) {
54 t.Run("Test for Binary-Search Tree", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

PushMethod · 0.65
HasMethod · 0.65
MinMethod · 0.65
MaxMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected