-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
27 lines (20 loc) · 908 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
const parser = require('./app');
let numTested = 0;
let numPassed = 0;
console.log(" Starting test\n");
test("Donald Lee", "Donald", "Lee");
test("Donald Lee Qian Siang", "Donald", "Lee");
test("Lee Qian Siang Donald", "Donald", "Lee");
test("Wong Jie Min", "Jie Min", "Wong");
test("Jie Min, Wong", "Jie Min", "Wong");
console.log(`\n ${numPassed}/${numTested} passed.\n`)
function test(fullName, expectedFirst, expectedLast) {
const result = parser.parseName(fullName);
numTested++;
if (result.firstName === expectedFirst && result.lastName === expectedLast) {
numPassed++;
console.log(`${numTested}. passed: ${fullName} returns ${result.firstName} and ${result.lastName}.`)
} else {
console.log(`${numTested}. failed: ${fullName} should return ${expectedFirst} and ${expectedLast} but instead returns ${result.firstName} and ${result.lastName}.`)
}
}