2017-11-25 00:45:26 +00:00
|
|
|
package libnmdc
|
|
|
|
|
|
|
|
import (
|
2017-11-25 01:22:38 +00:00
|
|
|
"strings"
|
2017-11-25 00:45:26 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTTH(t *testing.T) {
|
|
|
|
|
|
|
|
// echo -n 'hello world' | tthsum
|
|
|
|
testCases := [][2]string{
|
|
|
|
[2]string{"hello world", "ZIIVRZDR2FD3W4KKNMNYUU3765LPPK7BWY64CHI"},
|
|
|
|
[2]string{"", "LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ"},
|
2017-11-25 01:22:38 +00:00
|
|
|
[2]string{"\x00", "VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA"},
|
|
|
|
[2]string{strings.Repeat("A", 1024), "L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA"},
|
|
|
|
}
|
|
|
|
|
|
|
|
short := func(s string) string {
|
|
|
|
if len(s) > 15 {
|
|
|
|
return s[0:15] + "..."
|
|
|
|
}
|
|
|
|
return s
|
2017-11-25 00:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
input, expected := testCase[0], testCase[1]
|
2017-11-25 01:25:17 +00:00
|
|
|
result, err := TTH(input)
|
2017-11-25 00:45:26 +00:00
|
|
|
if err != nil {
|
2017-11-25 01:22:38 +00:00
|
|
|
t.Fatalf("Error getting TTH for '%s': %s", short(input), err.Error())
|
2017-11-25 00:45:26 +00:00
|
|
|
}
|
2017-11-26 00:29:32 +00:00
|
|
|
|
|
|
|
if Base32(result) != expected {
|
2017-11-25 01:22:38 +00:00
|
|
|
t.Fatalf("Wrong TTH for '%s' (got '%s' expected '%s')", short(input), result, expected)
|
2017-11-25 00:45:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|