diff options
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) + } +} |