Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
11
test/luhnCheck/luhnCheck.js
Normal file
11
test/luhnCheck/luhnCheck.js
Normal file
@ -0,0 +1,11 @@
|
||||
const luhnCheck = num => {
|
||||
let arr = (num + '')
|
||||
.split('')
|
||||
.reverse()
|
||||
.map(x => parseInt(x));
|
||||
let lastDigit = arr.splice(0, 1)[0];
|
||||
let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + (val * 2) % 9 || 9), 0);
|
||||
sum += lastDigit;
|
||||
return sum % 10 === 0;
|
||||
};
|
||||
module.exports = luhnCheck;
|
||||
11
test/luhnCheck/luhnCheck.test.js
Normal file
11
test/luhnCheck/luhnCheck.test.js
Normal file
@ -0,0 +1,11 @@
|
||||
const expect = require('expect');
|
||||
const luhnCheck = require('./luhnCheck.js');
|
||||
|
||||
|
||||
test('luhnCheck is a Function', () => {
|
||||
expect(luhnCheck).toBeInstanceOf(Function);
|
||||
});
|
||||
t.equal(luhnCheck(6011329933655299), false, "validates identification number");
|
||||
t.equal(luhnCheck('4485275742308327'), true, "validates identification number");
|
||||
t.equal(luhnCheck(123456789), false, "validates identification number");
|
||||
|
||||
Reference in New Issue
Block a user