Sha256: eb425add5c48c82779a88b07d3e14207d509752d8b589ed0430fdfa4d2714a60

Contents?: true

Size: 966 Bytes

Versions: 18

Compression:

Stored size: 966 Bytes

Contents

package luhn

import "testing"

const targetTestVersion = 1

var testCases = []struct {
	input       string
	description string
	ok          bool
}{
	{"1", "single digit strings can not be valid", false},
	{"0", "a single zero is invalid", false},
	{"046 454 286", "valid Canadian SIN", true},
	{"046 454 287", "invalid Canadian SIN", false},
	{"8273 1232 7352 0569", "invalid credit card", false},
	{"827a 1232 7352 0569", "strings that contain non-digits are not valid", false},
}

func TestValid(t *testing.T) {
	for _, test := range testCases {
		if ok := Valid(test.input); ok != test.ok {
			t.Fatalf("Valid(%s): %s\n\t Expected: %t\n\t Got: %t", test.input, test.description, ok, test.ok)
		}
	}
}

func BenchmarkValid(b *testing.B) {
	for i := 0; i < b.N; i++ {
		Valid("2323 2005 7766 3554")
	}
}

func TestTestVersion(t *testing.T) {
	if testVersion != targetTestVersion {
		t.Errorf("Found testVersion = %v, want %v", testVersion, targetTestVersion)
	}
}

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
trackler-2.0.6.28 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.27 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.26 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.25 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.24 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.23 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.22 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.21 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.20 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.19 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.18 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.17 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.16 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.15 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.14 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.13 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.12 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.11 tracks/go/exercises/luhn/luhn_test.go