MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / testFunc

Function testFunc

structure/heap/heap_test.go:115–150  ·  view source on GitHub ↗
(t *testing.T, tests []testStruct[T], less func(a, b T) bool)

Source from the content-addressed store, hash-verified

113}
114
115func testFunc[T any](t *testing.T, tests []testStruct[T], less func(a, b T) bool) {
116 for _, tt := range tests {
117 t.Run(tt.name, func(t *testing.T) {
118 h, err := heap.NewAny[T](less)
119 if err != nil {
120 t.Errorf("New Heap err %v", err)
121 }
122 for i, op := range tt.ops {
123 switch op.typ {
124 case testPush:
125 oldSize := h.Size()
126 h.Push(op.x)
127 newSize := h.Size()
128 if oldSize+1 != newSize {
129 t.Errorf("op %d testPush %v failed", i, op.x)
130 }
131 case testPop:
132 oldSize := h.Size()
133 h.Pop()
134 newSize := h.Size()
135 if oldSize-1 != newSize {
136 t.Errorf("op %d testPop %v failed", i, op.x)
137 }
138 case testTop:
139 if got := h.Top(); !reflect.DeepEqual(got, op.x) {
140 t.Errorf("op %d testTop %v, want %v", i, got, op.x)
141 }
142 case testEmpty:
143 if got := h.Empty(); got != op.isEmpty {
144 t.Errorf("op %d Empty() = %v, want %v", i, got, op.isEmpty)
145 }
146 }
147 }
148 })
149 }
150}

Callers 2

TestHeapExample1Function · 0.85
TestHeapExample2Function · 0.85

Calls 5

TopMethod · 0.80
PushMethod · 0.65
EmptyMethod · 0.65
SizeMethod · 0.45
PopMethod · 0.45

Tested by

no test coverage detected