blob: 35e12fdf786bc453ee018405fa1c452828f69221 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package queue
import (
"algorithms/ds"
"fmt"
"testing"
)
const minLength int = 1
const maxLength int = 1000
const factor int = 10
func TestElementaryPQ(t *testing.T) {
q := NewElementaryPQ(1)
for i := minLength; i <= maxLength; i *= factor {
test(q, i, t)
}
}
func test(q PQ, l int, t *testing.T) {
cb := func(t *testing.T) {
t.Parallel()
for _, a := range ds.NewRandomArrayList(l, -1) {
q.Insert(a)
}
prev, started := 0, false
for !q.Empty() {
next := q.DeleteMax()
if started {
if next < prev {
t.Errorf("Expected element '%v' to be lower than previous '%v': %v",
next, prev, q)
}
prev = next
continue
}
started = true
prev = next
}
}
t.Run(fmt.Sprintf("%d", l), cb)
}
|