From 97c287084146610e746d12d62845d831b8cb51d6 Mon Sep 17 00:00:00 2001 From: "mark.so" Date: Fri, 29 Mar 2024 16:56:30 +0900 Subject: [PATCH 1/2] push test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 58beeac..45240a7 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,4 @@ This section has moved here: [https://facebook.github.io/create-react-app/docs/d ### `npm run build` fails to minify This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) + From 7526fd80ad00015b3c73298f3038f8f1db4bf8dc Mon Sep 17 00:00:00 2001 From: "mark.so" Date: Fri, 29 Mar 2024 17:44:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[add]=20#1=20cal=20sum,=20divide=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/cal.js | 15 +++++++++++++++ src/utils/cal.test.js | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/utils/cal.js b/src/utils/cal.js index cb801eb..8238d03 100644 --- a/src/utils/cal.js +++ b/src/utils/cal.js @@ -5,3 +5,18 @@ * @returns */ export const add = (a, b) => a + b; + +export const sum = (nums) => { + if (nums === undefined) return undefined; + if (nums.length === 0) return undefined; + + return nums.reduce((acc, row) => acc + row, 0); +}; + +export const divide = (a, b) => { + + if (b === 0) { + return undefined; + } + return { quotient: Math.floor(a / b), remainder: a % b }; +}; diff --git a/src/utils/cal.test.js b/src/utils/cal.test.js index 6584f06..5a7732d 100644 --- a/src/utils/cal.test.js +++ b/src/utils/cal.test.js @@ -1,4 +1,4 @@ -import { add } from './cal'; +import { add, sum, divide } from './cal'; test('adds 1 + 2 to equal 3', () => { const result = add(1, 2); @@ -19,3 +19,40 @@ describe('add test', () => { } ); }); + + +describe('sum test', () => { + // add test cases here + const cases = [ + [undefined, undefined], + [[], undefined], + [[1], 1], + [[1, 2], 3], + ]; + test.each(cases)( + 'test case sum [%p] = %p', + (nums, expected) => { + const result = sum(nums); + expect(result).toBe(expected); + } + ); +}); + +describe('divide test', () => { + // add test cases here + const cases = [ + [1, 0, undefined], + [1, 1, { quotient: 1, remainder: 0 }], + [2, 1, { quotient: 2, remainder: 0 }], + [3, 1, { quotient: 3, remainder: 0 }], + [3, 2, { quotient: 1, remainder: 1 }], + [3, 3, { quotient: 1, remainder: 0 }], + ]; + test.each(cases)( + 'test case divide %p / %p %p', + (a, b, expected) => { + const result = divide(a, b); + expect(result).toEqual(expected); + } + ); +});