Skip to content

Commit 631c8b1

Browse files
committed
unit testing
1 parent 77dbd0d commit 631c8b1

18 files changed

+18715
-0
lines changed

27-unit-test/app.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/env node
2+
3+
const add = require('./calc');
4+
5+
if(process.argv.length != 4) {
6+
console.log('Usage: cmd x y');
7+
process.exit(1);
8+
}
9+
10+
const [,,x, y] = process.argv;
11+
console.log(`${x} + ${y} = ${add(Number(x), Number(y))}`);

27-unit-test/calc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function add(x, y) {
2+
if (isNaN(x) || isNaN(y)) {
3+
return NaN;
4+
} else {
5+
return x+y;
6+
}
7+
}
8+
9+
module.exports = add;

0 commit comments

Comments
 (0)