2a3d091978bee01f7548d4c2b096d52ab018b401
[Business-CreditCard.git] / t / test.t
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
3
4 ######################### We start with some black magic to print on failure.
5
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8
9 BEGIN { $| = 1; print "1..2\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use Business::CreditCard;
12 $loaded = 1;
13 print "ok 1\n";
14
15 ######################### End of black magic.
16
17 # Insert your test code below (better if it prints "ok 13"
18 # (correspondingly "not ok 13") depending on the success of chunk 13
19 # of the test code):
20
21 #test 2
22 if( test_card_identification() ){ print "ok 2\n" }else{ print "not ok 2\n" }
23
24 sub test_card_identification{
25         # 
26         # For the curious the table of test number aren't real credit card
27         # in fact they won't validate but they do obey the rule for the
28         # cardtype table to identify the card type.
29         #
30         my %test_table=(
31                 '5212345678901234' =>   'MasterCard',
32                 '5512345678901234' =>   'MasterCard',
33                 '4123456789012' =>      'VISA card',
34                 '4512345678901234' =>   'VISA card',
35                 '341234567890123' =>    'American Express card',
36                 '371234567890123' =>    'American Express card',
37                 #'30112345678901' =>     "Diner's Club/Carte Blanche",
38                 '30112345678901' =>     'Discover card',
39                 #'30512345678901' =>     "Diner's Club/Carte Blanche",
40                 '30512345678901' =>     'Discover card',
41                 #'36123456789012' =>     "Diner's Club/Carte Blanche",
42                 #'36123456789012' =>     'MasterCard',
43                 '36123456789012' =>     'Discover card',
44                 #'38123456789012' =>     "Diner's Club/Carte Blanche",
45                 '38123456789012' =>     'Discover card',
46                 '201412345678901' =>    'enRoute',
47                 '214912345678901' =>    'enRoute',
48                 '6011123456789012' =>   'Discover card',
49                 '3123456789012345' =>   'JCB',
50                 '213112345678901' =>    'JCB',
51                 '180012345678901' =>    'JCB',
52                 '1800123456789012' =>   'Unknown',
53                 '312345678901234' =>    'Unknown',
54                 '4111xxxxxxxxxxxx' =>   'VISA card',
55                 '6599xxxxxxxxxxxx' =>   'Discover card',
56                 '6222xxxxxxxxxxxx' =>   'Discover card', #China Union Pay
57                 '6304980000000000004' => 'Laser',
58                 '6499xxxxxxxxxxxx' =>   'Discover card',
59                 '5610xxxxxxxxxxxx' =>   'BankCard',
60                 '6250xxxxxxxxxxxx' =>   'Discover card', #China Union Pay
61                 '6280xxxxxxxxxxxx' =>   'Discover card', #China Union Pay
62         );
63         while( my ($k, $v)=each(%test_table) ){
64                 if(cardtype($k) ne $v){
65                         warn "Card $k - should be $v but cardtype returns ". cardtype($k). "\n";
66                         return;
67                 }
68         }
69         return 1;
70 }
71