72 lines
1.0 KiB
Go
72 lines
1.0 KiB
Go
package pqueue
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Pallinder/go-randomdata"
|
|
|
|
"474420502.top/eson/structure/compare"
|
|
)
|
|
|
|
func TestPush(t *testing.T) {
|
|
pq := New(compare.Int)
|
|
for i := 0; i < 10; i++ {
|
|
v := randomdata.Number(0, 100)
|
|
pq.Push(v)
|
|
t.Error(v)
|
|
}
|
|
t.Error(pq.Pop())
|
|
t.Error(pq.Pop())
|
|
t.Error(pq.Pop())
|
|
t.Error(pq.Pop())
|
|
t.Error(pq.Pop())
|
|
}
|
|
|
|
func TestPop(t *testing.T) {
|
|
pq := New(compare.Int)
|
|
for i := 0; i < 10; i++ {
|
|
v := randomdata.Number(0, 100)
|
|
pq.Push(v)
|
|
t.Error(v)
|
|
}
|
|
|
|
for i := 0; i < 10; i++ {
|
|
t.Error(pq.Pop())
|
|
}
|
|
}
|
|
|
|
func BenchmarkPriorityPush(b *testing.B) {
|
|
|
|
l := loadTestData()
|
|
execCount := 5
|
|
b.N = len(l) * execCount
|
|
|
|
b.ResetTimer()
|
|
b.StartTimer()
|
|
|
|
for i := 0; i < execCount; i++ {
|
|
pq := New(compare.Int)
|
|
for _, v := range l {
|
|
pq.Push(v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkPriorityPop(b *testing.B) {
|
|
|
|
l := loadTestData()
|
|
|
|
pq := New(compare.Int)
|
|
for _, v := range l {
|
|
pq.Push(v)
|
|
}
|
|
|
|
b.N = len(l) / 1000
|
|
b.ResetTimer()
|
|
b.StartTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
pq.Pop()
|
|
}
|
|
}
|