MCPcopy
hub / github.com/TheAlgorithms/Go / TestTreePredecessorAndSuccessor

Function TestTreePredecessorAndSuccessor

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

Source from the content-addressed store, hash-verified

415}
416
417func TestTreePredecessorAndSuccessor(t *testing.T) {
418 helper := func(tree TestTree[int]) {
419 nums := []int{10, 8, 88, 888, 4, -1, 100}
420 tree.Push(nums...)
421 if ret, ok := tree.Predecessor(100); !ok || ret != 88 {
422 t.Error("Error with Predecessor")
423 }
424
425 if _, ok := tree.Predecessor(-1); ok {
426 t.Error("Error with Predecessor")
427 }
428
429 tree.Push(-100)
430 if ret, ok := tree.Predecessor(-1); !ok || ret != -100 {
431 t.Error("Error with Predecessor")
432 }
433
434 if _, ok := tree.Predecessor(-12); ok {
435 t.Error("Error with Predecessor")
436 }
437
438 if ret, ok := tree.Predecessor(4); !ok || ret != -1 {
439 t.Error("Error with Predecessor")
440 }
441
442 if ret, ok := tree.Successor(4); !ok || ret != 8 {
443 t.Error("Error with Successor")
444 }
445
446 if ret, ok := tree.Successor(8); !ok || ret != 10 {
447 t.Error("Error with Successor")
448 }
449
450 if ret, ok := tree.Successor(88); !ok || ret != 100 {
451 t.Error("Error with Successor")
452 }
453
454 if ret, ok := tree.Successor(100); !ok || ret != 888 {
455 t.Error("Error with Successor")
456 }
457
458 tree.Delete(888)
459 if _, ok := tree.Successor(100); ok {
460 t.Error("Error with Successor")
461 }
462
463 if ret, ok := tree.Successor(-1); !ok || ret != 4 {
464 t.Error("Error with Successor")
465 }
466
467 if _, ok := tree.Successor(888); ok {
468 t.Error("Error with Successor")
469 }
470
471 if _, ok := tree.Successor(188); ok {
472 t.Error("Error with Successor")
473 }
474 }

Callers

nothing calls this directly

Calls 4

PushMethod · 0.65
PredecessorMethod · 0.65
SuccessorMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected