(t *testing.T, tests []testStruct[T], less func(a, b T) bool)
| 113 | } |
| 114 | |
| 115 | func 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 | } |
no test coverage detected