-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreditCardTest.rb
62 lines (58 loc) · 1.39 KB
/
CreditCardTest.rb
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
56
57
58
59
60
61
62
# requires the CreditCard and unit test classes
require_relative "CreditCard"
require "test/unit"
class CreditCardTest < Test::Unit::TestCase
def cards
# array of supplied test data
[
{
number: 4111111111111111,
company: "VISA",
valid: true
},
{
number: 4111111111111,
company: "VISA",
valid: false
},
{
number: 4012888888881881,
company: "VISA",
valid: true
},
{
number: 378282246310005,
company: "AMEX",
valid: true
},
{
number: 6011111111111117,
company: "Discover",
valid: true
},
{
number: 5105105105105100,
company: "Mastercard",
valid: true
},
{
number: "5105 1051 0510 5106",
company: "Mastercard",
valid: false
},
{
number: 9111111111111111,
company: "Unknown",
valid: false
}
]
end
def test_numbers
# test each element of the test data array, to verify expected results
cards.each do |card|
creditcard = CreditCard.new(card[:number])
assert_equal(card[:valid], creditcard.is_valid?, "[#{card[:number]}] validity not #{card[:valid]}" )
assert_equal(card[:company], creditcard.company, "[#{card[:number]}] #{card[:company]} equals #{creditcard.company}")
end
end
end