syncthing/luhn/luhn_test.go

34 lines
640 B
Go
Raw Normal View History

package luhn_test
import (
"testing"
"github.com/calmh/syncthing/luhn"
)
func TestGenerate(t *testing.T) {
2014-07-04 13:56:33 +00:00
// Base 6 Luhn
a := luhn.Alphabet("abcdef")
c := a.Generate("abcdef")
if c != 'e' {
t.Errorf("Incorrect check digit %c != e", c)
}
2014-07-04 13:56:33 +00:00
// Base 10 Luhn
a = luhn.Alphabet("0123456789")
c = a.Generate("7992739871")
if c != '3' {
t.Errorf("Incorrect check digit %c != 3", c)
}
}
func TestValidate(t *testing.T) {
a := luhn.Alphabet("abcdef")
if !a.Validate("abcdefe") {
t.Errorf("Incorrect validation response for abcdefe")
}
if a.Validate("abcdefd") {
t.Errorf("Incorrect validation response for abcdefd")
}
}