Skip to content

Commit

Permalink
Add test that findById is consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
travierm committed Apr 22, 2024
1 parent 05a421a commit c27c1f8
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ func TestHeap(t *testing.T) {
ClearTestFolder()
}

func TestFindByIdLargeDataset(t *testing.T) {
heap := NewHeap[TestRecord]("products", "storage/test")
for i := 0; i < 1000; i++ {
_ = heap.Insert(&Record[TestRecord]{ID: uint64(i), Data: TestRecord{Name: fmt.Sprintf("Product %d", i), Amount: 100.0}})
}

for i := 0; i < 4; i++ {
randomNum := rand.Uint64() % 1001
record, _ := heap.FindByID(randomNum)
assert.Equal(t, fmt.Sprintf("Product %d", randomNum), record.Data.Name)
}

ClearTestFolder()
}

func BenchmarkFindById(b *testing.B) {
// create 100 records
heap := NewHeap[TestRecord]("products", "storage/test")
Expand Down

0 comments on commit c27c1f8

Please sign in to comment.