45 lines
902 B
Go
45 lines
902 B
Go
package queue
|
|
|
|
import "testing"
|
|
|
|
func TestCreateAndLength(t *testing.T) {
|
|
q := &QueueNode{}
|
|
q.Create(1, 2, 3)
|
|
if got := q.Length(); got != 3 {
|
|
t.Errorf("Length = %d, want 3", got)
|
|
}
|
|
}
|
|
|
|
func TestPush(t *testing.T) {
|
|
q := &QueueNode{}
|
|
q.Create("a")
|
|
q.Push("b")
|
|
if got := q.Length(); got != 2 {
|
|
t.Errorf("Push 后 Length = %d, want 2", got)
|
|
}
|
|
}
|
|
|
|
func TestPop(t *testing.T) {
|
|
q := &QueueNode{}
|
|
q.Create(1, 2, 3)
|
|
// Pop 在头结点(哨兵)上调用,跳过第一个元素并返回头结点 Data
|
|
q.Pop()
|
|
if got := q.Length(); got != 2 {
|
|
t.Errorf("Pop 后 Length = %d, want 2", got)
|
|
}
|
|
}
|
|
|
|
func TestCreateEmpty(t *testing.T) {
|
|
q := &QueueNode{}
|
|
q.Create() // 无元素,不应 panic
|
|
if got := q.Length(); got != 0 {
|
|
t.Errorf("空 Create 后 Length = %d, want 0", got)
|
|
}
|
|
}
|
|
|
|
func TestPrint(t *testing.T) {
|
|
q := &QueueNode{}
|
|
q.Create(1, 2, 3)
|
|
q.Print() // 仅验证不 panic
|
|
}
|