@@ -51,14 +51,19 @@ func TestCorrectnessOfPop(t *testing.T) {
51
51
q .Push (& e )
52
52
}
53
53
var priorities []int
54
+ var peekPriorities []int
54
55
for q .Len () > 0 {
55
56
i := q .Pop ().(* TestElem ).Priority
56
57
t .Logf ("popped %v" , i )
57
58
priorities = append (priorities , i )
59
+ peekPriorities = append (peekPriorities , i )
58
60
}
59
- if ! sort .IntsAreSorted (priorities ) {
61
+ if ! sort .IntsAreSorted (peekPriorities ) {
60
62
t .Fatal ("the values were not returned in sorted order" )
61
63
}
64
+ if ! sort .IntsAreSorted (priorities ) {
65
+ t .Fatal ("the popped values were not returned in sorted order" )
66
+ }
62
67
}
63
68
64
69
func TestUpdate (t * testing.T ) {
@@ -73,12 +78,18 @@ func TestUpdate(t *testing.T) {
73
78
q .Push (middle )
74
79
q .Push (highest )
75
80
q .Push (lowest )
81
+ if q .Peek ().(* TestElem ).Key != highest .Key {
82
+ t .Fatal ("head element doesn't have the highest priority" )
83
+ }
76
84
if q .Pop ().(* TestElem ).Key != highest .Key {
77
85
t .Fatal ("popped element doesn't have the highest priority" )
78
86
}
79
87
q .Push (highest ) // re-add the popped element
80
88
highest .Priority = 0 // update the PQ
81
89
q .Update (highest .Index ()) // fix the PQ
90
+ if q .Peek ().(* TestElem ).Key != middle .Key {
91
+ t .Fatal ("middle element should now have the highest priority" )
92
+ }
82
93
if q .Pop ().(* TestElem ).Key != middle .Key {
83
94
t .Fatal ("middle element should now have the highest priority" )
84
95
}
0 commit comments