diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-30 01:43:12 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2019-08-30 01:43:12 +0300 |
commit | 878cb24695b7d39fa9de65a1e164abc84dc67ead (patch) | |
tree | 73946dd08310c2a3b7535297906a4ff5535db756 /damm/damm_test.go | |
parent | b0fba45d68c9ec6c2274ebd61b28ca22bb5deff6 (diff) |
Added Damm algorithm
Diffstat (limited to 'damm/damm_test.go')
-rw-r--r-- | damm/damm_test.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/damm/damm_test.go b/damm/damm_test.go new file mode 100644 index 0000000..1f338b8 --- /dev/null +++ b/damm/damm_test.go @@ -0,0 +1,32 @@ +package damm + +import ( + "log" + "testing" + + "github.com/neonxp/checksum" +) + +func TestLuhn(t *testing.T) { + samples := map[string]error{ + "456126121234546": checksum.ErrInvalidChecksum, + "A56126121234546": checksum.ErrInvalidNumber, + "5724": nil, + } + for num, result := range samples { + if err := Check(num); err != result { + t.Errorf("Expected %+v actual %+v for %s", result, err, num) + } + } + + num := "572" + checksum, err := Generate(num) + if err != nil { + t.Error(err) + } + numberWithChecksum := num + checksum + log.Println(numberWithChecksum) + if err := Check(numberWithChecksum); err != nil { + t.Errorf("Expected no error actual %+v for %s", err, numberWithChecksum) + } +} |