1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2024-11-27 18:45:40 +00:00
imgsrv/hash/hash_test.go

52 lines
1.2 KiB
Go
Raw Normal View History

2013-05-09 13:47:24 +00:00
package hash
import (
2013-03-27 20:30:24 +00:00
"fmt"
"testing"
"sort"
)
func TestRand64(t *testing.T) {
2013-03-27 20:30:24 +00:00
var i interface{}
i = Rand64()
v, ok := i.(int64)
if !ok {
t.Errorf("Rand64 returned wrong type")
}
if v < 0 {
t.Errorf("Rand64 returned a too small number [%d]", v)
}
}
func TestMd5Bytes(t *testing.T) {
2013-03-27 20:30:24 +00:00
var blob = []byte("Hurp til you Derp")
var expected = "3ef08fa896a154eee3c97f037c9d6dfc"
var actual = fmt.Sprintf("%x", GetMd5FromBytes(blob))
if actual != expected {
t.Errorf("Md5FromBytes sum did not match! %s != %s", actual, expected)
}
}
func TestMd5String(t *testing.T) {
2013-03-27 20:30:24 +00:00
var blob = "Hurp til you Derp"
var expected = "3ef08fa896a154eee3c97f037c9d6dfc"
var actual = fmt.Sprintf("%x", GetMd5FromString(blob))
if actual != expected {
t.Errorf("Md5FromString sum did not match! %s != %s", actual, expected)
}
}
func TestHash(t *testing.T) {
seen := []string{}
for i := 0; i < 10000; i++ {
h := GetSmallHash()
j := sort.SearchStrings(seen, h)
if len(seen) != 0 && j < len(seen) && h == seen[j] {
t.Errorf("there is a non-unique hash after %d attempts [%s and %s]", i, h, seen[j])
} else {
seen = append(seen, h)
sort.Strings(seen)
}
}
}