Files
gf/container/gqueue/gqueue_unit_test.go

58 lines
1.1 KiB
Go
Raw Normal View History

2019-06-17 19:54:00 +08:00
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// go test *.go -bench=".*" -benchmem
2019-06-16 22:55:07 +08:00
package gqueue_test
import (
"testing"
2019-10-25 17:32:03 +08:00
"time"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/container/gqueue"
"github.com/gogf/gf/test/gtest"
2019-06-16 22:55:07 +08:00
)
func TestQueue_Len(t *testing.T) {
2019-06-17 19:54:00 +08:00
max := 100
for n := 10; n < max; n++ {
q1 := gqueue.New(max)
for i := 0; i < max; i++ {
2019-06-16 23:24:03 +08:00
q1.Push(i)
}
2019-06-17 19:54:00 +08:00
gtest.Assert(q1.Len(), max)
gtest.Assert(q1.Size(), max)
}
}
func TestQueue_Basic(t *testing.T) {
q := gqueue.New()
for i := 0; i < 100; i++ {
q.Push(i)
2019-06-16 22:55:07 +08:00
}
2019-06-17 19:54:00 +08:00
gtest.Assert(q.Pop(), 0)
gtest.Assert(q.Pop(), 1)
2019-06-16 22:55:07 +08:00
}
func TestQueue_Pop(t *testing.T) {
q1 := gqueue.New()
q1.Push(1)
q1.Push(2)
2019-06-17 11:31:03 +08:00
q1.Push(3)
q1.Push(4)
2019-06-16 22:55:07 +08:00
i1 := q1.Pop()
gtest.Assert(i1, 1)
}
func TestQueue_Close(t *testing.T) {
q1 := gqueue.New()
q1.Push(1)
q1.Push(2)
2019-10-25 17:32:03 +08:00
time.Sleep(time.Millisecond)
2019-06-16 22:55:07 +08:00
gtest.Assert(q1.Len(), 2)
q1.Close()
}