-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
48 lines (40 loc) · 1.01 KB
/
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
48
'use strict';
/* global describe:false, it:false */
import { expect } from 'chai';
import luhn from './src';
describe('luhn', () => {
it('should exists', () => {
expect(luhn).to.exist;
});
it('should return false for wrong inputs', () => {
expect(luhn()).to.be.false;
expect(luhn('')).to.be.false;
expect(luhn('abc')).to.be.false;
expect(luhn('1.0')).to.be.false;
expect(luhn(1)).to.be.false;
expect(luhn([])).to.be.false;
expect(luhn({})).to.be.false;
});
describe('algorithm', () => {
let validOnes = [
'4149685344157815',
'4984421209470251',
'49927398716',
'1234567812345670'
],
invalidOnes = [
'49927398717',
'1234567812345678'
];
it('should recognize valid numbers', () => {
for (var i of validOnes) {
expect(luhn(i)).to.be.true;
}
});
it('should recognize invalid numbers', () => {
for (var i of invalidOnes) {
expect(luhn(i)).to.be.false;
}
});
});
});