github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xcontainer/stack/stack_test.go (about) 1 package stack 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestStack(t *testing.T) { 10 t.Run("slice", func(t *testing.T) { 11 s := NewSliceStack(10) 12 s.Push(1) 13 assert.Equal(t, 1, s.Size(), "stack size is 1 after put one element") 14 s.Push(false) 15 assert.Equal(t, 2, s.Size(), "stack size is 2 after put another element") 16 peek, ok := s.Peek() 17 assert.Equal(t, true, ok, "stack has peek element") 18 assert.Equal(t, false, peek, "peek value is bool(false)") 19 pop, ok := s.Pop() 20 assert.Equal(t, true, ok, "stack has peek element so should be popped") 21 assert.Equal(t, false, pop, "popped value is bool(false)") 22 assert.Equal(t, 1, s.Size(), "stack size should be 1 after pop one element") 23 }) 24 }