From 1dd43e378c55b6984bda6c2e8b048d2ed821aa43 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Mon, 5 Jul 2021 11:52:03 +0300 Subject: - Finish binary_heap Signed-off-by: Valery Piashchynski --- pkg/priority_queue/binary_heap_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'pkg/priority_queue/binary_heap_test.go') diff --git a/pkg/priority_queue/binary_heap_test.go b/pkg/priority_queue/binary_heap_test.go index a2b0e7e8..1b510be3 100644 --- a/pkg/priority_queue/binary_heap_test.go +++ b/pkg/priority_queue/binary_heap_test.go @@ -29,6 +29,27 @@ func TestBinHeap_Init(t *testing.T) { require.Equal(t, expected, a) } +func TestBinHeap_Init2(t *testing.T) { + a := []PQItem{Test(2), Test(23), Test(33), Test(44), Test(1), Test(2), Test(2), Test(2), Test(4), Test(6), Test(99)} + + bh := NewBinHeap() + + for i := 0; i < len(a); i++ { + bh.Insert(a[i]) + } + + expected := []PQItem{Test(1), Test(2), Test(2), Test(2), Test(2), Test(4), Test(6), Test(23), Test(33), Test(44), Test(99)} + + res := make([]PQItem, 0, 12) + + for i := 0; i < 11; i++ { + item := bh.GetMax() + res = append(res, item) + } + + require.Equal(t, expected, res) +} + func BenchmarkBinHeap_Init(b *testing.B) { a := []PQItem{Test(2), Test(23), Test(33), Test(44), Test(1), Test(2), Test(2), Test(2), Test(4), Test(6), Test(99)} bh := NewBinHeap() -- cgit v1.2.3