Sha256: 775c9872fdd9c8061663a15c4f23736e91a98e7f12b267cd922a33340c93b78c

Contents?: true

Size: 1.07 KB

Versions: 66

Compression:

Stored size: 1.07 KB

Contents

package luhn

import "testing"

var validTests = []struct {
	n  string
	ok bool
}{
	{"738", false},
	{"8739567", true},
	{"1111", false},
	{"8763", true},
	{"    ", false},
	{"", false},
	{"2323 2005 7766 3554", true},
}

var addTests = []struct{ raw, luhn string }{
	{"123", "1230"},
	{"873956", "8739567"},
	{"837263756", "8372637564"},
	{"2323 2005 7766 355", "2323 2005 7766 3554"},
	// bonus Unicode cases
	// {"2323·2005·7766·355", "2323·2005·7766·3554"},
	// {"123", "1230"},
}

func TestValid(t *testing.T) {
	for _, test := range validTests {
		if ok := Valid(test.n); ok != test.ok {
			t.Fatalf("Valid(%s) = %t, want %t.", test.n, ok, test.ok)
		}
	}
}

func TestAddCheck(t *testing.T) {
	for _, test := range addTests {
		if luhn := AddCheck(test.raw); luhn != test.luhn {
			t.Fatalf("AddCheck(%s) = %s, want %s.", test.raw, luhn, test.luhn)
		}
	}
}

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

func BenchmarkAddCheck(b *testing.B) {
	for i := 0; i < b.N; i++ {
		AddCheck("2323 2005 7766 355")
	}
}

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
trackler-2.0.6.10 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.9 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.8 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.7 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.6 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.5 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.4 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.3 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.2 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.1 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.6.0 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.18 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.17 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.16 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.15 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.14 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.13 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.12 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.11 tracks/go/exercises/luhn/luhn_test.go
trackler-2.0.5.10 tracks/go/exercises/luhn/luhn_test.go