添加 structures

This commit is contained in:
YDZ
2020-08-06 23:19:28 +08:00
parent ef3da5d363
commit 1934e384d2
18 changed files with 1079 additions and 0 deletions

27
structures/Stack_test.go Normal file
View File

@ -0,0 +1,27 @@
package structures
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Stack(t *testing.T) {
ast := assert.New(t)
s := NewStack()
ast.True(s.IsEmpty(), "检查新建的 s 是否为空")
start, end := 0, 100
for i := start; i < end; i++ {
s.Push(i)
ast.Equal(i-start+1, s.Len(), "Push 后检查 q 的长度。")
}
for i := end - 1; i >= start; i-- {
ast.Equal(i, s.Pop(), "从 s 中 pop 出数来。")
}
ast.True(s.IsEmpty(), "检查 Pop 完毕后的 s 是否为空")
}