Skip to content

Commit 91b366f

Browse files
author
dunghenry
committed
add test
1 parent e86ab2b commit 91b366f

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

test/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function add(a, b) {
2+
return a + b
3+
}
4+
function subtract(a, b) {
5+
return a - b
6+
}
7+
function multiply(a, b) {
8+
return a * b
9+
}
10+
function divide(a, b) {
11+
return a / b
12+
}
13+
function power(a, b) {
14+
return a ** b
15+
}
16+
module.exports = {
17+
add,
18+
subtract,
19+
multiply,
20+
divide,
21+
power
22+
}

test/index.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const test = require('node:test');
2+
const assert = require('assert/strict');
3+
const { add, subtract, multiply, divide, power } = require('.');
4+
test('add', () => {
5+
assert.equal(add(1, 2), 3);
6+
});
7+
test('subtract', () => {
8+
assert.equal(subtract(1, 2), -1);
9+
});
10+
test('multiply', () => {
11+
assert.equal(multiply(1, 2), 2);
12+
});
13+
test('divide', () => {
14+
assert.equal(divide(1, 2), 0.5);
15+
});
16+
test('power', () => {
17+
assert.equal(power(2, 2), 4);
18+
});

test/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "test",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT"
6+
}

0 commit comments

Comments
 (0)