Skip to content

Commit

Permalink
heap tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Sep 19, 2024
1 parent 0dc5a0f commit fb72e5d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions heap/heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"unsafe"

"github.com/keilerkonzept/topk/heap"
sketchheap "github.com/keilerkonzept/topk/heap"
"github.com/keilerkonzept/topk/internal/sizeof"
)

func TestMinHeap_LessSwap(t *testing.T) {
h := sketchheap.NewMin(5)
h := heap.NewMin(5)

h.Items = []sketchheap.Item{
h.Items = []heap.Item{
{Item: "a", Count: 5, Fingerprint: 1},
{Item: "b", Count: 2, Fingerprint: 2},
{Item: "c", Count: 3, Fingerprint: 3},
Expand All @@ -34,7 +33,7 @@ func TestMinHeap_LessSwap(t *testing.T) {
}

func TestMinHeap_Full(t *testing.T) {
h := sketchheap.NewMin(2)
h := heap.NewMin(2)

h.Update("a", 1, 2)
if h.Full() {
Expand All @@ -48,7 +47,7 @@ func TestMinHeap_Full(t *testing.T) {
}

func TestMinHeap_Update(t *testing.T) {
h := sketchheap.NewMin(2)
h := heap.NewMin(2)

// Insert new item
h.Update("a", 1, 10)
Expand Down Expand Up @@ -78,7 +77,7 @@ func TestMinHeap_Update(t *testing.T) {
}

func TestMinHeap_Min(t *testing.T) {
h := sketchheap.NewMin(2)
h := heap.NewMin(2)

// Empty heap
if h.Min() != 0 {
Expand All @@ -96,11 +95,11 @@ func TestMinHeap_Min(t *testing.T) {
}

func TestMinHeap_Reinit(t *testing.T) {
h := sketchheap.NewMin(3)
h := heap.NewMin(3)

h.Push(sketchheap.Item{Item: "a", Count: 0, Fingerprint: 1})
h.Push(sketchheap.Item{Item: "b", Count: 2, Fingerprint: 2})
h.Push(sketchheap.Item{Item: "c", Count: 3, Fingerprint: 3})
h.Push(heap.Item{Item: "a", Count: 0, Fingerprint: 1})
h.Push(heap.Item{Item: "b", Count: 2, Fingerprint: 2})
h.Push(heap.Item{Item: "c", Count: 3, Fingerprint: 3})

// Reinit should remove items with 0 count
h.Reinit()
Expand All @@ -113,7 +112,7 @@ func TestMinHeap_Reinit(t *testing.T) {
}

func TestMinHeap_Find(t *testing.T) {
h := sketchheap.NewMin(3)
h := heap.NewMin(3)
h.Update("a", 1, 10)

// Find existing item
Expand All @@ -130,7 +129,7 @@ func TestMinHeap_Find(t *testing.T) {
}

func TestMinHeap_Get(t *testing.T) {
h := sketchheap.NewMin(3)
h := heap.NewMin(3)
h.Update("a", 1, 10)

// Get existing item
Expand All @@ -150,8 +149,8 @@ func TestMinHeap_SizeBytes(t *testing.T) {
h := heap.NewMin(3)

const (
sizeofMinStruct = int(unsafe.Sizeof(sketchheap.Min{}))
sizeofItem = int(unsafe.Sizeof(sketchheap.Item{}))
sizeofMinStruct = int(unsafe.Sizeof(heap.Min{}))
sizeofItem = int(unsafe.Sizeof(heap.Item{}))
)

// Initial size should only account for the struct and empty containers
Expand Down

0 comments on commit fb72e5d

Please sign in to comment.