photoprism/pkg/checksum/charset_test.go
Michael Mayer 01da5bdec7 CRC32: Move checksum generation to a dedicated package
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-20 14:56:07 +01:00

93 lines
1.9 KiB
Go

package checksum
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestChar(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
data := ""
expected := "a"
result := string(Char([]byte(data)))
t.Logf("Char(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
t.Run("One", func(t *testing.T) {
data := "1"
expected := "R"
result := string(Char([]byte(data)))
t.Logf("Char(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
t.Run("Serial", func(t *testing.T) {
data := "zr2g80wvjmm1zwzg"
expected := "G"
result := string(Char([]byte(data)))
t.Logf("Char(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
t.Run("HelloWorld", func(t *testing.T) {
data := "Hello World!"
expected := "X"
result := string(Char([]byte(data)))
t.Logf("Char(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
}
func TestBase36(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
data := ""
expected := "a"
result := string(Base36([]byte(data)))
t.Logf("Base36(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
t.Run("One", func(t *testing.T) {
data := "1"
expected := "l"
result := string(Base36([]byte(data)))
t.Logf("Base36(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
t.Run("Serial", func(t *testing.T) {
data := "zr2g80wvjmm1zwzg"
expected := "u"
result := string(Base36([]byte(data)))
t.Logf("Base36(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
t.Run("HelloWorld", func(t *testing.T) {
data := "Hello World!"
expected := "x"
result := string(Base36([]byte(data)))
t.Logf("Base36(%s): result %s, expected %s", data, result, expected)
assert.Equal(t, expected, result)
})
}