mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 08:27:30 +08:00
添加 structures
This commit is contained in:
27
structures/Stack_test.go
Normal file
27
structures/Stack_test.go
Normal 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 是否为空")
|
||||
}
|
Reference in New Issue
Block a user