60 lines
766 B
Go
60 lines
766 B
Go
package validate
|
|
|
|
import "testing"
|
|
|
|
func TestLuhn(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
pan string
|
|
want bool
|
|
}{
|
|
{
|
|
"Mastercard",
|
|
"5555555555554444",
|
|
true,
|
|
},
|
|
{
|
|
"Visa",
|
|
"4111111111111111",
|
|
true,
|
|
},
|
|
{
|
|
"example from wiki",
|
|
"17893729974",
|
|
true,
|
|
},
|
|
{
|
|
"another example",
|
|
"79927398713",
|
|
true,
|
|
},
|
|
{
|
|
"worong check digit",
|
|
"17893729975",
|
|
false,
|
|
},
|
|
{
|
|
"off by one error",
|
|
"27893729974",
|
|
false,
|
|
},
|
|
{
|
|
"empty",
|
|
"",
|
|
false,
|
|
},
|
|
{
|
|
"not a digit",
|
|
"27893a29974",
|
|
false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := Luhn(tt.pan)
|
|
if got != tt.want {
|
|
t.Errorf("Luhn(%s) = %v, want %v", tt.name, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|