fix(testcase): modify testcase

pull/45/head
reanon 2 years ago
parent bed8b07b0b
commit d32f15feb1

@ -6,9 +6,9 @@ package chapter_stack_and_queue
import "testing" import "testing"
func TestStack(t *testing.T) { func TestArrayStack(t *testing.T) {
// 初始化栈 // 初始化栈
stack := NewLinkedListStack() stack := NewArrayStack()
// 元素入栈 // 元素入栈
stack.Push(1) stack.Push(1)
@ -35,9 +35,9 @@ func TestStack(t *testing.T) {
t.Log("栈是否为空 = ", isEmpty) t.Log("栈是否为空 = ", isEmpty)
} }
func TestArrayStack(t *testing.T) { func TestLinkedListStack(t *testing.T) {
// 初始化栈 // 初始化栈
stack := NewArrayStack() stack := NewLinkedListStack()
// 元素入栈 // 元素入栈
stack.Push(1) stack.Push(1)
@ -64,13 +64,9 @@ func TestArrayStack(t *testing.T) {
t.Log("栈是否为空 = ", isEmpty) t.Log("栈是否为空 = ", isEmpty)
} }
func TestLinkedListStack(t *testing.T) { // BenchmarkArrayStack 8 ns/op in Mac M1 Pro
func BenchmarkArrayStack(b *testing.B) {
} stack := NewArrayStack()
// BenchmarkStack 65.02 ns/op in Mac M1 Pro
func BenchmarkStack(b *testing.B) {
stack := NewLinkedListStack()
// use b.N for looping // use b.N for looping
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
stack.Push(777) stack.Push(777)
@ -80,9 +76,9 @@ func BenchmarkStack(b *testing.B) {
} }
} }
// BenchmarkArrayStack 8 ns/op in Mac M1 Pro // BenchmarkLinkedListStack 65.02 ns/op in Mac M1 Pro
func BenchmarkArrayStack(b *testing.B) { func BenchmarkLinkedListStack(b *testing.B) {
stack := NewArrayStack() stack := NewLinkedListStack()
// use b.N for looping // use b.N for looping
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
stack.Push(777) stack.Push(777)

Loading…
Cancel
Save