Skip to content

Commit 5ff1812

Browse files
committed
Test: sample test code
1 parent 107314e commit 5ff1812

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: __test__/sum.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ import { sum } from '../src/sum';
44
test('add 1+ 2 is 3', () => {
55
expect(sum(1, 2)).toBe(3);
66
});
7+
8+
test('a값의 상한은 100이다.', () => {
9+
expect(sum(90, 70)).toBe(160);
10+
});
11+
12+
test('a값이 100 이상일 경우 에러가 발생한다.', () => {
13+
expect(() => sum(110, 20)).toThrow('0~100 사이의 값을 입력해주세요.');
14+
});

Diff for: src/sum.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export function sum(a: number, b: number) {
2+
if (a < 0 || a > 100) {
3+
throw new Error('0~100 사이의 값을 입력해주세요.');
4+
}
5+
26
return a + b;
37
}

0 commit comments

Comments
 (0)