Skip to content

Commit b335da7

Browse files
Code and tests (#4)
Code for add functionality along with a test suite
1 parent 6286faa commit b335da7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/add.test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, it, expect } from "vitest";
2+
import { add } from "../src/add";
23

34
describe("Test add function", () => {
45
it("should add two positive numbers", () => {
@@ -8,9 +9,29 @@ describe("Test add function", () => {
89
const expected = 3;
910

1011
// Act
11-
const result = a + b;
12+
const result = add(a, b);
1213

1314
// Assert
1415
expect(result).toBe(expected);
1516
});
17+
18+
it("should add two negative numbers", () => {
19+
const x = -5;
20+
const y = -6;
21+
const expected = -11;
22+
23+
const res = add(x, y);
24+
25+
expect(res).toBe(expected);
26+
});
27+
28+
it("should add a positive and a negative number", () => {
29+
const firstNum = -7;
30+
const secondNum = 10;
31+
const expected = 3;
32+
33+
const res = add(firstNum, secondNum);
34+
35+
expect(res).toBe(expected);
36+
});
1637
});

0 commit comments

Comments
 (0)