github.com/chain5j/chain5j-pkg@v1.0.7/collection/queues/queue/queue_test.go (about)

     1  // Package queue
     2  //
     3  // @author: xwc1125
     4  package queue
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/davecgh/go-spew/spew"
    10  )
    11  
    12  type item struct {
    13  	nonce int64
    14  	value interface{}
    15  }
    16  
    17  func TestNew(t *testing.T) {
    18  	linkedQueue := NewLinkedQueue()
    19  
    20  	for i := int64(0); i < 5; i++ {
    21  		linkedQueue.PushFront(Element(item{
    22  			i,
    23  			i,
    24  		}))
    25  	}
    26  	for i := 0; i < 2; i++ {
    27  		spew.Dump(linkedQueue.PeekFront())
    28  		spew.Dump(linkedQueue.PeekBack())
    29  		linkedQueue.PollFront()
    30  	}
    31  	spew.Dump(linkedQueue.PeekFront())
    32  	spew.Dump(linkedQueue.PeekBack())
    33  	linkedQueue.PollBack()
    34  	for i := 0; i < 2; i++ {
    35  		spew.Dump(linkedQueue.PeekFront())
    36  		spew.Dump(linkedQueue.PeekBack())
    37  		linkedQueue.PollFront()
    38  	}
    39  	spew.Dump(linkedQueue.PeekFront())
    40  	spew.Dump(linkedQueue.PeekBack())
    41  	linkedQueue.PollBack()
    42  	spew.Dump(linkedQueue.PeekFront())
    43  	spew.Dump(linkedQueue.PeekBack())
    44  	linkedQueue.PushBack(Element(item{
    45  		8,
    46  		8,
    47  	}))
    48  	spew.Dump(linkedQueue.PeekFront())
    49  	spew.Dump(linkedQueue.PeekBack())
    50  	linkedQueue.PushBack(Element(item{
    51  		9,
    52  		9,
    53  	}))
    54  	spew.Dump(linkedQueue.PeekFront())
    55  	spew.Dump(linkedQueue.PeekBack())
    56  	linkedQueue.PollBack()
    57  	spew.Dump(linkedQueue.PeekFront())
    58  	spew.Dump(linkedQueue.PeekBack())
    59  	linkedQueue.PollBack()
    60  	spew.Dump(linkedQueue.PeekFront())
    61  	spew.Dump(linkedQueue.PeekBack())
    62  
    63  	linkedQueue.Clear()
    64  
    65  	spew.Dump(linkedQueue.PeekFront())
    66  }
    67  
    68  func TestDel(t *testing.T) {
    69  	queue := NewLinkedQueue()
    70  	queue.PushFront("1")
    71  	queue.Remove("1")
    72  
    73  	queue.PushBack("2")
    74  	queue.Remove("2")
    75  
    76  	queue.PushFront("3")
    77  	queue.PollFront()
    78  	queue.Remove("3")
    79  
    80  	queue.PushFront("1")
    81  	queue.PushBack("2")
    82  	queue.PushFront("3")
    83  	queue.PollFront()
    84  	queue.PollBack()
    85  	// queue.Remove("1")
    86  	queue.Remove("3")
    87  	queue.Remove("2")
    88  
    89  	queue.Clear()
    90  }