TestStackArray for testing Stack with Array
(t *testing.T)
| 68 | |
| 69 | // TestStackArray for testing Stack with Array |
| 70 | func TestStackArray(t *testing.T) { |
| 71 | newStack := stack.NewStack[int]() |
| 72 | t.Run("Stack With Array", func(t *testing.T) { |
| 73 | |
| 74 | newStack.Push(2) |
| 75 | newStack.Push(3) |
| 76 | |
| 77 | t.Run("Stack Push", func(t *testing.T) { |
| 78 | var stackElements []any |
| 79 | for i := 0; i < 2; i++ { |
| 80 | poppedElement := newStack.Pop() |
| 81 | stackElements = append(stackElements, poppedElement) |
| 82 | } |
| 83 | |
| 84 | if !reflect.DeepEqual([]any{3, 2}, stackElements) { |
| 85 | t.Errorf("Stack Push is not work we expected %v but got %v", []any{3, 2}, newStack) |
| 86 | } |
| 87 | |
| 88 | newStack.Push(2) |
| 89 | newStack.Push(3) |
| 90 | }) |
| 91 | |
| 92 | pop := newStack.Pop() |
| 93 | |
| 94 | t.Run("Stack Pop", func(t *testing.T) { |
| 95 | if newStack.Length() == 2 && pop != 3 { |
| 96 | t.Errorf("Stack Pop is not work we expected %v but got %v", 3, pop) |
| 97 | } |
| 98 | }) |
| 99 | |
| 100 | newStack.Push(2) |
| 101 | newStack.Push(83) |
| 102 | |
| 103 | t.Run("Stack Peak", func(t *testing.T) { |
| 104 | if newStack.Peek() != 83 { |
| 105 | t.Errorf("Stack Peek is not work we expected %v but got %v", 83, newStack.Peek()) |
| 106 | } |
| 107 | }) |
| 108 | |
| 109 | t.Run("Stack Length", func(t *testing.T) { |
| 110 | if newStack.Length() != 3 { |
| 111 | t.Errorf("Stack Length is not work we expected %v but got %v", 3, newStack.Length()) |
| 112 | } |
| 113 | }) |
| 114 | |
| 115 | t.Run("Stack Empty", func(t *testing.T) { |
| 116 | if newStack.IsEmpty() == true { |
| 117 | t.Errorf("Stack Empty is not work we expected %v but got %v", false, newStack.IsEmpty()) |
| 118 | } |
| 119 | |
| 120 | newStack.Pop() |
| 121 | newStack.Pop() |
| 122 | newStack.Pop() |
| 123 | |
| 124 | if newStack.IsEmpty() == false { |
| 125 | t.Errorf("Stack Empty is not work we expected %v but got %v", true, newStack.IsEmpty()) |
| 126 | } |
| 127 | }) |