luhn_test.go 481 B

123456789101112131415161718192021222324252627
  1. // Copyright (C) 2014 The Protocol Authors.
  2. package protocol
  3. import (
  4. "strings"
  5. "testing"
  6. )
  7. func TestLuhn32(t *testing.T) {
  8. c, err := luhn32("AB725E4GHIQPL3ZFGT")
  9. if err != nil {
  10. t.Fatal(err)
  11. }
  12. if c != 'G' {
  13. t.Errorf("Incorrect check digit %c != G", c)
  14. }
  15. _, err = luhn32("3734EJEKMRHWPZQTWYQ1")
  16. if err == nil {
  17. t.Error("Unexpected nil error")
  18. }
  19. if !strings.Contains(err.Error(), "'1'") {
  20. t.Errorf("luhn32 should have errored on digit '1', got %v", err)
  21. }
  22. }