algorithms-go/DataStructure/stack/stack_array_test.go
2021-04-07 18:13:02 +08:00

36 lines
563 B
Go

package stack
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestNew(t *testing.T) {
s := New()
for i := 0; i < 10; i++ {
err := s.Push(i)
assert.NoError(t, err)
}
err := s.Push(11)
assert.Error(t, err)
for i := 9; i >= 0; i-- {
k, _ := s.Pop()
assert.Equal(t, i, k)
}
_, err = s.Pop()
assert.Error(t, err)
}
func TestNewListStack(t *testing.T) {
s := NewListStack()
for i := 0; i < 10; i++ {
s.Push(i)
}
for i := 9; i >= 0; i-- {
k, _ := s.Pop()
assert.Equal(t, i, k)
}
_, err := s.Pop()
assert.Error(t, err)
}