-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbusiness-creditcard_test.go
55 lines (46 loc) · 1.5 KB
/
business-creditcard_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package creditcard
import (
"testing"
)
type card struct {
Number string
Type string
Valid bool
}
var cards = []*card{
&card{"4242424242424242", "Visa", true}, // should pass
&card{"4213729238347292", "Visa", false}, // should fail
&card{"79927398713", "Unknown", true}, // should pass
&card{"79927398710", "Unknown", false}, // should fail
&card{"6011111111111117", "Discover", true}, // should pass
&card{"6011342393482022", "Discover", false}, // should fail
&card{"344347386473833", "AmericanExpress", false}, // should fail
&card{"374347386473833", "AmericanExpress", false}, // should fail
&card{"30569309025904", "DinersClub/Carteblanche", true}, // should pass
&card{"30569309025905", "DinersClub/Carteblanche", false}, // should fail
&card{"5555555555554444", "MasterCard", true}, // should pass
&card{"5555555555554445", "MasterCard", false}, // should fail
&card{"180034239348202", "JCB", false}, // should fail
}
func TestValidate(t *testing.T) {
for _, card := range cards {
valid := Validate(card.Number)
if valid != card.Valid {
t.Errorf("card validation [%v]; want [%v]", valid, card.Valid)
}
}
}
func TestCardype(t *testing.T) {
for _, card := range cards {
cardType := Cardtype(card.Number)
if cardType != card.Type {
t.Errorf("card type [%s]; want [%s]", cardType, card.Type)
}
}
}
func TestGenerateLastDigit(t *testing.T) {
lastDigit := GenerateLastDigit("5276 4400 6542 131")
if lastDigit != "9" {
t.Errorf("last digit [%s]; want [%s]", lastDigit, "9")
}
}