diff options
Diffstat (limited to 'queue/pq_test.go')
| -rw-r--r-- | queue/pq_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/queue/pq_test.go b/queue/pq_test.go new file mode 100644 index 0000000..35e12fd --- /dev/null +++ b/queue/pq_test.go @@ -0,0 +1,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) +} |
