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