예제 1-6 좀 더 범용적인 check 함수를 만들어서 테스트하기
// custom-test-phase3.js
const assertEquals = (expected, actual) => {
if (actual !== expected) {
throw new Error(`Expected ${expected} but was ${actual}`);
}
};
const check = (name, implementation) => {
try {
implementation();
console.log(`${name} passed`);
} catch (e) {
console.error(`${name} FAILED`, e.stack);
}
};
check('sum with 2 numbers should sum them up', () => {
const result = sum('1,2');
assertEquals(3, result);
});
check('sum with multiple digit numbers should sum them up', () => {
const result = sum('10,20');
assertEquals(30, result);
});