MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestStackLinkedList

Function TestStackLinkedList

structure/stack/stack_test.go:20–67  ·  view source on GitHub ↗

TestStackLinkedList for testing Stack with LinkedList

(t *testing.T)

Source from the content-addressed store, hash-verified

18
19// TestStackLinkedList for testing Stack with LinkedList
20func TestStackLinkedList(t *testing.T) {
21 var newStack stack.Stack
22
23 newStack.Push(1)
24 newStack.Push(2)
25
26 t.Run("Stack Push", func(t *testing.T) {
27 result := newStack.Show()
28 expected := []any{2, 1}
29 for x := range result {
30 if result[x] != expected[x] {
31 t.Errorf("Stack Push is not work, got %v but expected %v", result, expected)
32 }
33 }
34 })
35
36 t.Run("Stack isEmpty", func(t *testing.T) {
37 if newStack.IsEmpty() {
38 t.Error("Stack isEmpty is returned true but expected false", newStack.IsEmpty())
39 }
40
41 })
42
43 t.Run("Stack Length", func(t *testing.T) {
44 if newStack.Length() != 2 {
45 t.Error("Stack Length should be 2 but got", newStack.Length())
46 }
47 })
48
49 newStack.Pop()
50 pop := newStack.Pop()
51
52 t.Run("Stack Pop", func(t *testing.T) {
53 if pop != 1 {
54 t.Error("Stack Pop should return 1 but is returned", pop)
55 }
56
57 })
58
59 newStack.Push(52)
60 newStack.Push(23)
61 newStack.Push(99)
62 t.Run("Stack Peek", func(t *testing.T) {
63 if newStack.Peek() != 99 {
64 t.Error("Stack Peak should return 99 but got ", newStack.Peek())
65 }
66 })
67}
68
69// TestStackArray for testing Stack with Array
70func TestStackArray(t *testing.T) {

Callers

nothing calls this directly

Calls 6

PushMethod · 0.95
ShowMethod · 0.95
IsEmptyMethod · 0.95
LengthMethod · 0.95
PopMethod · 0.95
PeekMethod · 0.95

Tested by

no test coverage detected