MCPcopy
hub / github.com/expr-lang/expr / testRingOp

Function testRingOp

internal/ring/ring_test.go:96–140  ·  view source on GitHub ↗
(t *testing.T, r *Ring[T], op ringOp[T])

Source from the content-addressed store, hash-verified

94}
95
96func testRingOp[T comparable](t *testing.T, r *Ring[T], op ringOp[T]) {
97 var zero T
98 switch op.opType {
99 case opEnq:
100 r.Enqueue(op.value)
101 case opDeq:
102 shouldSucceed := r.Len() > 0
103 v, ok := r.Dequeue()
104 switch {
105 case ok != shouldSucceed:
106 t.Fatalf("should have succeeded: %v", shouldSucceed)
107 case ok && v != op.value:
108 t.Fatalf("expected value: %v; got: %v", op.value, v)
109 case !ok && v != zero:
110 t.Fatalf("expected zero value; got: %v", v)
111 }
112 case opRst:
113 r.Reset()
114 }
115 if c := r.Cap(); c != op.cap {
116 t.Fatalf("expected cap: %v; got: %v", op.cap, c)
117 }
118 if l := r.Len(); l != len(op.items) {
119 t.Errorf("expected Len(): %v; got: %v", len(op.items), l)
120 }
121 var got []T
122 for i := 0; ; i++ {
123 v, ok := r.Nth(i)
124 if !ok {
125 break
126 }
127 got = append(got, v)
128 }
129 if l := len(got); l != len(op.items) {
130 t.Errorf("expected items: %v\ngot items: %v", op.items, got)
131 }
132 for i := range op.items {
133 if op.items[i] != got[i] {
134 t.Fatalf("expected items: %v\ngot items: %v", op.items, got)
135 }
136 }
137 if v, ok := r.Nth(len(op.items)); ok || v != zero {
138 t.Fatalf("expected no more items, got: v=%v; ok=%v", v, ok)
139 }
140}

Callers 1

testRingFunction · 0.85

Calls 7

EnqueueMethod · 0.80
DequeueMethod · 0.80
CapMethod · 0.80
NthMethod · 0.80
ErrorfMethod · 0.65
LenMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…