@@ -286,39 +286,60 @@ func TestKeyedPriorityQueue_Remove(t *testing.T) {
286286 t .Run ("Keys" , func (t * testing.T ) {
287287 testCases := []struct {
288288 key string
289+ wantStatus bool
289290 wantPeekKey string
290291 wantPeekValue int
291292 wantLen int
292293 }{
293294 {
294295 key : "first" ,
296+ wantStatus : true ,
295297 wantPeekKey : "second" ,
296298 wantPeekValue : 8 ,
297299 wantLen : 4 ,
298300 },
299301 {
300302 key : "third" ,
303+ wantStatus : true ,
301304 wantPeekKey : "second" ,
302305 wantPeekValue : 8 ,
303306 wantLen : 3 ,
304307 },
305308 {
306309 key : "second" ,
310+ wantStatus : true ,
307311 wantPeekKey : "fourth" ,
308312 wantPeekValue : 10 ,
309313 wantLen : 2 ,
310314 },
311315 {
312316 key : "last" ,
317+ wantStatus : true ,
313318 wantPeekKey : "fourth" ,
314319 wantPeekValue : 10 ,
315320 wantLen : 1 ,
316321 },
322+ {
323+ key : "nonexistent" ,
324+ wantStatus : false ,
325+ wantLen : 1 ,
326+ },
317327 }
318328
319329 for _ , tc := range testCases {
320330 t .Run (tc .key , func (t * testing.T ) {
321- pq .Remove (tc .key )
331+ gotStatus := pq .Remove (tc .key )
332+ if gotStatus != tc .wantStatus {
333+ t .Errorf ("pq.Remove(): got status %t; want %t" , gotStatus , tc .wantStatus )
334+ }
335+
336+ if got := pq .Len (); got != tc .wantLen {
337+ t .Errorf ("pq.Len(): got %d; want %d" , got , tc .wantLen )
338+ }
339+
340+ if ! gotStatus {
341+ return
342+ }
322343
323344 gotPeekKey , gotPeekValue , ok := pq .Peek ()
324345 if ! ok {
@@ -332,22 +353,9 @@ func TestKeyedPriorityQueue_Remove(t *testing.T) {
332353 if gotPeekValue != tc .wantPeekValue {
333354 t .Errorf ("pq.PeekValue(): got value %d; want %d" , gotPeekValue , tc .wantPeekValue )
334355 }
335-
336- if got := pq .Len (); got != tc .wantLen {
337- t .Errorf ("pq.Len(): got %d; want %d" , got , tc .wantLen )
338- }
339356 })
340357 }
341358 })
342-
343- t .Run ("NonExistingKey" , func (t * testing.T ) {
344- want := pq .Len ()
345- pq .Remove ("non-existing-key" )
346-
347- if got := pq .Len (); got != want {
348- t .Errorf ("pq.Len(): got %d; want %d" , got , want )
349- }
350- })
351359}
352360
353361func TestKeyedPriorityQueue_Peek_EmptyQueue (t * testing.T ) {
@@ -479,7 +487,6 @@ func TestKeyedPriorityQueue_Set(t *testing.T) {
479487 }
480488 })
481489 }
482-
483490}
484491
485492func benchmarkKeyedPriorityQueue_PushPop (b * testing.B , n int ) {
@@ -500,18 +507,23 @@ func benchmarkKeyedPriorityQueue_PushPop(b *testing.B, n int) {
500507func BenchmarkKeyedPriorityQueue_PushPop_10 (b * testing.B ) {
501508 benchmarkKeyedPriorityQueue_PushPop (b , 10 )
502509}
510+
503511func BenchmarkKeyedPriorityQueue_PushPop_100 (b * testing.B ) {
504512 benchmarkKeyedPriorityQueue_PushPop (b , 100 )
505513}
514+
506515func BenchmarkKeyedPriorityQueue_PushPop_1000 (b * testing.B ) {
507516 benchmarkKeyedPriorityQueue_PushPop (b , 1000 )
508517}
518+
509519func BenchmarkKeyedPriorityQueue_PushPop_10000 (b * testing.B ) {
510520 benchmarkKeyedPriorityQueue_PushPop (b , 10000 )
511521}
522+
512523func BenchmarkKeyedPriorityQueue_PushPop_100000 (b * testing.B ) {
513524 benchmarkKeyedPriorityQueue_PushPop (b , 100000 )
514525}
526+
515527func BenchmarkKeyedPriorityQueue_PushPop_1000000 (b * testing.B ) {
516528 benchmarkKeyedPriorityQueue_PushPop (b , 1000000 )
517529}
0 commit comments