Skip to content

Commit c94a891

Browse files
committed
Create Basic.test.js
1 parent 7c6287d commit c94a891

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Basic.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function rectangle_area(width, height) {
2+
if (width <= 0 || height <= 0) {
3+
return 0;
4+
}
5+
return width * height;
6+
}
7+
8+
test('Normal rectangle area, width > 0 and height > 0', () => {
9+
const rect1 = rectangle_area(8, 6);
10+
expect(rect1).toBe(48);
11+
});
12+
13+
test('Zero rectangle area, width <= 0 or height <= 0', () => {
14+
const rect1 = rectangle_area(-4, 6);
15+
expect(rect1).toBe(0);
16+
17+
const rect2 = rectangle_area(4, -6);
18+
expect(rect2).toBe(0);
19+
20+
const rect3 = rectangle_area(-4, -6);
21+
expect(rect3).toBe(0);
22+
});

0 commit comments

Comments
 (0)