aboutsummaryrefslogtreecommitdiff
path: root/verhoeff/verhoeff_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'verhoeff/verhoeff_test.go')
-rw-r--r--verhoeff/verhoeff_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/verhoeff/verhoeff_test.go b/verhoeff/verhoeff_test.go
new file mode 100644
index 0000000..7678b1f
--- /dev/null
+++ b/verhoeff/verhoeff_test.go
@@ -0,0 +1,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)
+ }
+}