-
Notifications
You must be signed in to change notification settings - Fork 31
/
test.js
47 lines (40 loc) · 949 Bytes
/
test.js
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
'use strict';
const test = require('tape');
const luhn = require('./');
test(function( t ){
const pans = [
// from the ISO standard
'6123451234567893',
// http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm
'4012111111111111',
'378282246310005',
'371449635398431',
'378734493671000',
'5610591081018250',
'30569309025904',
'38520000023237',
'6011111111111117',
'6011000990139424',
'3530111333300000',
'3566002020360505',
'5555555555554444',
'5105105105105100',
'4111111111111111',
'4012888888881881',
'4222222222222',
'5019717010103742',
'6331101999990016',
];
const invalid = [
'76009244561',
'4571736004738485',
];
pans.forEach(function( pan ){
t.equal(luhn(true, pan), true, pan+' is valid');
t.equal(luhn(pan.slice(0, -1)), pan.slice(-1));
});
invalid.forEach(function( pan ){
t.equal(luhn(true, pan), false, pan+' is invalid');
});
t.end();
});