Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions heatmap_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package heatmap

import (
"bytes"
"fmt"
"hash/fnv"
"image"
"image/png"
"io"
"math"
"math/rand"
"testing"

"github.com/dustin/go-heatmap/schemes"

"github.com/jteeuwen/imghash"
)

var testPoints = []DataPoint{}
Expand Down Expand Up @@ -56,16 +58,34 @@ func TestHeatmapKMLLimits(t *testing.T) {
}
}

const expHash = uint64(62624876249118208)
const expHash = uint64(17499379771095836972)

func TestMkImage(t *testing.T) {
got := imghash.Average(Heatmap(image.Rect(0, 0, 1024, 1024),
testPoints, 150, 128, schemes.AlphaFire))
heatmap := Heatmap(image.Rect(0, 0, 1024, 1024),
testPoints, 150, 128, schemes.AlphaFire)

got := imgHash(heatmap)
if got != expHash {
t.Errorf("Expected hash = %v, got %v", expHash, got)
}
}

func imgHash(img image.Image) uint64 {
var buf bytes.Buffer
err := png.Encode(&buf, img)
if err != nil {
panic(fmt.Sprint("Failed to encode image:", err))
}

hash := fnv.New64()
_, err = hash.Write(buf.Bytes())
if err != nil {
panic(fmt.Sprint("Failed to generate hash:", err))
}

return hash.Sum64()
}

func TestMust(t *testing.T) {
must(nil) // no panic
panicked := false
Expand Down
5 changes: 2 additions & 3 deletions kml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

"github.com/dustin/go-heatmap/schemes"
"github.com/jteeuwen/imghash"
)

const testKmlImgURL = "http://www.example.com/thing.png"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestKML(t *testing.T) {
if err != nil {
t.Fatalf("Error generating kml: %v", err)
}
got := imghash.Average(img)
got := imgHash(img)
if got != expHash {
t.Errorf("Expected image hash %v, got %v", expHash, got)
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func TestKMZ(t *testing.T) {
if err != nil {
t.Errorf("Error decoding image: %v", err)
}
got := imghash.Average(img)
got := imgHash(img)
if got != expHash {
t.Errorf("Expected image hash %v, got %v", expHash, got)
}
Expand Down