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

Function TestStackLinkedListWithList

structure/stack/stack_test.go:132–188  ·  view source on GitHub ↗

TestStackLinkedListWithList for testing Stack with Container/List Library (STL)

(t *testing.T)

Source from the content-addressed store, hash-verified

130
131// TestStackLinkedListWithList for testing Stack with Container/List Library (STL)
132func TestStackLinkedListWithList(t *testing.T) {
133 stackList := &stack.SList{
134 Stack: list.New(),
135 }
136
137 t.Run("Stack Push", func(t *testing.T) {
138
139 stackList.Push(2)
140 stackList.Push(3)
141
142 if stackList.Length() != 2 {
143 t.Errorf("Stack Push is not work we expected %v but got %v", 2, stackList.Length())
144 }
145 })
146
147 t.Run("Stack Pop", func(t *testing.T) {
148 pop, _ := stackList.Pop()
149
150 if stackList.Length() == 1 && pop != 3 {
151 t.Errorf("Stack Pop is not work we expected %v but got %v", 3, pop)
152 }
153 })
154
155 t.Run("Stack Peak", func(t *testing.T) {
156
157 stackList.Push(2)
158 stackList.Push(83)
159 peak, _ := stackList.Peek()
160 if peak != 83 {
161 t.Errorf("Stack Peak is not work we expected %v but got %v", 83, peak)
162 }
163 })
164
165 t.Run("Stack Length", func(t *testing.T) {
166 if stackList.Length() != 3 {
167 t.Errorf("Stack Length is not work we expected %v but got %v", 3, stackList.Length())
168 }
169 })
170
171 t.Run("Stack Empty", func(t *testing.T) {
172 if stackList.IsEmpty() == true {
173 t.Errorf("Stack Empty is not work we expected %v but got %v", false, stackList.IsEmpty())
174 }
175
176 d1, err := stackList.Pop()
177 d2, _ := stackList.Pop()
178 d3, _ := stackList.Pop()
179
180 if err != nil {
181 t.Errorf("got an unexpected error %v, pop1: %v, pop2: %v, pop3: %v", err, d1, d2, d3)
182 }
183
184 if stackList.IsEmpty() == false {
185 t.Errorf("Stack Empty is not work we expected %v but got %v", true, stackList.IsEmpty())
186 }
187 })
188}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected