2017-09-20 19:34:32 +00:00
|
|
|
// Copyright (C) 2014 The Protocol Authors.
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2020-03-29 20:28:04 +00:00
|
|
|
"strings"
|
2017-09-20 19:34:32 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-03-29 20:28:04 +00:00
|
|
|
func TestLuhn32(t *testing.T) {
|
|
|
|
c, err := luhn32("AB725E4GHIQPL3ZFGT")
|
2017-09-20 19:34:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-03-29 20:28:04 +00:00
|
|
|
if c != 'G' {
|
|
|
|
t.Errorf("Incorrect check digit %c != G", c)
|
2017-09-20 19:34:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 20:28:04 +00:00
|
|
|
_, err = luhn32("3734EJEKMRHWPZQTWYQ1")
|
2017-09-20 19:34:32 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Error("Unexpected nil error")
|
|
|
|
}
|
2020-03-29 20:28:04 +00:00
|
|
|
if !strings.Contains(err.Error(), "'1'") {
|
|
|
|
t.Errorf("luhn32 should have errored on digit '1', got %v", err)
|
2017-09-20 19:34:32 +00:00
|
|
|
}
|
|
|
|
}
|