forgot to include Changes file in MANIFEST
[Business-CreditCard.git] / test.pl
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                 '30512345678901' =>     "Diner's Club/Carte Blanche",
39                 '36123456789012' =>     "Diner's Club/Carte Blanche",
40                 '38123456789012' =>     "Diner's Club/Carte Blanche",
41                 '201412345678901' =>    'enRoute',
42                 '214912345678901' =>    'enRoute',
43                 '6011123456789012' =>   'Discover card',
44                 '3123456789012345' =>   'JCB',
45                 '213112345678901' =>    'JCB',
46                 '180012345678901' =>    'JCB',
47                 '1800123456789012' =>   'Unknown',
48                 '312345678901234' =>    'Unknown',
49         );
50         while( my ($k, $v)=each(%test_table) ){
51                 if(cardtype($k) ne $v){
52                         print "Card $k - should be $v cardtpe returns ",cardtype
53 ($k),"\n";
54                         return;
55                 }
56         }
57         return 1;
58 }
59