@@ -286,39 +286,60 @@ func TestKeyedPriorityQueue_Remove(t *testing.T) {
286
286
t .Run ("Keys" , func (t * testing.T ) {
287
287
testCases := []struct {
288
288
key string
289
+ wantStatus bool
289
290
wantPeekKey string
290
291
wantPeekValue int
291
292
wantLen int
292
293
}{
293
294
{
294
295
key : "first" ,
296
+ wantStatus : true ,
295
297
wantPeekKey : "second" ,
296
298
wantPeekValue : 8 ,
297
299
wantLen : 4 ,
298
300
},
299
301
{
300
302
key : "third" ,
303
+ wantStatus : true ,
301
304
wantPeekKey : "second" ,
302
305
wantPeekValue : 8 ,
303
306
wantLen : 3 ,
304
307
},
305
308
{
306
309
key : "second" ,
310
+ wantStatus : true ,
307
311
wantPeekKey : "fourth" ,
308
312
wantPeekValue : 10 ,
309
313
wantLen : 2 ,
310
314
},
311
315
{
312
316
key : "last" ,
317
+ wantStatus : true ,
313
318
wantPeekKey : "fourth" ,
314
319
wantPeekValue : 10 ,
315
320
wantLen : 1 ,
316
321
},
322
+ {
323
+ key : "nonexistent" ,
324
+ wantStatus : false ,
325
+ wantLen : 1 ,
326
+ },
317
327
}
318
328
319
329
for _ , tc := range testCases {
320
330
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
+ }
322
343
323
344
gotPeekKey , gotPeekValue , ok := pq .Peek ()
324
345
if ! ok {
@@ -332,22 +353,9 @@ func TestKeyedPriorityQueue_Remove(t *testing.T) {
332
353
if gotPeekValue != tc .wantPeekValue {
333
354
t .Errorf ("pq.PeekValue(): got value %d; want %d" , gotPeekValue , tc .wantPeekValue )
334
355
}
335
-
336
- if got := pq .Len (); got != tc .wantLen {
337
- t .Errorf ("pq.Len(): got %d; want %d" , got , tc .wantLen )
338
- }
339
356
})
340
357
}
341
358
})
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
- })
351
359
}
352
360
353
361
func TestKeyedPriorityQueue_Peek_EmptyQueue (t * testing.T ) {
@@ -479,7 +487,6 @@ func TestKeyedPriorityQueue_Set(t *testing.T) {
479
487
}
480
488
})
481
489
}
482
-
483
490
}
484
491
485
492
func benchmarkKeyedPriorityQueue_PushPop (b * testing.B , n int ) {
@@ -500,18 +507,23 @@ func benchmarkKeyedPriorityQueue_PushPop(b *testing.B, n int) {
500
507
func BenchmarkKeyedPriorityQueue_PushPop_10 (b * testing.B ) {
501
508
benchmarkKeyedPriorityQueue_PushPop (b , 10 )
502
509
}
510
+
503
511
func BenchmarkKeyedPriorityQueue_PushPop_100 (b * testing.B ) {
504
512
benchmarkKeyedPriorityQueue_PushPop (b , 100 )
505
513
}
514
+
506
515
func BenchmarkKeyedPriorityQueue_PushPop_1000 (b * testing.B ) {
507
516
benchmarkKeyedPriorityQueue_PushPop (b , 1000 )
508
517
}
518
+
509
519
func BenchmarkKeyedPriorityQueue_PushPop_10000 (b * testing.B ) {
510
520
benchmarkKeyedPriorityQueue_PushPop (b , 10000 )
511
521
}
522
+
512
523
func BenchmarkKeyedPriorityQueue_PushPop_100000 (b * testing.B ) {
513
524
benchmarkKeyedPriorityQueue_PushPop (b , 100000 )
514
525
}
526
+
515
527
func BenchmarkKeyedPriorityQueue_PushPop_1000000 (b * testing.B ) {
516
528
benchmarkKeyedPriorityQueue_PushPop (b , 1000000 )
517
529
}
0 commit comments