github.com/gogf/gf@v1.16.9/container/gqueue/gqueue_z_unit_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). 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/gogf/gf.
     6  
     7  // go test *.go -bench=".*" -benchmem
     8  
     9  package gqueue_test
    10  
    11  import (
    12  	"testing"
    13  	"time"
    14  
    15  	"github.com/gogf/gf/container/gqueue"
    16  	"github.com/gogf/gf/test/gtest"
    17  )
    18  
    19  func TestQueue_Len(t *testing.T) {
    20  	gtest.C(t, func(t *gtest.T) {
    21  		max := 100
    22  		for n := 10; n < max; n++ {
    23  			q1 := gqueue.New(max)
    24  			for i := 0; i < max; i++ {
    25  				q1.Push(i)
    26  			}
    27  			t.Assert(q1.Len(), max)
    28  			t.Assert(q1.Size(), max)
    29  		}
    30  	})
    31  }
    32  
    33  func TestQueue_Basic(t *testing.T) {
    34  	gtest.C(t, func(t *gtest.T) {
    35  		q := gqueue.New()
    36  		for i := 0; i < 100; i++ {
    37  			q.Push(i)
    38  		}
    39  		t.Assert(q.Pop(), 0)
    40  		t.Assert(q.Pop(), 1)
    41  	})
    42  }
    43  
    44  func TestQueue_Pop(t *testing.T) {
    45  	gtest.C(t, func(t *gtest.T) {
    46  		q1 := gqueue.New()
    47  		q1.Push(1)
    48  		q1.Push(2)
    49  		q1.Push(3)
    50  		q1.Push(4)
    51  		i1 := q1.Pop()
    52  		t.Assert(i1, 1)
    53  	})
    54  }
    55  
    56  func TestQueue_Close(t *testing.T) {
    57  	gtest.C(t, func(t *gtest.T) {
    58  		q1 := gqueue.New()
    59  		q1.Push(1)
    60  		q1.Push(2)
    61  		time.Sleep(time.Millisecond)
    62  		t.Assert(q1.Len(), 2)
    63  		q1.Close()
    64  	})
    65  }