blob: 7678b1f4842b1f1c16f30e3174a648b51df1a791 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package verhoeff
import (
"testing"
"github.com/neonxp/checksum"
)
func TestVerhoeff(t *testing.T) {
samples := map[string]error{
"4561261212345464": checksum.ErrInvalidChecksum,
"A561261212345464": checksum.ErrInvalidNumber,
"758722": nil,
"123451": nil,
"1428570": nil,
"1234567890120": nil,
"84736430954837284567892": nil,
}
for num, result := range samples {
if err := Check(num); err != result {
t.Errorf("Expected %+v actual %+v", result, err)
}
}
num := "4561261212345467"
checksum, err := Generate(num)
if err != nil {
t.Error(err)
}
numberWithChecksum := num + checksum
if err := Check(numberWithChecksum); err != nil {
t.Errorf("Expected no error actual %+v", err)
}
}
|