github.com/zhongdalu/gf@v1.0.0/g/container/gqueue/gqueue_unit_test.go (about)

     1  // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  // go test *.go -bench=".*" -benchmem
     8  
     9  package gqueue_test
    10  
    11  import (
    12  	"github.com/zhongdalu/gf/g/container/gqueue"
    13  	"github.com/zhongdalu/gf/g/test/gtest"
    14  	"testing"
    15  )
    16  
    17  func TestQueue_Len(t *testing.T) {
    18  	max := 100
    19  	for n := 10; n < max; n++ {
    20  		q1 := gqueue.New(max)
    21  		for i := 0; i < max; i++ {
    22  			q1.Push(i)
    23  		}
    24  		gtest.Assert(q1.Len(), max)
    25  		gtest.Assert(q1.Size(), max)
    26  	}
    27  }
    28  
    29  func TestQueue_Basic(t *testing.T) {
    30  	q := gqueue.New()
    31  	for i := 0; i < 100; i++ {
    32  		q.Push(i)
    33  	}
    34  	gtest.Assert(q.Pop(), 0)
    35  	gtest.Assert(q.Pop(), 1)
    36  }
    37  
    38  func TestQueue_Pop(t *testing.T) {
    39  	q1 := gqueue.New()
    40  	q1.Push(1)
    41  	q1.Push(2)
    42  	q1.Push(3)
    43  	q1.Push(4)
    44  	i1 := q1.Pop()
    45  	gtest.Assert(i1, 1)
    46  }
    47  
    48  func TestQueue_Close(t *testing.T) {
    49  	q1 := gqueue.New()
    50  	q1.Push(1)
    51  	q1.Push(2)
    52  	gtest.Assert(q1.Len(), 2)
    53  	q1.Close()
    54  }