github.com/tumi8/quic-go@v0.37.4-tum/noninternal/utils/ringbuffer/ringbuffer_test.go (about) 1 package ringbuffer 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 ) 7 8 var _ = Describe("RingBuffer", func() { 9 It("push and pop", func() { 10 r := RingBuffer[int]{} 11 Expect(len(r.ring)).To(Equal(0)) 12 Expect(func() { r.PopFront() }).To(Panic()) 13 r.PushBack(1) 14 r.PushBack(2) 15 r.PushBack(3) 16 Expect(r.PopFront()).To(Equal(1)) 17 Expect(r.PopFront()).To(Equal(2)) 18 r.PushBack(4) 19 r.PushBack(5) 20 Expect(r.Len()).To(Equal(3)) 21 r.PushBack(6) 22 Expect(r.Len()).To(Equal(4)) 23 Expect(r.PopFront()).To(Equal(3)) 24 Expect(r.PopFront()).To(Equal(4)) 25 Expect(r.PopFront()).To(Equal(5)) 26 Expect(r.PopFront()).To(Equal(6)) 27 }) 28 It("clear", func() { 29 r := RingBuffer[int]{} 30 r.Init(2) 31 r.PushBack(1) 32 r.PushBack(2) 33 Expect(r.full).To(BeTrue()) 34 r.Clear() 35 Expect(r.full).To(BeFalse()) 36 Expect(r.Len()).To(Equal(0)) 37 }) 38 })