2019-11-21 16:19:22 +00:00
|
|
|
package identicon
|
|
|
|
|
|
|
|
import (
|
2020-02-10 11:22:37 +00:00
|
|
|
"crypto/md5" // nolint: gosec
|
2019-11-21 16:19:22 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
var GeneratedPattern = []byte{
|
|
|
|
129, 201, 130, 201, 129,
|
|
|
|
56, 157, 244, 157, 56,
|
|
|
|
232, 187, 241, 187, 232,
|
|
|
|
183, 61, 165, 61, 183,
|
|
|
|
149, 108, 179, 108, 149,
|
|
|
|
}
|
|
|
|
|
|
|
|
var GeneratedBitmap = []byte{
|
|
|
|
0, 0, 1, 0, 0,
|
|
|
|
1, 0, 1, 0, 1,
|
|
|
|
1, 0, 0, 0, 1,
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
0, 1, 0, 1, 0,
|
|
|
|
}
|
|
|
|
|
2020-02-10 11:22:37 +00:00
|
|
|
var GeneratedHash = md5.Sum([]byte("Culona")) // nolint: gosec
|
2019-11-21 16:19:22 +00:00
|
|
|
|
|
|
|
func TestItGeneratesAPatternFromAListOfBytes(t *testing.T) {
|
|
|
|
pattern := generatePatternFromHash(GeneratedHash)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(GeneratedPattern, pattern) {
|
|
|
|
t.Fatal("Failing asserting equality of pattern.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestItGeneratesABitMapFromPattern(t *testing.T) {
|
|
|
|
bitmap := convertPatternToBinarySwitch(GeneratedPattern)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(GeneratedBitmap, bitmap) {
|
|
|
|
t.Fatal("Failing asserting equality of bitmap.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestItGeneratesAnIdenticonFromString(t *testing.T) {
|
|
|
|
identicon := generate("Culona")
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(GeneratedBitmap, identicon.bitmap) {
|
|
|
|
t.Fatal("Failing asserting that the identicon has a valid bitmap.")
|
|
|
|
}
|
|
|
|
}
|