gonads/queue_test.go

35 lines
481 B
Go
Raw Normal View History

package gonads
import (
"context"
"testing"
"time"
)
func TestQueue(t *testing.T) {
q := NewQueue[int](5)
for i := range make([]struct{}, 5) {
q.Push(i)
}
for range make([]struct{}, 5) {
t.Log(q.Pop())
}
defer func() {
if r := recover(); r != nil {
if sr, ok := r.(string); ok {
t.Log(sr)
return
}
panic(r)
}
} ()
ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond)
q.Push(1)
t.Log(q.TryPop(ctx))
q.TryPop(ctx)
}