From b4ecc4412440512b650555d3d51e85855daec34f Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Sun, 29 Oct 2023 12:03:57 +0900 Subject: [PATCH 01/53] =?UTF-8?q?chore:=20prettier,=20eslint=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 30 ++++++++++++++++++++++++++++++ .prettierrc.js | 11 +++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .eslintrc.js create mode 100644 .prettierrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..b32af76f2 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,30 @@ +export default { + env: { + browser: true, + es2021: true, + }, + extends: ['airbnb-base', 'prettier'], + overrides: [ + { + env: { + jest: true, + node: true, + }, + files: [ + '.eslintrc.{js,cjs}', + ], + parserOptions: { + sourceType: 'script', + }, + }, + ], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + rules: { + 'max-depth': ['error', 2], + 'max-params': ['error', 3], + 'max-lines-per-function': ['error', { max: 10 }], + }, +}; diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 000000000..1b4ce05b2 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,11 @@ +export default { + singleQuote: true, + semi: true, + useTabs: false, + tabWidth: 2, + trailingComma: "all", + printWidth: 80, + bracketSpacing: true, + arrowParens: "always", + endOfLine: "auto", +}; From fc43a68f38528cce7bc029f5ba3f175ea511365d Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Sun, 29 Oct 2023 13:42:08 +0900 Subject: [PATCH 02/53] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 153 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..3bdcf0151 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,153 @@ +# ๐Ÿš— ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„ ๐Ÿš— + +``` + ๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„) + pobi,woni,jun + ์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”? + 5 + + pobi : - + woni : + jun : - + + pobi : -- + woni : - + jun : -- + + pobi : --- + woni : -- + jun : --- + + pobi : ---- + woni : --- + jun : ---- + + pobi : ----- + woni : ---- + jun : ----- + + ์ตœ์ข… ์šฐ์Šน์ž : pobi, jun + +``` + +--- + +## โœ… ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ชฉ๋ก + +1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - 1-1. [] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - ex) "๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)" + - 1-2. [] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ + - ์ด๋ฆ„ ์ž…๋ ฅ์€ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ + - ์ด๋ฆ„์— ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ + - ex) pobi,woni,jun + + - 1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + - ๊ฐ ์ด๋ฆ„์ด 5๊ธ€์ž ์ดˆ๊ณผ์ธ ๊ฒฝ์šฐ + - ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ๋Š” ๊ฒฝ์šฐ + - ์ด๋ฆ„ ์ค‘๊ฐ„์— ์‰ผํ‘œ๊ฐ€ ๋“ค์–ด๊ฐ„ ๊ฒฝ์šฐ + - throw๋ฌธ์„ ์‚ฌ์šฉํ•ด "[ERROR]" ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ€์ง€๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ + - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ + +2. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ + - 2-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ์ž๋™์ฐจ ์ƒ์„ฑ + +3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - 3-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - ex) "์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?" + - 3-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ + - ex) 3 + - 3-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ + - 3๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - ์ž์—ฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ˜•์‹์„ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - ์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ 10 ์ด์ƒ์ธ ๊ฒฝ์šฐ(์ž„์˜ ์„ค์ •) + - throw๋ฌธ์„ ์‚ฌ์šฉํ•ด "[ERROR]" ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ€์ง€๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ + - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ + +4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ + - 4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ + - 4-2. [] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ + - 4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ + - 4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ + - ์šฐ์Šน์ž ํ•œ ๋ช… ์ด์ƒ ๊ฐ€๋Šฅ + +5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ + - 5-1. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - "์‹คํ–‰ ๊ฒฐ๊ณผ" + - 5-2. [] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + +6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ + - 6-1. [] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - ์šฐ์Šน์ž๊ฐ€ ์—ฌ๋ ค๋ช…์ผ ๊ฒฝ์šฐ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ + - ex) ์ตœ์ข… ์šฐ์Šน์ž : pobi, jun + + +--- + +## โœ”๏ธ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„ ๋ชฉ๋ก + +1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - T-1-1. [] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-1-2. [] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + - T-1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + +2. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ + - T-2-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ + +3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - T-3-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-3-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ + - T-3-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + +4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ + - T-4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ + - T-4-2. [] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ + - T-4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ + - T-4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ + +5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ + - T-5-1. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-5-2. [] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + +6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ + - T-6-1. [] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + +--- + +## ๐Ÿ–‹๏ธ ์š”๊ตฌ์‚ฌํ•ญ + +- [] Node.js 18.17.1 ๋ฒ„์ „์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค. +- [] ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์˜ ์‹œ์ž‘์ ์€ App.js์˜ play ๋ฉ”์„œ๋“œ์ด๋‹ค. +- [] package.json์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋‹ค. +- [] ์ˆœ์ˆ˜ Vanila JS๋กœ๋งŒ ๊ตฌํ˜„ํ•œ๋‹ค. +- [] ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(jQuery, Lodash ๋“ฑ)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- [] JavaScript ์ฝ”๋“œ ์ปจ๋ฒค์…˜์„ ์ง€ํ‚ค๋ฉด์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ•œ๋‹ค +- [] ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ ์‹œ process.exit()๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค +- [] ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„์ด ์™„๋ฃŒ๋˜๋ฉด ApplicationTest์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ•ด์•ผ ํ•œ๋‹ค +- [] ์š”๊ตฌ ์‚ฌํ•ญ์—์„œ ๋‹ฌ๋ฆฌ ๋ช…์‹œํ•˜์ง€ ์•Š๋Š” ํ•œ ํŒŒ์ผ, ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. +- [] indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) 2๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. + - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. +- [] jest๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณธ์ธ์ด ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ ๋™์ž‘ํ•จ์„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. +- [] @woowacourse/mission-utils์—์„œ ์ œ๊ณตํ•˜๋Š” Random ๋ฐ Console API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค +- [] Random ๊ฐ’ ์ถ”์ถœ์€ Random.pickNumberInRange()๋ฅผ ํ™œ์šฉํ•œ๋‹ค. +- [] ์‚ฌ์šฉ์ž์˜ ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๊ณ  ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Console.readLineAsync, Console.print๋ฅผ ํ™œ์šฉํ•œ๋‹ค + +--- + +## ๐Ÿ“ข 1์ฃผ์ฐจ ๊ณตํ†ต ํ”ผ๋“œ๋ฐฑ + +- ์š”๊ตฌ์‚ฌํ•ญ์„ ์ •ํ™•ํžˆ ์ค€์ˆ˜ํ•œ๋‹ค +- ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์˜๋ฏธ ์žˆ๊ฒŒ ์ž‘์„ฑํ•œ๋‹ค +- git์„ ํ†ตํ•ด ๊ด€๋ฆฌํ•  ์ž์›์— ๋Œ€ํ•ด์„œ๋„ ๊ณ ๋ คํ•œ๋‹ค +- Pull Request๋ฅผ ๋ณด๋‚ด๊ธฐ ์ „ ๋ธŒ๋žœ์น˜๋ฅผ ํ™•์ธํ•œ๋‹ค +- PR์„ ํ•œ ๋ฒˆ ์ž‘์„ฑํ–ˆ๋‹ค๋ฉด ๋‹ซ์ง€ ๋ง๊ณ  ์ถ”๊ฐ€ ์ปค๋ฐ‹์„ ํ•œ๋‹ค +- ์ด๋ฆ„์„ ํ†ตํ•ด ์˜๋„๋ฅผ ๋“œ๋Ÿฌ๋‚ธ๋‹ค +- ์ถ•์•ฝํ•˜์ง€ ์•Š๋Š”๋‹ค +- ๊ณต๋ฐฑ๋„ ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜์ด๋‹ค +- ๊ณต๋ฐฑ ๋ผ์ธ์„ ์˜๋ฏธ ์žˆ๊ฒŒ ์‚ฌ์šฉํ•œ๋‹ค +- space์™€ tab์„ ํ˜ผ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค +- ์˜๋ฏธ ์—†๋Š” ์ฃผ์„์„ ๋‹ฌ์ง€ ์•Š๋Š”๋‹ค +- linter์™€ Code Formatter์˜ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•œ๋‹ค +- EOL(End Of Line) +- ๋ถˆํ•„์š”ํ•œ console.log๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๋Š”๋‹ค +- JavaScript์—์„œ ์ œ๊ณตํ•˜๋Š” API๋ฅผ ์ ๊ทน ํ™œ์šฉํ•œ๋‹ค \ No newline at end of file From 14188777a712a9bf56aa2a6d0e7681f94398e575 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 11:33:00 +0900 Subject: [PATCH 03/53] =?UTF-8?q?feat:=20(1-1)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index c38b30d5b..6ff5427d6 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,18 @@ +import { Console } from "@woowacourse/mission-utils"; + class App { - async play() {} + + async play() { + await this.getCarName(); + } + + async getCarName() { + const inputName = await Console.readLineAsync("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)"); + return inputName; + } } +const app = new App(); +app.play(); + export default App; From d65ad00dc24e2432a892bc1abbdbfdd6910bd00f Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 11:46:29 +0900 Subject: [PATCH 04/53] =?UTF-8?q?docs:=20(1-1)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 11 +++++---- docs/StudyLog.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 docs/StudyLog.md diff --git a/docs/README.md b/docs/README.md index 3bdcf0151..4c4438c21 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # ๐Ÿš— ์ž๋™์ฐจ ๊ฒฝ์ฃผ ๊ฒŒ์ž„ ๐Ÿš— -``` +``` html ๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„) pobi,woni,jun ์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”? @@ -35,7 +35,7 @@ ## โœ… ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ชฉ๋ก 1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ - - 1-1. [] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - 1-1. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ex) "๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)" - 1-2. [] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ - ์ด๋ฆ„ ์ž…๋ ฅ์€ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ @@ -81,7 +81,6 @@ - ์šฐ์Šน์ž๊ฐ€ ์—ฌ๋ ค๋ช…์ผ ๊ฒฝ์šฐ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ - ex) ์ตœ์ข… ์šฐ์Šน์ž : pobi, jun - --- ## โœ”๏ธ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„ ๋ชฉ๋ก @@ -130,7 +129,7 @@ - [] jest๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณธ์ธ์ด ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ ๋™์ž‘ํ•จ์„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. - [] @woowacourse/mission-utils์—์„œ ์ œ๊ณตํ•˜๋Š” Random ๋ฐ Console API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค - [] Random ๊ฐ’ ์ถ”์ถœ์€ Random.pickNumberInRange()๋ฅผ ํ™œ์šฉํ•œ๋‹ค. -- [] ์‚ฌ์šฉ์ž์˜ ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๊ณ  ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Console.readLineAsync, Console.print๋ฅผ ํ™œ์šฉํ•œ๋‹ค +- [] ์‚ฌ์šฉ์ž์˜ ๊ฐ’์„ ์ž…๋ ฅ ๋ฐ›๊ณ  ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Console.readLineAsync, Console.print๋ฅผ ํ™œ์šฉํ•œ๋‹ค --- @@ -150,4 +149,6 @@ - linter์™€ Code Formatter์˜ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•œ๋‹ค - EOL(End Of Line) - ๋ถˆํ•„์š”ํ•œ console.log๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๋Š”๋‹ค -- JavaScript์—์„œ ์ œ๊ณตํ•˜๋Š” API๋ฅผ ์ ๊ทน ํ™œ์šฉํ•œ๋‹ค \ No newline at end of file +- JavaScript์—์„œ ์ œ๊ณตํ•˜๋Š” API๋ฅผ ์ ๊ทน ํ™œ์šฉํ•œ๋‹ค + +--- diff --git a/docs/StudyLog.md b/docs/StudyLog.md new file mode 100644 index 000000000..85862e707 --- /dev/null +++ b/docs/StudyLog.md @@ -0,0 +1,61 @@ +# ๐Ÿ“– ๋ฐฐ์šด ๋‚ด์šฉ ๐Ÿ“– + +## 1. ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ + +
+ +### 1-1. ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + +- `Class` + - ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์—์„œ, ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•œ 'ํ‹€' ๋˜๋Š” '์„ค๊ณ„๋„'์˜ ๊ฐœ๋… + - ๋ฐ์ดํ„ฐ(์†์„ฑ or ๋ฉค๋ฒ„ ๋ณ€์ˆ˜) + ๋ฐ์ดํ„ฐ๋ฅผ ์กฐ์ž‘ํ•˜๋Š” ๋ฉ”์„œ๋“œ(ํ•จ์ˆ˜)๋ฅผ ํฌํ•จํ•œ๋‹ค +- `Method` + - ํด๋ž˜์Šค ๋‚ด์—์„œ ์ •์˜๋œ ํ•จ์ˆ˜ + - ๊ฐ์ฒด๊ฐ€ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋™์ž‘์ด๋‚˜ ํ–‰์œ„ + - ๊ฐ์ฒด์˜ ์†์„ฑ(๋ฐ์ดํ„ฐ)์„ ์กฐ์ž‘ํ•˜๊ฑฐ๋‚˜ ์ฒ˜๋ฆฌํ•œ๋‹ค + - '๋‹ฌ๋ฆฐ๋‹ค', '๋ฉˆ์ถ˜๋‹ค' ๋“ฑ +- `this ํ‚ค์›Œ๋“œ` + - ํ˜„์žฌ ๊ฐ์ฒด ๋˜๋Š” ํ˜„์žฌ ์ปจํ…์ŠคํŠธ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ํ‚ค์›Œ๋“œ +- `async ์™€ await` + - ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ ํŒจํ„ด์œผ๋กœ ์–ด๋–ค ๋™์ž‘์˜ ์™„๋ฃŒ๋ฅผ ๊ธฐ๋‹ค๋ ค์•ผ ํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค + - ์˜ˆ๋ฅผ ๋“ค์–ด ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์„ ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ž‘์—…๋“ฑ์€ ์‹œ๊ฐ„์ด ์–ผ๋งˆ๋‚˜ ๊ฑธ๋ฆด์ง€ ๋ชจ๋ฅด๋ฏ€๋กœ ๋น„๋™๊ธฐ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค + - async - ํ•จ์ˆ˜๊ฐ€ ๋น„๋™๊ธฐ๋กœ ์ž‘๋™ํ•จ์„ ์„ ์–ธํ•œ๋‹ค + - await - ๋น„๋™๊ธฐ ๋™์ž‘์˜ ์™„๋ฃŒ๋ฅผ ๊ธฐ๋‹ค๋ฆฐ๋‹ค +- `readLine(query, callback)` + - ์ฃผ์–ด์ง„ ์งˆ๋ฌธ์„ ํ™”๋ฉด์— ์ถœ๋ ฅํ•œ๋‹ค + - ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ต๋ณ€์„ ์ž…๋ ฅํ•  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฐ๋‹ค + - ์ดํ›„ ์ž…๋ ฅ๋œ ๋‹ต๋ณ€์„ ์ธ์ˆ˜๋กœ ์ „๋‹ฌํ•˜๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค + + ``` javascript + Console.readLine('๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.', (answer) => { + console.log(`๋‹‰๋„ค์ž„: ${answer}`); + }); + ``` + +- `readLineAsync(query)` + - ์ฃผ์–ด์ง„ ์งˆ๋ฌธ์„ ํ™”๋ฉด์— ์ถœ๋ ฅํ•œ๋‹ค + - ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๋‹ต๋ณ€์„ Promise๋ฅผ ํ†ตํ•ด ๋ฐ˜ํ™˜ํ•œ๋‹ค + + ``` javascript + async function getUername() { + try{ + const username = await Console.readLineAsync('๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.'); + } catch (error) { + // reject ๋˜๋Š” ๊ฒฝ์šฐ + } + } + ``` + +- `print(message)` + - ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์„ ์ฝ˜์†”์— ์ถœ๋ ฅํ•œ๋‹ค + + ``` javascript + async function getUername() { + try{ + const username = await Console.readLineAsync('๋‹‰๋„ค์ž„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.'); + } catch (error) { + // reject ๋˜๋Š” ๊ฒฝ์šฐ + } + } + ``` + From 65849de491ae9d1bfbb1d72b5af40886cbdb7315 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 11:48:22 +0900 Subject: [PATCH 05/53] =?UTF-8?q?feat:=20(T-1-1)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 __tests__/BeforeRefactor.test.js diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js new file mode 100644 index 000000000..1d38dff1e --- /dev/null +++ b/__tests__/BeforeRefactor.test.js @@ -0,0 +1,19 @@ +import App from "../src/App.js"; +import { Console } from "@woowacourse/mission-utils" + +const mockInput = (input) => { + Console.readLineAsync = jest.fn(() => Promise.resolve(input)); +}; + +describe("App class Test", () => { + test("getCarName ์‚ฌ์šฉ์ž ์ž…๋ ฅ", async () => { + const testInput = "pobi,woni,jun"; + mockInput(testInput); + + const app = new App(); + const result = await app.getCarName(); + + expect(Console.readLineAsync).toHaveBeenCalledTimes(1); + expect(result).toBe(testInput); + }); +}); \ No newline at end of file From b9ea9954ca6acf32f85da0335470f0a31c9d13ca Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 11:49:20 +0900 Subject: [PATCH 06/53] =?UTF-8?q?docs:=20(T-1-1)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 4c4438c21..1e0948ed7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -86,7 +86,7 @@ ## โœ”๏ธ ํ…Œ์ŠคํŠธ ๊ตฌํ˜„ ๋ชฉ๋ก 1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ - - T-1-1. [] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-1-1. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - T-1-2. [] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - T-1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index 85862e707..c7b364a65 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -59,3 +59,23 @@ } ``` +
+ +### T-1-1. ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + +- `Mocking` + - ์‹ค์ œ ๊ตฌํ˜„์„ ๋ฐ”๊พธ์ง€ ์•Š๊ณ ๋„ ํ…Œ์ŠคํŠธ์˜ ๊ฒฉ๋ฆฌ๋ฅผ ๋ณด์žฅํ•˜๊ณ  ์‹คํ–‰ํ•œ๋‹ค +- `Spy` + - ํ•จ์ˆ˜๋‚˜ ๋ฉ”์„œ๋“œ๊ฐ€ ์–ด๋–ป๊ฒŒ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ์ถ”์ ํ•œ๋‹ค +- `Mocking Clear` + - ๊ฐ ํ…Œ์ŠคํŠธ ์‚ฌ์ด์—์„œ Mock๊ณผ Spy์˜ ์ƒํƒœ๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค + - ๋‹ค๋ฅธ ํ…Œ์ŠคํŠธ์˜ ๊ฒฐ๊ณผ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ธฐ ์œ„ํ•œ ๋ชฉ์  +- `Describe` + - ๊ด€๋ จ ํ…Œ์ŠคํŠธ๋“ค์„ ๊ทธ๋ฃนํ™”ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค + - ๋ธ”๋ก ์•ˆ ํ…Œ์ŠคํŠธ๋“ค์ด ํŠน์ • ํด๋ž˜์Šค๋‚˜ ํ•จ์ˆ˜, ๊ธฐ๋Šฅ ๋“ฑ์— ๊ด€ํ•œ ๊ฒƒ์ด๋ผ๋Š” ๊ฒƒ์„ ์•Œ๋ ค์ค€๋‹ค +- `Test` + - ๊ฐœ๋ณ„ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋ฅผ ์ •์˜ํ•œ๋‹ค + - ์ฒซ ๋ฒˆ์งธ ์ธ์ž๋Š” ํ…Œ์ŠคํŠธ์˜ ์ด๋ฆ„ ๋˜๋Š” ์„ค๋ช…์„ ๋ฌธ์ž์—ด๋กœ ๋ฐ›๋Š”๋‹ค + - ๋‘๋ฒˆ์งธ ์ธ์ž๋Š” ํ…Œ์ŠคํŠธ ๋กœ์ง์„ ํฌํ•จํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋ฐ›๋Š”๋‹ค +- `Expectation` + - ๊ฐ’์— ๋Œ€ํ•œ ํŠน์ • ์กฐ๊ฑด์„ ์„ค์ •ํ•œ๋‹ค. From 8a22c9f6703b3d90dc332e7b2cca443e19151203 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 15:04:52 +0900 Subject: [PATCH 07/53] =?UTF-8?q?feat:=20(1-2)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 6ff5427d6..50bc35ac1 100644 --- a/src/App.js +++ b/src/App.js @@ -8,7 +8,12 @@ class App { async getCarName() { const inputName = await Console.readLineAsync("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)"); - return inputName; + return this.sanitizeCarName(inputName); + } + + sanitizeCarName(inputName) { + const sanitizedName = inputName.split(',').map(name => name.trim()); + return sanitizedName; } } From d0fe8177b4c0bf47803423eb725d72b49dfee0ae Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 15:07:33 +0900 Subject: [PATCH 08/53] =?UTF-8?q?docs:=20(1-2)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 1e0948ed7..a25231326 100644 --- a/docs/README.md +++ b/docs/README.md @@ -37,7 +37,7 @@ 1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ - 1-1. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ex) "๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)" - - 1-2. [] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ + - 1-2. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ - ์ด๋ฆ„ ์ž…๋ ฅ์€ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ - ์ด๋ฆ„์— ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ - ex) pobi,woni,jun diff --git a/docs/StudyLog.md b/docs/StudyLog.md index c7b364a65..9b870a07e 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -79,3 +79,67 @@ - ๋‘๋ฒˆ์งธ ์ธ์ž๋Š” ํ…Œ์ŠคํŠธ ๋กœ์ง์„ ํฌํ•จํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๋ฐ›๋Š”๋‹ค - `Expectation` - ๊ฐ’์— ๋Œ€ํ•œ ํŠน์ • ์กฐ๊ฑด์„ ์„ค์ •ํ•œ๋‹ค. + +
+ +### 1-2. ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ + +- `this ํ‚ค์›Œ๋“œ` + - ๊ฐ™์€ ํด๋ž˜์Šค ๋‚ด๋ถ€์˜ ๋‹ค๋ฅธ ๋ฉ”์„œ๋“œ๋‚˜ ์†์„ฑ์„ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค + - ์ธ์ž๋ฅผ ํ•ด๋‹น ๋ฉ”์„œ๋“œ์— ๋„˜๊ฒจ์ค„ ์ˆ˜ ์žˆ๋‹ค +- `๊ฐ์ฒด` + - ๋ฐ์ดํ„ฐ์™€ ๊ด€๋ จ๋œ ๊ธฐ๋Šฅ์„ ํ•จ๊ป˜ ํฌํ•จํ•˜๋Š” ํ•ญ๋ชฉ์„ ์˜๋ฏธ + - ์ƒ์„ฑ์˜ ๊ธฐ์›์ด๋˜๋Š” ์ •๋ณด ๋ช…์‹œ (X) + - ๋ชจ๋“  ๊ฐ์ฒด๋Š” ์ธ์Šคํ„ด์Šค (X) +- `์ธ์Šคํ„ด์Šค` + - ํด๋ž˜์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ƒ์„ฑ๋œ ๋ฉ”๋ชจ๋ฆฌ์— ํ• ๋‹น๋œ ์‹ค์ œ ๊ตฌํ˜„์ฒด๋ฅผ ์˜๋ฏธ + - ํด๋ž˜์Šค - ์ฟ ํ‚ค๋ฅผ ๋งŒ๋“œ๋Š” ํ‹€ + - ์ธ์Šคํ„ด์Šค - ๊ทธ ํ‹€๋กœ ๋งŒ๋“  ์‹ค์ œ ์ฟ ํ‚ค + - ์ƒ์„ฑ์˜ ๊ธฐ์›์ด ๋˜๋Š” ํด๋ž˜์Šค๋‚˜ ํ”„๋กœํ† ํƒ€์ž…์— ๋Œ€ํ•œ ์ •๋ณด ๋ช…์‹œ (O) + - ๋ชจ๋“  ์ธ์Šคํ„ด์Šค๋Š” ๊ฐ์ฒด (O) + - ์ƒ์„ฑ : const ์ธ์Šคํ„ด์Šค๋ช… = new ํด๋ž˜์Šค๋ช…(๋งค๊ฐœ๋ณ€์ˆ˜); + + ``` javascript + //Dog : ํด๋ž˜์Šค, ์„ค๊ณ„๋„๋‚˜ ํ‹€์˜ ๊ธฐ๋Šฅ + class Dog { + constructor(name) { + this.name = name; + } + + bark() { + console.log(`${this.name} says mung!`); + } + } + + //myDog : Dog ํด๋ž˜์Šค๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์‹ค์ œ ๊ฐœ๋ฅผ ์ƒ์„ฑ + const myDog = new Dog("Bobby"); + + //๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ–ˆ์œผ๋ฏ€๋กœ bark์˜ ๊ธฐ๋Šฅ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ + //์ถœ๋ ฅ : Bobby says mung! + myDog.bark(); + ``` + +- `ํ™”์‚ดํ‘œ ํ•จ์ˆ˜` + - ES6์—์„œ ๋„์ž…๋œ ์ƒˆ๋กœ์šด ํ•จ์ˆ˜ ํ‘œํ˜„ ๋ฐฉ์‹ + - ๊ฐ„๊ฒฐํ•œ ๋ฌธ๋ฒ• - ๋ณธ๋ฌธ์ด ํ•œ ์ค„์ธ ๊ฒฝ์šฐ ์ค‘๊ด„ํ˜ธ ๋ฐ 'return'๋ฌธ ์ƒ๋žต ๊ฐ€๋Šฅ + - this๋ฐ”์ธ๋”ฉ - ์ž์‹ ๋งŒ์˜ this๋ฅผ ๊ฐ€์ง€์ง€ ์•Š๊ณ , ์ƒ์œ„ ์Šค์ฝ”ํ”„ this ์ฐธ์กฐ +- `์ „์—ญ ๊ฐ์ฒด` + - ๋ธŒ๋ผ์šฐ์ € : window ๊ฐ์ฒด, ์ „์—ญ์œผ๋กœ ์„ ์–ธ๋œ ๋ณ€์ˆ˜๋‚˜ ํ•จ์ˆ˜ + - Node.js : global ๊ฐ์ฒด, ๋ช…์‹œ์ ์œผ๋กœ ํ• ๋‹น๋œ ๋ณ€์ˆ˜๋‚˜ ํ•จ์ˆ˜ + - ๋ชจ๋“  ์Šค์ฝ”ํ”„์—์„œ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ฃผ์˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค +- `split` + - ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ + - ํŠน์ • ๊ตฌ๋ถ„์ž๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฌธ์ž์—ด์„ ์—ฌ๋Ÿฌ ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค + + ``` javascript + const str = "apple,banana,grape"; + const fruits = str.split(','); + // ["apple", "banana", "grape"] + ``` + +- `map` + - ๋ฐฐ์—ด ๋ฉ”์„œ๋“œ + - ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์ฃผ์–ด์ง„ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค + - ๊ทธ ๊ฒฐ๊ณผ๋กœ ๊ตฌ์„ฑ๋œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ๋ถˆ๋ณ€์„ฑ - ์›๋ณธ ๋ฐฐ์—ด์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ์ˆœํšŒ - ๋ฐฐ์—ด์˜ ๋ชจ๋“  ์š”์†Œ์— ๋Œ€ํ•ด ์ฃผ์–ด์ง„ ํ•จ์ˆ˜๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•œ๋‹ค From 8af9f1292d6887af055546ef847c435c1a2c7014 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 15:11:22 +0900 Subject: [PATCH 09/53] =?UTF-8?q?refactor:=20(T-1-1)=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EA=B8=B0=EB=8C=80=EA=B0=92=20?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 1d38dff1e..347ef23dd 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -5,15 +5,17 @@ const mockInput = (input) => { Console.readLineAsync = jest.fn(() => Promise.resolve(input)); }; -describe("App class Test", () => { - test("getCarName ์‚ฌ์šฉ์ž ์ž…๋ ฅ", async () => { - const testInput = "pobi,woni,jun"; - mockInput(testInput); +describe("App class", () => { + describe("getCarName method", () => { + test("์‚ฌ์šฉ์ž ์ž…๋ ฅ", async () => { + const testInput = "pobi,woni,jun"; + mockInput(testInput); - const app = new App(); - const result = await app.getCarName(); + const app = new App(); + const result = await app.getCarName(); - expect(Console.readLineAsync).toHaveBeenCalledTimes(1); - expect(result).toBe(testInput); + expect(Console.readLineAsync).toHaveBeenCalledTimes(1); + expect(result).toEqual(["pobi", "woni", "jun"]); // ์ˆ˜์ •๋œ ๋ถ€๋ถ„ + }); }); }); \ No newline at end of file From 1b569326998f5e74c606f7e498f9d6dc8647a4c9 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 15:17:42 +0900 Subject: [PATCH 10/53] =?UTF-8?q?chore:=20eslint=20=EA=B7=9C=EC=B9=99=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.js b/.eslintrc.js index b32af76f2..fb72f754c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,5 +26,6 @@ export default { 'max-depth': ['error', 2], 'max-params': ['error', 3], 'max-lines-per-function': ['error', { max: 10 }], + 'import/extensions': 'off', }, }; From 4af29d202712a42c263061666c9f5cefa4b2a122 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 15:26:45 +0900 Subject: [PATCH 11/53] =?UTF-8?q?feat:=20(T-1-2)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=B2=98=EB=A6=AC=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 347ef23dd..395dc4ca1 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -18,4 +18,41 @@ describe("App class", () => { expect(result).toEqual(["pobi", "woni", "jun"]); // ์ˆ˜์ •๋œ ๋ถ€๋ถ„ }); }); + + describe("sanitizeCarName method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ด๋ฆ„ ์‚ฌ์ด์— ๊ณต๋ฐฑ์ด ์—†์„ ๋•Œ", () => { + const input = "pobi,woni,jun"; + const result = app.sanitizeCarName(input); + expect(result).toEqual(["pobi", "woni", "jun"]); + }); + + test("์ด๋ฆ„ ์•ž๋’ค์— ๊ณต๋ฐฑ์ด ์žˆ์„ ๋•Œ", () => { + const input = " pobi ,woni , jun "; + const result = app.sanitizeCarName(input); + expect(result).toEqual(["pobi", "woni", "jun"]); + }); + + test("๊ณต๋ฐฑ๋งŒ ์žˆ๋Š” ์ด๋ฆ„์ด ์žˆ์„ ๋•Œ", () => { + const input = "pobi, , jun"; + const result = app.sanitizeCarName(input); + expect(result).toEqual(["pobi", "", "jun"]); + }); + + test("์ฝค๋งˆ๊ฐ€ ์—†์„ ๋•Œ", () => { + const input = "pobi woni jun"; + const result = app.sanitizeCarName(input); + expect(result).toEqual(["pobi woni jun"]); + }); + + test("์—ฐ์†์ ์œผ๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ฝค๋งˆ๊ฐ€ ๋‚˜์˜ฌ ๋•Œ", () => { + const input = "pobi,,,woni,,jun"; + const result = app.sanitizeCarName(input); + expect(result).toEqual(["pobi", "", "", "woni", "", "jun"]); + }); + }); }); \ No newline at end of file From 416f1f6c26d7026df496c81862e6c6e4f2971ede Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 15:28:04 +0900 Subject: [PATCH 12/53] =?UTF-8?q?docs:=20(T-1-2)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index a25231326..419696ebe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -87,7 +87,7 @@ 1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ - T-1-1. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - - T-1-2. [] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + - T-1-2. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - T-1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 2. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index 9b870a07e..4c828630d 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -110,10 +110,10 @@ console.log(`${this.name} says mung!`); } } - + //myDog : Dog ํด๋ž˜์Šค๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์‹ค์ œ ๊ฐœ๋ฅผ ์ƒ์„ฑ - const myDog = new Dog("Bobby"); - + const myDog = new Dog("Bobby"); + //๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ–ˆ์œผ๋ฏ€๋กœ bark์˜ ๊ธฐ๋Šฅ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ //์ถœ๋ ฅ : Bobby says mung! myDog.bark(); @@ -143,3 +143,22 @@ - ๊ทธ ๊ฒฐ๊ณผ๋กœ ๊ตฌ์„ฑ๋œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค - ๋ถˆ๋ณ€์„ฑ - ์›๋ณธ ๋ฐฐ์—ด์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค - ์ˆœํšŒ - ๋ฐฐ์—ด์˜ ๋ชจ๋“  ์š”์†Œ์— ๋Œ€ํ•ด ์ฃผ์–ด์ง„ ํ•จ์ˆ˜๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰ํ•œ๋‹ค + +
+ +### T-1-2. ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + +- `matcher` + - ํ…Œ์ŠคํŒ… ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณตํ•˜๋Š” ํ•จ์ˆ˜๋‚˜ ๋ฉ”์„œ๋“œ + - ์‹ค์ œ ๊ฒฐ๊ณผ์™€ ๊ธฐ๋Œ€๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ํ…Œ์ŠคํŠธ์˜ ์„ฑ๊ณต ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋œ๋‹ค +- `toBe` + - ๊ธฐ๋ณธ ํƒ€์ž…์˜ ๊ฐ’์ด ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค +- `not` + - matcher์˜ ๋ฐ˜๋Œ€ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ์ฃผ๋กœ ๋‘ ๊ฐ’์ด ๋‹ค๋ฅธ์ง€ ํ™•์ธํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค +- `toBeTruthy` + - ๊ฐ’์ด boolean์—์„œ true๋กœ ํ‰๊ฐ€๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค +- `toBeFalsy` + - ๊ฐ’์ด boolean์—์„œ false๋กœ ํ‰๊ฐ€๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค +- `toContain` + - ๋ฐฐ์—ด์ด๋‚˜ ๋ฌธ์ž์—ด์ด ํŠน์ • ํ•ญ๋ชฉ ๋˜๋Š” ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค From c7e1dea09db64599e3c242a82dc722e857292319 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:12:59 +0900 Subject: [PATCH 13/53] =?UTF-8?q?docs:=20(1-2)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=B2=98=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=AA=A9=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 419696ebe..7c9828303 100644 --- a/docs/README.md +++ b/docs/README.md @@ -40,8 +40,8 @@ - 1-2. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ - ์ด๋ฆ„ ์ž…๋ ฅ์€ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ - ์ด๋ฆ„์— ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ + - ๋นˆ ๋ฌธ์ž์—ด ์ œ๊ฑฐ - ex) pobi,woni,jun - - 1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - ๊ฐ ์ด๋ฆ„์ด 5๊ธ€์ž ์ดˆ๊ณผ์ธ ๊ฒฝ์šฐ - ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ๋Š” ๊ฒฝ์šฐ From fa9c7a8b42a72d0cce641e86ceded1389d6835d8 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:15:29 +0900 Subject: [PATCH 14/53] =?UTF-8?q?feat:=20(1-2)=20=EB=B9=88=20=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EC=A0=9C=EA=B1=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.js b/src/App.js index 50bc35ac1..a916168d1 100644 --- a/src/App.js +++ b/src/App.js @@ -7,12 +7,12 @@ class App { } async getCarName() { - const inputName = await Console.readLineAsync("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)"); + const inputName = await Console.readLineAsync("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)\n"); return this.sanitizeCarName(inputName); } sanitizeCarName(inputName) { - const sanitizedName = inputName.split(',').map(name => name.trim()); + const sanitizedName = inputName.split(',').map(name => name.trim()).filter(name => name); return sanitizedName; } } From e886ae5a58941295d63194408c06ac8d78173ae1 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:38:58 +0900 Subject: [PATCH 15/53] =?UTF-8?q?refactor:=20(T-1-2)=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B8=B0=EB=8C=80=EA=B0=92=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 395dc4ca1..7fccd8184 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -40,19 +40,13 @@ describe("App class", () => { test("๊ณต๋ฐฑ๋งŒ ์žˆ๋Š” ์ด๋ฆ„์ด ์žˆ์„ ๋•Œ", () => { const input = "pobi, , jun"; const result = app.sanitizeCarName(input); - expect(result).toEqual(["pobi", "", "jun"]); - }); - - test("์ฝค๋งˆ๊ฐ€ ์—†์„ ๋•Œ", () => { - const input = "pobi woni jun"; - const result = app.sanitizeCarName(input); - expect(result).toEqual(["pobi woni jun"]); + expect(result).toEqual(["pobi", "jun"]); }); test("์—ฐ์†์ ์œผ๋กœ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ฝค๋งˆ๊ฐ€ ๋‚˜์˜ฌ ๋•Œ", () => { const input = "pobi,,,woni,,jun"; const result = app.sanitizeCarName(input); - expect(result).toEqual(["pobi", "", "", "woni", "", "jun"]); + expect(result).toEqual(["pobi", "woni", "jun"]); }); }); }); \ No newline at end of file From 71a7c87f86016496b3486fdeb85cc458da4235e1 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:39:58 +0900 Subject: [PATCH 16/53] =?UTF-8?q?docs:=20(1-3)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 7c9828303..d4b88c234 100644 --- a/docs/README.md +++ b/docs/README.md @@ -43,9 +43,9 @@ - ๋นˆ ๋ฌธ์ž์—ด ์ œ๊ฑฐ - ex) pobi,woni,jun - 1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + - ์ด๋ฆ„์ด ๋‘ ๊ฐœ ๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ - ๊ฐ ์ด๋ฆ„์ด 5๊ธ€์ž ์ดˆ๊ณผ์ธ ๊ฒฝ์šฐ - ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ๋Š” ๊ฒฝ์šฐ - - ์ด๋ฆ„ ์ค‘๊ฐ„์— ์‰ผํ‘œ๊ฐ€ ๋“ค์–ด๊ฐ„ ๊ฒฝ์šฐ - throw๋ฌธ์„ ์‚ฌ์šฉํ•ด "[ERROR]" ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ€์ง€๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ From 20416cb004bad9d014960c6f5c205997f5a9967f Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:41:29 +0900 Subject: [PATCH 17/53] =?UTF-8?q?feat:=20(1-3)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=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/App.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/App.js b/src/App.js index a916168d1..659ffc102 100644 --- a/src/App.js +++ b/src/App.js @@ -13,8 +13,33 @@ class App { sanitizeCarName(inputName) { const sanitizedName = inputName.split(',').map(name => name.trim()).filter(name => name); + return this.validateCarName(sanitizedName); + } + + validateCarName(sanitizedName) { + this.#checkMinimumCar(sanitizedName); + this.#checkLength(sanitizedName); + this.#checkDuplicate(sanitizedName); return sanitizedName; } + + #checkMinimumCar(sanitizedName) { + if (sanitizedName.length < 2) { + throw new Error("[ERROR] ์ตœ์†Œ ๋‘ ๋Œ€ ์ด์ƒ์˜ ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + } + + #checkLength(sanitizedName) { + if (sanitizedName.some(name => name.length > 5)) { + throw new Error("[ERROR] ์ž๋™์ฐจ ์ด๋ฆ„์€ 5์ž๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + } + + #checkDuplicate(sanitizedName) { + if (new Set(sanitizedName).size !== sanitizedName.length) { + throw new Error("[ERROR] ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ์Šต๋‹ˆ๋‹ค."); + } + } } const app = new App(); From 657833c2723435b0c9cdc330e1ea84793c1815bc Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:42:23 +0900 Subject: [PATCH 18/53] =?UTF-8?q?docs:=20(1-3)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index d4b88c234..43c4ef685 100644 --- a/docs/README.md +++ b/docs/README.md @@ -42,7 +42,7 @@ - ์ด๋ฆ„์— ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ - ๋นˆ ๋ฌธ์ž์—ด ์ œ๊ฑฐ - ex) pobi,woni,jun - - 1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + - 1-3. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ - ์ด๋ฆ„์ด ๋‘ ๊ฐœ ๋ฏธ๋งŒ์ธ ๊ฒฝ์šฐ - ๊ฐ ์ด๋ฆ„์ด 5๊ธ€์ž ์ดˆ๊ณผ์ธ ๊ฒฝ์šฐ - ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ๋Š” ๊ฒฝ์šฐ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index 4c828630d..c8fffcb93 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -162,3 +162,25 @@ - ๊ฐ’์ด boolean์—์„œ false๋กœ ํ‰๊ฐ€๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค - `toContain` - ๋ฐฐ์—ด์ด๋‚˜ ๋ฌธ์ž์—ด์ด ํŠน์ • ํ•ญ๋ชฉ ๋˜๋Š” ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + +
+ +### 1-3. ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + +- `Set์˜ ๊ฐœ๋…` + - ES6์—์„œ ๋„์ž…๋œ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ + - ์œ ์ผํ•œ ๊ฐ’๋งŒ ์ €์žฅ๋˜๋Š” ์ปฌ๋ ‰์…˜์œผ๋กœ ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค +- `Set์˜ ํŠน์ง•` + - ๊ฐ’์€ ์œ ์ผํ•˜๊ฒŒ ํ•˜๋‚˜๋งŒ ์กด์žฌํ•œ๋‹ค + - ๊ฐ ์š”์†Œ๋Š” ์ˆœ์„œ๋ฅผ ๊ฐ€์ง€์ง€ ์•Š๋Š”๋‹ค + - ๋ฐฐ์—ด๊ณผ ์œ ์‚ฌํ•˜์ง€๋งŒ ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์ด ์ฃผ์š” ์ฐจ์ด์ ์ด๋‹ค +- `์ค‘๋ณต์ฒดํฌ์™€ Set` + - ๋ฐฐ์—ด์— ์ค‘๋ณต๋˜๋Š” ์ด๋ฆ„์ด ์žˆ๋‹ค๋ฉด, Set์œผ๋กœ ๋ณ€ํ™˜ํ–ˆ์„๋•Œ์˜ ๊ธธ์ด์™€ ์›๋ž˜ ๋ฐฐ์—ด์˜ ๊ธธ์ด๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค + - Set์€ ์ค‘๋ณต์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ค‘๋ณต ๊ฐ’์„ ์ œ๊ฑฐํ•˜๊ฒŒ ๋œ๋‹ค + - ๋”ฐ๋ผ์„œ ๋‘ ๊ธธ์ด๋ฅผ ๋น„๊ตํ•จ์œผ๋กœ์จ ์›๋ž˜ ๋ฐฐ์—ด์— ์ค‘๋ณต ์š”์†Œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค +- `_์–ธ๋”์Šค์ฝ”์–ด, #` + - ์ผ๋ฐ˜์ ์œผ๋กœ private ๋˜๋Š” ๋‚ด๋ถ€์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์„œ๋“œ๋‚˜ ๋ณ€์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค + - ์ฆ‰ ๋ณ€์ˆ˜๋‚˜ ๋ฉ”์„œ๋“œ๋ฅผ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋œ๋‹ค๋Š” ์˜๋ฏธ๋ฅผ ์ „๋‹ฌํ•œ๋‹ค + - JavaScript์—๋Š” privateํ‚ค์›Œ๋“œ ๋Œ€์‹  ์ปจ๋ฒค์…˜์œผ๋กœ ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ์‚ฌ์šฉํ•ด์™”๋‹ค + - ES6๋ถ€ํ„ฐ๋Š” #์„ ์‚ฌ์šฉํ•˜์—ฌ privateํ•„๋“œ๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๊ฒŒ๋˜์—ˆ์ง€๋งŒ ๋งŽ์€ ๊ฐœ๋ฐœ์ž๋“ค์€ ์—ฌ์ „ํžˆ ์–ธ๋”์Šค์ฝ”์–ด ์ปจ๋ฒค์…˜์„ ์‚ฌ์šฉํ•œ๋‹ค. + - ์—์–ด๋น„์•ค๋น„ ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ๋Š” ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค \ No newline at end of file From afa85b6b192375501998be350c619f75eca0b3d4 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:43:44 +0900 Subject: [PATCH 19/53] =?UTF-8?q?feat:=20(T-1-3)=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 7fccd8184..e3d571002 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -49,4 +49,26 @@ describe("App class", () => { expect(result).toEqual(["pobi", "woni", "jun"]); }); }); + + describe("Error Handling in validateCarName", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ž๋™์ฐจ ์ด๋ฆ„์ด 5์ž๋ฅผ ์ดˆ๊ณผํ•  ๋•Œ", async () => { + mockInput("pobipobi,woni,jun"); + await expect(app.getCarName()).rejects.toThrow("[ERROR] ์ž๋™์ฐจ ์ด๋ฆ„์€ 5์ž๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + }); + + test("์ž๋™์ฐจ ์ด๋ฆ„์ด ์ค‘๋ณต๋  ๋•Œ", async () => { + mockInput("pobi,pobi,jun"); + await expect(app.getCarName()).rejects.toThrow("[ERROR] ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ์Šต๋‹ˆ๋‹ค."); + }); + + test("์ž๋™์ฐจ ์ด๋ฆ„์ด ์ตœ์†Œ 2๋Œ€ ๋ฏธ๋งŒ์ผ ๋•Œ", async () => { + mockInput("pobi"); + await expect(app.getCarName()).rejects.toThrow("[ERROR] ์ตœ์†Œ ๋‘ ๋Œ€ ์ด์ƒ์˜ ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + }); + }); }); \ No newline at end of file From ab373886501dc874ab8543e2b216ce19d988aa67 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:51:07 +0900 Subject: [PATCH 20/53] =?UTF-8?q?docs:=20(T-1-3)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 43c4ef685..ada4ae0b5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -88,7 +88,7 @@ 1. [] ์ž๋™์ฐจ ์ด๋ฆ„ ์ž…๋ ฅ ๋ฐ›๊ธฐ - T-1-1. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - T-1-2. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - - T-1-3. [] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + - T-1-3. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 2. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ - T-2-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index c8fffcb93..e4610e57a 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -183,4 +183,24 @@ - ์ฆ‰ ๋ณ€์ˆ˜๋‚˜ ๋ฉ”์„œ๋“œ๋ฅผ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•˜๊ฑฐ๋‚˜ ์‚ฌ์šฉํ•˜๋ฉด ์•ˆ๋œ๋‹ค๋Š” ์˜๋ฏธ๋ฅผ ์ „๋‹ฌํ•œ๋‹ค - JavaScript์—๋Š” privateํ‚ค์›Œ๋“œ ๋Œ€์‹  ์ปจ๋ฒค์…˜์œผ๋กœ ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ์‚ฌ์šฉํ•ด์™”๋‹ค - ES6๋ถ€ํ„ฐ๋Š” #์„ ์‚ฌ์šฉํ•˜์—ฌ privateํ•„๋“œ๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ๊ฒŒ๋˜์—ˆ์ง€๋งŒ ๋งŽ์€ ๊ฐœ๋ฐœ์ž๋“ค์€ ์—ฌ์ „ํžˆ ์–ธ๋”์Šค์ฝ”์–ด ์ปจ๋ฒค์…˜์„ ์‚ฌ์šฉํ•œ๋‹ค. - - ์—์–ด๋น„์•ค๋น„ ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ๋Š” ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค \ No newline at end of file + - ์—์–ด๋น„์•ค๋น„ ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ๋Š” ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ๋ถ™์ด๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค + +
+ +### T-1-3. ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + +- `Private ๋ฉ”์„œ๋“œ ํ…Œ์ŠคํŠธ` + - Priavate ๋ฉ”์„œ๋“œ๋Š” ์ง์ ‘ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์—†๋‹ค + - ๊ฐ„์ ‘์ ์œผ๋กœ public ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•ด์•ผํ•œ๋‹ค + - ํŠนํžˆ private ๋ฉ”์„œ๋“œ์— ์˜ํ–ฅ์„ ๋ฐ›๋Š” public ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ๊ทธ ํšจ๊ณผ๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ใ…ฃ์žˆ๋‹ค +- `๋น„๋™๊ธฐ ์—๋Ÿฌ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ` + - await expect(...).rejects.toThrow(...) ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•œ๋‹ค + + ``` javascript + test("๋น„๋™๊ธฐ ์—๋Ÿฌ ์˜ˆ์ƒํ•˜๊ธฐ", async () => { + await expect(asyncFunction()).rejects.toThrow("์˜ˆ์ƒ๋˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€"); + }); + ``` + + - ์ด๋ฅผ ํ†ตํ•ด ๋น„๋™๊ธฐ ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๋”ฐ + - ๊ฒฐ๋ก ์ ์œผ๋กœ, ์ง์ ‘์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์—†๋Š” ์ฝ”๋“œ๋‚˜ ์ƒํ™ฉ๋“ค์—๋„ ๊ฐ„์ ‘์ ์ธ ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด ์ฝ”๋“œ์˜ ํ’ˆ์งˆ์„ ํ™•๋ณดํ•  ์ˆ˜ ์žˆ๋‹ค From 1c07318cd4d1abe5561130ebf040e24d4e8e9249 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 16:58:46 +0900 Subject: [PATCH 21/53] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=AA=A9=EB=A1=9D=202=EB=B2=88,=203=EB=B2=88=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/README.md b/docs/README.md index ada4ae0b5..38ab51597 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,20 +49,20 @@ - throw๋ฌธ์„ ์‚ฌ์šฉํ•ด "[ERROR]" ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ€์ง€๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ -2. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ - - 2-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ์ž๋™์ฐจ ์ƒ์„ฑ - -3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - - 3-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ +2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - 2-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ex) "์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?" - - 3-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ + - 2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ - ex) 3 - - 3-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ + - 2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ - 3๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - ์ž์—ฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ˜•์‹์„ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - ์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ 10 ์ด์ƒ์ธ ๊ฒฝ์šฐ(์ž„์˜ ์„ค์ •) - throw๋ฌธ์„ ์‚ฌ์šฉํ•ด "[ERROR]" ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ€์ง€๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ + +3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ + - 3-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ์ž๋™์ฐจ ์ƒ์„ฑ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - 4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ @@ -90,13 +90,13 @@ - T-1-2. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - T-1-3. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ -2. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ - - T-2-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ +2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ + - T-2-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ + - T-2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ -3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - - T-3-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - - T-3-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ - - T-3-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ +3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ + - T-3-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - T-4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ From 7a29b8b65bfce0f73cf238de7440e4bd2101967d Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 17:18:03 +0900 Subject: [PATCH 22/53] =?UTF-8?q?feat:=20(2-1)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/App.js b/src/App.js index 659ffc102..cdf7cbda2 100644 --- a/src/App.js +++ b/src/App.js @@ -40,6 +40,11 @@ class App { throw new Error("[ERROR] ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ์Šต๋‹ˆ๋‹ค."); } } + + async getRound() { + const round = parseInt(await Console.readLineAsync("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"), 10); + return round; + } } const app = new App(); From 7b646fb8f04d125ead89494b3dc554c3331368ea Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 17:26:39 +0900 Subject: [PATCH 23/53] =?UTF-8?q?docs:=20(2-1)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 38ab51597..7f2372dca 100644 --- a/docs/README.md +++ b/docs/README.md @@ -50,7 +50,7 @@ - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - - 2-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - 2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ex) "์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?" - 2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ - ex) 3 diff --git a/docs/StudyLog.md b/docs/StudyLog.md index e4610e57a..d72e747f0 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -202,5 +202,34 @@ }); ``` - - ์ด๋ฅผ ํ†ตํ•ด ๋น„๋™๊ธฐ ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๋”ฐ + - ์ด๋ฅผ ํ†ตํ•ด ๋น„๋™๊ธฐ ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ์—๋Ÿฌ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์žˆ๋‹ค - ๊ฒฐ๋ก ์ ์œผ๋กœ, ์ง์ ‘์ ์ธ ๋ฐฉ๋ฒ•์œผ๋กœ ํ…Œ์ŠคํŠธ ํ•  ์ˆ˜ ์—†๋Š” ์ฝ”๋“œ๋‚˜ ์ƒํ™ฉ๋“ค์—๋„ ๊ฐ„์ ‘์ ์ธ ๋ฐฉ๋ฒ•์„ ํ†ตํ•ด ์ฝ”๋“œ์˜ ํ’ˆ์งˆ์„ ํ™•๋ณดํ•  ์ˆ˜ ์žˆ๋‹ค + +
+ +--- + +## 2. ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ + +
+ +### 2-1. ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + +- `parseInt` + - ๋ฌธ์ž์—ด์„ ์ •์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ + - ์‚ฌ์šฉ์ž์—๊ฒŒ ์ˆซ์ž๋ฅผ ์ž…๋ ฅ๋ฐ›๋„๋ก ์š”์ฒญํ•˜๋”๋ผ๋„, ๋ฐ˜ํ™˜๊ฐ’์€ ๋ฌธ์ž์—ด ํ˜•ํƒœ๊ฐ€ ๋œ๋‹ค + - ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ž์—ด์„ ์‹ค์ œ ์ •์ˆ˜๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด, parseIntํ•จ์ˆ˜๊ฐ€ ์“ฐ์ธ๋‹ค + - ํ˜•์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค + + ``` javascript + parseInt(string, radix); + ``` + + - String - ๋ณ€ํ™˜๋  ๋ฌธ์ž์—ด + - radix - ๊ธฐ์ˆ˜, ๋ฌธ์ž์—ด์ด ํ‘œ์‹œ๋˜๋Š” ์ง„์ˆ˜๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” 2์—์„œ 36์‚ฌ์ด ์ •์ˆ˜์ด๋‹ค + - ex) 10์€ parseInt์˜ ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ, 10์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ•˜๋ผ๋Š” ์˜๋ฏธ์ด๋‹ค + - radix๋ฅผ ์ƒ๋žตํ•˜๋ฉด ๋ฌธ์ž์—ด์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ์ง„์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค + - 0x ๋˜๋Š” 0X - 16์ง„์ˆ˜๋กœ ๊ฐ„์ฃผ + - 0o - 8์ง„์ˆ˜๋กœ ๊ฐ„์ฃผ + - ๋‚˜๋จธ์ง€ ๊ฒฝ์šฐ - ๊ธฐ๋ณธ์ ์œผ๋กœ 10์ง„์ˆ˜๋กœ ๊ฐ„์ฃผ + - ํ•˜์ง€๋งŒ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด radix ๊ฐ’์„ ํ•ญ์ƒ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค From 08a7b9cb3e144505a2308134478b0420ed801f90 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 17:30:03 +0900 Subject: [PATCH 24/53] =?UTF-8?q?feat:=20(T-2-1)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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 --- __tests__/BeforeRefactor.test.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index e3d571002..3aca34d11 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -15,7 +15,8 @@ describe("App class", () => { const result = await app.getCarName(); expect(Console.readLineAsync).toHaveBeenCalledTimes(1); - expect(result).toEqual(["pobi", "woni", "jun"]); // ์ˆ˜์ •๋œ ๋ถ€๋ถ„ + expect(Console.readLineAsync).toHaveBeenCalledWith("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)\n"); + expect(result).toEqual(["pobi", "woni", "jun"]); }); }); @@ -70,5 +71,22 @@ describe("App class", () => { mockInput("pobi"); await expect(app.getCarName()).rejects.toThrow("[ERROR] ์ตœ์†Œ ๋‘ ๋Œ€ ์ด์ƒ์˜ ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); }); - }); + }); + + describe("getRound method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์‹œ๋„ํ•  ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ", async () => { + const testInput = "5"; + mockInput(testInput); + + const result = await app.getRound(); + + expect(Console.readLineAsync).toHaveBeenCalledWith("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"); + expect(result).toBe(5); + }); + }); }); \ No newline at end of file From 45065bba81ef45a54d9b32c2c733cba11e48cbc1 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 17:43:25 +0900 Subject: [PATCH 25/53] =?UTF-8?q?docs:=20(T-2-1)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 7f2372dca..e292e1bff 100644 --- a/docs/README.md +++ b/docs/README.md @@ -91,7 +91,7 @@ - T-1-3. [โœ”๏ธ] ์ด๋ฆ„ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - - T-2-1. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - T-2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ - T-2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index d72e747f0..c09b57336 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -233,3 +233,69 @@ - 0o - 8์ง„์ˆ˜๋กœ ๊ฐ„์ฃผ - ๋‚˜๋จธ์ง€ ๊ฒฝ์šฐ - ๊ธฐ๋ณธ์ ์œผ๋กœ 10์ง„์ˆ˜๋กœ ๊ฐ„์ฃผ - ํ•˜์ง€๋งŒ ์˜ˆ์ƒ์น˜ ๋ชปํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด radix ๊ฐ’์„ ํ•ญ์ƒ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค + +
+ +### T-2-1. ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + +- `toHaveBeen ๊ด€๋ จ matcher` + - toHaveBeen์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” matcher๋“ค์€ ํŠนํžˆ mockํ•จ์ˆ˜์˜ ํ˜ธ์ถœ๊ณผ ๊ด€๋ จ๋œ ๊ฒ€์ฆ์— ์‚ฌ์šฉ๋œ๋‹ค +- `toHaveBeenCalled` + - mock ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค +- `toHaveBeenCalledTimes` + - mock ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ํšŸ์ˆ˜๋งŒํผ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveBeenCalledTimes(3); + // mockFunc์ด 3๋ฒˆ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ + ``` + +- `toHaveBeenCalledWith` + - mock ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ์ธ์ˆ˜๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveBeenCalledWith(arg1, arg2); + // mockFunc์ด arg1, arg2๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ + ``` + +- `toHaveBeenLastCalledWith` + - mock ํ•จ์ˆ˜๊ฐ€ ๋งˆ์ง€๋ง‰์œผ๋กœ ํ˜ธ์ถœ๋  ๋•Œ ์ฃผ์–ด์ง„ ์ธ์ˆ˜๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveBeenLastCalledWith(arg1, arg2); + // mockFunc์ด ๋งˆ์ง€๋ง‰์œผ๋กœ arg1, arg2๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ + ``` + +- `toHaveBeenNthCalledWith` + - mock ํ•จ์ˆ˜๊ฐ€ n๋ฒˆ์งธ๋กœ ํ˜ธ์ถœ๋  ๋•Œ ํŠน์ • ์ธ์ˆ˜๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveBeenNthCalledWith(1, arg1, arg2); + // mockFunc์ด ์ฒซ ๋ฒˆ์งธ๋กœ arg1, arg2๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ + ``` + +- `toHaveReturned` + - mock ํ•จ์ˆ˜๊ฐ€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค +- `toHaveReturnedWith` + - mock ํ•จ์ˆ˜๊ฐ€ ํŠน์ • ๊ฐ’์„ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveReturnedWith(returnValue); + // mockFunc์ด returnValue๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธ + ``` + +- `toHaveBeenLastReturnedWith` + - mock ํ•จ์ˆ˜๊ฐ€ ๋งˆ์ง€๋ง‰ ํ˜ธ์ถœ์—์„œ ํŠน์ • ๊ฐ’์„ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveBeenLastReturnedWith(returnValue); + // mockFunc์˜ ๋งˆ์ง€๋ง‰ ํ˜ธ์ถœ์—์„œ returnValue๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธ + ``` + +- `toHaveNthReturnedWith` + - mock ํ•จ์ˆ˜์˜ n๋ฒˆ์งธ ํ˜ธ์ถœ์—์„œ ํŠน์ • ๊ฐ’์„ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค + + ``` javascript + expect(mockFunc).toHaveNthReturnedWith(1, returnValue); + // mockFunc์˜ ์ฒซ ๋ฒˆ์งธ ํ˜ธ์ถœ์—์„œ returnValue๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธ + ``` From b1ea3badc58d3abaf8555a7798c09d0dae7631d6 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 17:47:08 +0900 Subject: [PATCH 26/53] =?UTF-8?q?docs:=20(2-2)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index e292e1bff..eb6da7472 100644 --- a/docs/README.md +++ b/docs/README.md @@ -52,7 +52,8 @@ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - 2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ex) "์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?" - - 2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ + - 2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ + - ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ - ex) 3 - 2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ - 3๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ @@ -92,7 +93,7 @@ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - T-2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - - T-2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ํ…Œ์ŠคํŠธ + - T-2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - T-2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ From 58cabb1eee1f09ad6d483f3804a37d7f1d6ebbd0 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 18:23:05 +0900 Subject: [PATCH 27/53] =?UTF-8?q?feat:=20(2-2)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=B2=98=EB=A6=AC=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/App.js | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/App.js b/src/App.js index cdf7cbda2..49fd00050 100644 --- a/src/App.js +++ b/src/App.js @@ -7,43 +7,48 @@ class App { } async getCarName() { - const inputName = await Console.readLineAsync("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)\n"); - return this.sanitizeCarName(inputName); + const inputCar = await Console.readLineAsync("๊ฒฝ์ฃผํ•  ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”.(์ด๋ฆ„์€ ์‰ผํ‘œ(,) ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„)\n"); + return this.sanitizeCarName(inputCar); } - sanitizeCarName(inputName) { - const sanitizedName = inputName.split(',').map(name => name.trim()).filter(name => name); - return this.validateCarName(sanitizedName); + sanitizeCarName(inputCar) { + const sanitizedCar = inputCar.split(',').map(name => name.trim()).filter(name => name); + return this.validateCarName(sanitizedCar); } - validateCarName(sanitizedName) { - this.#checkMinimumCar(sanitizedName); - this.#checkLength(sanitizedName); - this.#checkDuplicate(sanitizedName); - return sanitizedName; + validateCarName(sanitizedCar) { + this.#checkMinimumCar(sanitizedCar); + this.#checkLength(sanitizedCar); + this.#checkDuplicate(sanitizedCar); + return sanitizedCar; } - #checkMinimumCar(sanitizedName) { - if (sanitizedName.length < 2) { + #checkMinimumCar(sanitizedCar) { + if (sanitizedCar.length < 2) { throw new Error("[ERROR] ์ตœ์†Œ ๋‘ ๋Œ€ ์ด์ƒ์˜ ์ž๋™์ฐจ ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); } } - #checkLength(sanitizedName) { - if (sanitizedName.some(name => name.length > 5)) { + #checkLength(sanitizedCar) { + if (sanitizedCar.some(name => name.length > 5)) { throw new Error("[ERROR] ์ž๋™์ฐจ ์ด๋ฆ„์€ 5์ž๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); } } - #checkDuplicate(sanitizedName) { - if (new Set(sanitizedName).size !== sanitizedName.length) { + #checkDuplicate(sanitizedCar) { + if (new Set(sanitizedCar).size !== sanitizedCar.length) { throw new Error("[ERROR] ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ์Šต๋‹ˆ๋‹ค."); } } - async getRound() { - const round = parseInt(await Console.readLineAsync("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"), 10); - return round; + async getRoundNumber() { + const inputRound = await Console.readLineAsync("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"); + return this.sanitizeRoundNumber(inputRound); + } + + sanitizeRoundNumber(inputRound) { + const sanitizedRound = parseInt(inputRound.trim().replace(/\s+/g, ''), 10); + return sanitizedRound; } } From d5fe6e7343a56bfc34bbc9c73f1b02c3edea4bd9 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 18:25:56 +0900 Subject: [PATCH 28/53] =?UTF-8?q?docs:=20(2-2)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index eb6da7472..c2bc90f6a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -52,7 +52,7 @@ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - 2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ex) "์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?" - - 2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ + - 2-2. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ - ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ - ex) 3 - 2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index c09b57336..e1c17a36c 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -299,3 +299,66 @@ expect(mockFunc).toHaveNthReturnedWith(1, returnValue); // mockFunc์˜ ์ฒซ ๋ฒˆ์งธ ํ˜ธ์ถœ์—์„œ returnValue๋ฅผ ๋ฐ˜ํ™˜ํ–ˆ๋Š”์ง€ ํ™•์ธ ``` + +
+ +### 2-2. ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ + +- `trim` + - ๋ฌธ์ž์—ด์˜ ์•ž ๋’ค ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด trim() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค + + ``` javascript + const result = " example ".trim(); + ``` + +- `parseInt` + - ๋ฌธ์ž์—ด ๋‚ด์— ์ˆซ์ž์™€ ๋ฌธ์ž๊ฐ€ ํ•จ๊ป˜ ์žˆ์„ ๋•Œ + - ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๋ฅผ ๋งŒ๋‚˜๋ฉด ํ•ด๋‹น ๋ฌธ์ž๊นŒ์ง€๋งŒ ํŒŒ์‹ฑํ•˜๊ณ , ๊ทธ ์ดํ›„์˜ ๋ฌธ์ž๋Š” ๋ฌด์‹œํ•œ๋‹ค + + ``` javascript + const number = parseInt("123abc", 10); + // number : 123 + ``` + + - ๊ณต๋ฐฑ๋งŒ ์žˆ๋Š” ๋ฌธ์ž์—ด ์ผ๋•Œ + - ๊ฒฐ๊ณผ๊ฐ’์€ NaN์ด๋‹ค + + ``` javascript + const input = " "; + const result = parseInt(input.trim().replace(/\s+/g, ''), 10); + // result : NaN + ``` + +- `replace` + - ๋ฌธ์ž์—ด์˜ ์ผ๋ถ€๋ฅผ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด๋กœ ๋Œ€์ฒดํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•œ๋‹ค + - ๋‘ ๊ฐ€์ง€ ์ธ์ž๋ฅผ ๋ฐ›๋Š”๋‹ค + - ๊ฒ€์ƒ‰ ํŒจํ„ด - ๋Œ€์ฒด๋  ๋ฌธ์ž์—ด ๋˜๋Š” ์ •๊ทœ ํ‘œํ˜„์‹ + - ๋Œ€์ฒด ๋ฌธ์ž์—ด - ๋Œ€์ฒด๋  ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด ๋˜๋Š” ํ•จ์ˆ˜ + + ``` javascript + const str = "Hello, World!"; + const newStr = str.replace("World", "Seojin"); + console.log(newStr); + // ์ถœ๋ ฅ: "Hello, Seojin!" + + ``` + +- `์ •๊ทœํ‘œํ˜„์‹` + - ๋ฌธ์ž์—ด์˜ ํŠน์ • ํŒจํ„ด์„ ์ฐพ๊ธฐ ์œ„ํ•œ ๋„๊ตฌ์ด๋‹ค + - /.../๋กœ ๋‘˜๋Ÿฌ์‹ธ์—ฌ ์žˆ๋Š” ํ˜•์‹์œผ๋กœ ํ‘œํ˜„๋œ๋‹ค + - \d: ๋ชจ๋“  ์ˆซ์ž(0-9์™€ ๋™์ผ) + - \s: ๋ชจ๋“  ๊ณต๋ฐฑ ๋ฌธ์ž(์ŠคํŽ˜์ด์Šค, ํƒญ, ์ค„๋ฐ”๊ฟˆ ๋“ฑ) + - \w: ๋ชจ๋“  ๋‹จ์–ด ๋ฌธ์ž(a-z, A-Z, 0-9, _์™€ ๋™์ผ) + - g: ์ „์—ญ ๊ฒ€์ƒ‰, ๋ฌธ์ž์—ด ๋‚ด์˜ ๋ชจ๋“  ์ผ์น˜ ํ•ญ๋ชฉ์„ ๊ฒ€์ƒ‰ + - i: ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜์ง€ ์•Š๋Š” ๊ฒ€์ƒ‰ + + ``` javascript + const str = "Hello 123 World 456!"; + const newStr = str.replace(/\d+/g, ''); + console.log(newStr); + // ์ถœ๋ ฅ: "Hello World !" + + ``` + +- ๊ฒฐ๋ก  + - ๋ฌธ์ž์—ด์„ ์ ์ ˆํ•˜๊ฒŒ ์ •์ œํ•œ ํ›„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ด๋‹ค \ No newline at end of file From f23742c85cd1fa3ed08fdcf609a041c22b70ce22 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 18:27:38 +0900 Subject: [PATCH 29/53] =?UTF-8?q?feat:=20(T-2-2)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 33 +++++++++++++++++++++++++++++++- docs/README.md | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 3aca34d11..7d85516e7 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -83,10 +83,41 @@ describe("App class", () => { const testInput = "5"; mockInput(testInput); - const result = await app.getRound(); + const result = await app.getRoundNumber(); expect(Console.readLineAsync).toHaveBeenCalledWith("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"); expect(result).toBe(5); }); }); + + describe("sanitizeRoundNumber method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ˆซ์ž์— ๊ณต๋ฐฑ์ด ์—†์„ ๋•Œ", () => { + const input = "3"; + const result = app.sanitizeRoundNumber(input); + expect(result).toEqual(3); + }); + + test("์•ž๋’ค์— ๊ณต๋ฐฑ์ด ์žˆ์„ ๋•Œ", () => { + const input = " 3 "; + const result = app.sanitizeRoundNumber(input); + expect(result).toEqual(3); + }); + + test("๊ณต๋ฐฑ๋งŒ ์žˆ์„ ๋•Œ", () => { + const input = " "; + const result = app.sanitizeRoundNumber(input); + expect(result).toEqual(NaN); + }); + + test("์ˆซ์ž ์‚ฌ์ด์— ๊ณต๋ฐฑ์ด ์žˆ์„ ๋•Œ", () => { + const input = "1 0"; + const result = app.sanitizeRoundNumber(input); + expect(result).toEqual(10); + }); + }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index c2bc90f6a..d11256e0d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -93,7 +93,7 @@ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - T-2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - - T-2-2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + - T-2-2. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - T-2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ From 87854a72a01a600fcd5245896ba88e4017fb071f Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 18:31:38 +0900 Subject: [PATCH 30/53] =?UTF-8?q?docs:=20(2-3)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=83=81=EC=84=B8=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index d11256e0d..4721eab7c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -56,7 +56,7 @@ - ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ - ex) 3 - 2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ - - 3๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ + - 1๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - ์ž์—ฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ˜•์‹์„ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - ์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ 10 ์ด์ƒ์ธ ๊ฒฝ์šฐ(์ž„์˜ ์„ค์ •) - throw๋ฌธ์„ ์‚ฌ์šฉํ•ด "[ERROR]" ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋ฉ”์„ธ์ง€๋ฅผ ๊ฐ€์ง€๋Š” ์˜ˆ์™ธ ๋ฐœ์ƒ From f563c7a4c5d81af5c89af54ca8f8cd35a01a8b23 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 19:32:19 +0900 Subject: [PATCH 31/53] =?UTF-8?q?feat:=20(2-3)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index 49fd00050..d802af8ca 100644 --- a/src/App.js +++ b/src/App.js @@ -13,13 +13,13 @@ class App { sanitizeCarName(inputCar) { const sanitizedCar = inputCar.split(',').map(name => name.trim()).filter(name => name); - return this.validateCarName(sanitizedCar); + return this.#validateCarName(sanitizedCar); } - validateCarName(sanitizedCar) { + #validateCarName(sanitizedCar) { this.#checkMinimumCar(sanitizedCar); - this.#checkLength(sanitizedCar); - this.#checkDuplicate(sanitizedCar); + this.#checkCarLength(sanitizedCar); + this.#checkCarDuplicate(sanitizedCar); return sanitizedCar; } @@ -29,13 +29,13 @@ class App { } } - #checkLength(sanitizedCar) { + #checkCarLength(sanitizedCar) { if (sanitizedCar.some(name => name.length > 5)) { throw new Error("[ERROR] ์ž๋™์ฐจ ์ด๋ฆ„์€ 5์ž๋ฅผ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); } } - #checkDuplicate(sanitizedCar) { + #checkCarDuplicate(sanitizedCar) { if (new Set(sanitizedCar).size !== sanitizedCar.length) { throw new Error("[ERROR] ์ค‘๋ณต๋˜๋Š” ์ž๋™์ฐจ ์ด๋ฆ„์ด ์žˆ์Šต๋‹ˆ๋‹ค."); } @@ -48,8 +48,29 @@ class App { sanitizeRoundNumber(inputRound) { const sanitizedRound = parseInt(inputRound.trim().replace(/\s+/g, ''), 10); + if (inputRound.includes('.') || !Number.isInteger(sanitizedRound)) { + throw new Error("[ERROR] ํšŸ์ˆ˜๋Š” ์ž์—ฐ์ˆ˜ ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค"); + } + return this.#validateRound(sanitizedRound); + } + + #validateRound(sanitizedRound) { + this.#checkMinimumRound(sanitizedRound); + this.#checkMaximumRound(sanitizedRound); return sanitizedRound; } + + #checkMinimumRound(sanitizedRound) { + if (sanitizedRound < 1) { + throw new Error("[ERROR] ์ตœ์†Œ 1 ์ด์ƒ์˜ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + } + + #checkMaximumRound(sanitizedRound) { + if (sanitizedRound > 10) { + throw new Error("[ERROR] ์ตœ๋Œ€ 10 ์ดํ•˜์˜ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + } + } } const app = new App(); From 7586dcdbdc8be6c408b6d94992874d20d0325e3a Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 19:33:12 +0900 Subject: [PATCH 32/53] =?UTF-8?q?docs:=20(2-3)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 4721eab7c..edc5fee27 100644 --- a/docs/README.md +++ b/docs/README.md @@ -55,7 +55,7 @@ - 2-2. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ - ๊ณต๋ฐฑ์ด ๋“ค์–ด๊ฐˆ ๊ฒฝ์šฐ ์ œ๊ฑฐ - ex) 3 - - 2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ + - 2-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ - 1๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - ์ž์—ฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ˜•์‹์„ ์ž…๋ ฅํ•œ ๊ฒฝ์šฐ - ์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ 10 ์ด์ƒ์ธ ๊ฒฝ์šฐ(์ž„์˜ ์„ค์ •) diff --git a/docs/StudyLog.md b/docs/StudyLog.md index e1c17a36c..87f454e33 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -361,4 +361,31 @@ ``` - ๊ฒฐ๋ก  - - ๋ฌธ์ž์—ด์„ ์ ์ ˆํ•˜๊ฒŒ ์ •์ œํ•œ ํ›„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ด๋‹ค \ No newline at end of file + - ๋ฌธ์ž์—ด์„ ์ ์ ˆํ•˜๊ฒŒ ์ •์ œํ•œ ํ›„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ํšจ์œจ์ ์ด๋‹ค + +
+ +### 2-3. ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ + +- `includes()` + - ๋ฌธ์ž์—ด์ด ํŠน์ • ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋œ๋‹ค + - ์ง€์ •๋œ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๋ฉด true, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด false ๋ฐ˜ํ™˜ + - ์ •๊ทœ ํ‘œํ˜„์‹ ์‚ฌ์šฉํ•  ํ•„์š” ์—†์ด ๋น ๋ฅด๊ฒŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค + + ``` javascript + string.includes(searchString, position) + ``` + + - searchString - ๋ฉ”์ธ ๋ฌธ์ž์—ด์—์„œ ์ฐพ์„ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด + - position - ์„ ํƒ ์‚ฌํ•ญ, ๋ฌธ์ž์—ด ๋‚ด์—์„œ ๊ฒ€์ƒ‰์„ ์‹œ์ž‘ํ•  ์œ„์น˜, ๊ธฐ๋ณธ๊ฐ’ 0 + +- `Number.isInteger()` + - ์ „๋‹ฌ๋œ ๊ฐ’์ด ์ •์ˆ˜์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค + - ๊ฐ’์ด ์ •์ˆ˜๋ฉด true, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด false ๋ฐ˜ํ™˜ + - ์‚ฌ์šฉ์ž ์ž…๋ ฅ์ด๋‚˜ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด ๋‹ค์–‘ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๊ฒ€์ฆํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค + + ``` javascript + Number.isInteger(value) + ``` + + - value - ํ™•์ธํ•  ๊ฐ’ \ No newline at end of file From ac2b78f5aad7748c0ae2a952a18221cd0fdea003 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 19:35:25 +0900 Subject: [PATCH 33/53] =?UTF-8?q?feat:=20(T-2-3)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 33 ++++++++++++++++++++++++++------ docs/README.md | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 7d85516e7..585581de1 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -108,16 +108,37 @@ describe("App class", () => { expect(result).toEqual(3); }); - test("๊ณต๋ฐฑ๋งŒ ์žˆ์„ ๋•Œ", () => { - const input = " "; - const result = app.sanitizeRoundNumber(input); - expect(result).toEqual(NaN); - }); - test("์ˆซ์ž ์‚ฌ์ด์— ๊ณต๋ฐฑ์ด ์žˆ์„ ๋•Œ", () => { const input = "1 0"; const result = app.sanitizeRoundNumber(input); expect(result).toEqual(10); }); }); + + describe("Error Handling in validateRound", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ 1 ๋ฏธ๋งŒ์ผ ๋•Œ", async () => { + mockInput("0"); + await expect(app.getRoundNumber()).rejects.toThrow("[ERROR] ์ตœ์†Œ 1 ์ด์ƒ์˜ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + }); + + test("์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ 10 ์ดˆ๊ณผ์ผ ๋•Œ", async () => { + mockInput("11"); + await expect(app.getRoundNumber()).rejects.toThrow("[ERROR] ์ตœ๋Œ€ 10 ์ดํ•˜์˜ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + }); + + test("์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ ์ž์—ฐ์ˆ˜ ํ˜•์‹์ด ์•„๋‹ ๋•Œ", async () => { + mockInput("2.5"); + await expect(app.getRoundNumber()).rejects.toThrow("[ERROR] ํšŸ์ˆ˜๋Š” ์ž์—ฐ์ˆ˜ ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค"); + }); + + test("์‹œ๋„ ํšŸ์ˆ˜๊ฐ€ ๋ฌธ์ž์ผ ๋•Œ", async () => { + mockInput("์‚ผ"); + await expect(app.getRoundNumber()).rejects.toThrow("[ERROR] ํšŸ์ˆ˜๋Š” ์ž์—ฐ์ˆ˜ ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค"); + }); + }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index edc5fee27..36e57f91b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -94,7 +94,7 @@ 2. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฐ›๊ธฐ - T-2-1. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - T-2-2. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ - - T-2-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ + - T-2-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ - T-3-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ From e2effbe66ae5843677356b2a4bc056a5af967b09 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 20:11:08 +0900 Subject: [PATCH 34/53] =?UTF-8?q?feat:=20(3-1)=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B0=92=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=EC=B0=A8=20=EC=83=9D=EC=84=B1=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index d802af8ca..b292b8a0f 100644 --- a/src/App.js +++ b/src/App.js @@ -2,8 +2,13 @@ import { Console } from "@woowacourse/mission-utils"; class App { + constructor() { + this.car = []; + } + async play() { - await this.getCarName(); + const carName = await this.getCarName(); + this.MakeCar(carName); } async getCarName() { @@ -41,6 +46,10 @@ class App { } } + MakeCar(carName) { + this.car = carName.map(name => ({ name })); + } + async getRoundNumber() { const inputRound = await Console.readLineAsync("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"); return this.sanitizeRoundNumber(inputRound); @@ -71,6 +80,8 @@ class App { throw new Error("[ERROR] ์ตœ๋Œ€ 10 ์ดํ•˜์˜ ํšŸ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); } } + + } const app = new App(); From 9d61222e84a32e885d44f9a9ea197ed89df149d1 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 20:12:09 +0900 Subject: [PATCH 35/53] =?UTF-8?q?docs:=20(3-1)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 36e57f91b..abec09ddc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -63,7 +63,7 @@ - ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ฆ‰์‹œ ์ข…๋ฃŒ 3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ - - 3-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ์ž๋™์ฐจ ์ƒ์„ฑ + - 3-1. [โœ”๏ธ] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ์ž๋™์ฐจ ์ƒ์„ฑ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - 4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index 87f454e33..83eb66ada 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -388,4 +388,33 @@ Number.isInteger(value) ``` - - value - ํ™•์ธํ•  ๊ฐ’ \ No newline at end of file + - value - ํ™•์ธํ•  ๊ฐ’ + +
+ +--- + +## 3. ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ + +
+ +### 3-1. ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ + +- `constructor` + - ์ƒ์„ฑ์ž + - ํด๋ž˜์Šค ๋‚ด์—์„œ ๊ฐ์ฒด์˜ ์ดˆ๊ธฐ ์ƒํƒœ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ํŠน๋ณ„ํ•œ ๋ฉ”์„œ๋“œ + - ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ constructor๊ฐ€ ์ž๋™์œผ๋กœ ํ˜ธ์ถœ๋œ๋‹ค + - ์ด๋ฅผ ํ†ตํ•ด ์ดˆ๊ธฐ ์†์„ฑ ๊ฐ’์„ ์„ค์ •ํ•˜๊ฑฐ๋‚˜, ํ•„์š”ํ•œ ์ดˆ๊ธฐํ™” ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค + - ์ƒ์„ฑ์ž๋Š” ํ•„์š”์— ๋”ฐ๋ผ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐ›์„ ์ˆ˜๋„ ์žˆ๋‹ค + - ์ด๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด ์ƒ์„ฑ ์‹œ ์™ธ๋ถ€์—์„œ ๊ฐ’์„ ์ „๋‹ฌํ•˜์—ฌ ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค + + ``` javascript + class App { + constructor() { + this.car = []; + } + } + ``` + + - App ํด๋ž˜์Šค์˜ constructor๋Š” this.car๋ผ๋Š” ๋นˆ ๋ฐฐ์—ด์„ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ์žˆ๋‹ค + - ์ด๋Š” App ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ๋งˆ๋‹ค this.car๊ฐ€ ๋นˆ ๋ฐฐ์—ด๋กœ ์ดˆ๊ธฐํ™”๋œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค From d624b4e7dac23fce395e2bcfd4dbff8d4dc616db Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 20:14:10 +0900 Subject: [PATCH 36/53] =?UTF-8?q?feat:=20(T-3-1)=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B0=92=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=EC=B0=A8=20=EC=83=9D=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=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 --- __tests__/BeforeRefactor.test.js | 20 +++++++++++++++++++- docs/README.md | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 585581de1..bab9d0f19 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -140,5 +140,23 @@ describe("App class", () => { mockInput("์‚ผ"); await expect(app.getRoundNumber()).rejects.toThrow("[ERROR] ํšŸ์ˆ˜๋Š” ์ž์—ฐ์ˆ˜ ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค"); }); - }); + }); + + describe("makeCar method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ž๋™์ฐจ ์ƒ์„ฑํ•˜๊ธฐ", () => { + const carName = ["pobi", "woni", "jun"]; + app.MakeCar(carName); + + expect(app.car).toEqual([ + { name: "pobi" }, + { name: "woni" }, + { name: "jun" } + ]); + }); + }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index abec09ddc..b6868ed64 100644 --- a/docs/README.md +++ b/docs/README.md @@ -97,7 +97,7 @@ - T-2-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ์ž…๋ ฅ ์˜ˆ์™ธ์ฒ˜๋ฆฌ ํ…Œ์ŠคํŠธ 3. [] ์ž๋™์ฐจ ๋งŒ๋“ค๊ธฐ - - T-3-1. [] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ + - T-3-1. [โœ”๏ธ] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - T-4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ From 18fc3b78050b793e558ae98708f02755f6be277c Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 20:38:40 +0900 Subject: [PATCH 37/53] =?UTF-8?q?feat:=20(4-1)=200=20~=209=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=20=EB=AC=B4=EC=9E=91=EC=9C=84=20=EA=B0=92=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index b292b8a0f..43490c5d1 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,5 @@ import { Console } from "@woowacourse/mission-utils"; +import { Random } from "@woowacourse/mission-utils" class App { @@ -8,7 +9,7 @@ class App { async play() { const carName = await this.getCarName(); - this.MakeCar(carName); + this.makeCar(carName); } async getCarName() { @@ -46,7 +47,7 @@ class App { } } - MakeCar(carName) { + makeCar(carName) { this.car = carName.map(name => ({ name })); } @@ -81,7 +82,10 @@ class App { } } - + randomNumber() { + const randomValue = Random.pickNumberInRange(0, 9); + return randomValue; + } } const app = new App(); From 8748d74e1668d2751a7329f283d53c25879031c1 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 20:39:38 +0900 Subject: [PATCH 38/53] =?UTF-8?q?docs:=20(4-1)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index b6868ed64..266479355 100644 --- a/docs/README.md +++ b/docs/README.md @@ -66,7 +66,7 @@ - 3-1. [โœ”๏ธ] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ผ ์ž๋™์ฐจ ์ƒ์„ฑ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - - 4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ + - 4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ - 4-2. [] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ - 4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ - 4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index 83eb66ada..f30688c12 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -418,3 +418,51 @@ - App ํด๋ž˜์Šค์˜ constructor๋Š” this.car๋ผ๋Š” ๋นˆ ๋ฐฐ์—ด์„ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ์žˆ๋‹ค - ์ด๋Š” App ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ƒ์„ฑ๋  ๋•Œ๋งˆ๋‹ค this.car๊ฐ€ ๋นˆ ๋ฐฐ์—ด๋กœ ์ดˆ๊ธฐํ™”๋œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค + +
+ +--- + +## 4. ์ž๋™์ฐจ ๊ฒฝ์ฃผ + +
+ +### 4-1. 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ + +- `pickNumberInRange(startInclusive, endInclusive)` + - ์ˆซ์ž ๋ฒ”์œ„๋ฅผ ์ง€์ •ํ•˜๋ฉด ์‹œ์ž‘ ๋˜๋Š” ๋ ์ˆซ์ž๋ฅผ ํฌํ•จํ•˜์—ฌ ๋ฒ”์œ„์˜ ์ˆซ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ํ˜•์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค + + ``` javascript + Random.pickNumberInRange(1, 10); // 1 + Random.pickNumberInRange(1, 10); // 10 + Random.pickNumberInRange(1, 10); // 4 + Random.pickNumberInRange(1, 10); // 5parseInt(string, radix); + ``` + +- `pickNumberInList(array)` + - ๋ชฉ๋ก์— ์žˆ๋Š” ์ˆซ์ž ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ํ˜•์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค + + ``` javascript + Random.pickNumberInList([1, 3, 10]); // 1 + Random.pickNumberInList([1, 3, 10]); // 10 + Random.pickNumberInList([1, 3, 10]); // 3 + ``` + +- `pickUniqueNumbersInRange(startInclusive, endInclusive, count)` + - ์ˆซ์ž ๋ฒ”์œ„ ๋‚ด์—์„œ ์ง€์ •๋œ ๊ฐœ์ˆ˜๋งŒํผ ๊ฒน์น˜์ง€ ์•Š๋Š” ์ˆซ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ํ˜•์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค + + ``` javascript + Random.pickUniqueNumbersInRange(1, 10, 2); // [1, 2] + Random.pickUniqueNumbersInRange(1, 10, 5); // [1, 10, 7, 8, 5] + ``` + +- `shuffle(array)` + - ๋ฌด์ž‘์œ„๋กœ ์„ž์ธ ์ƒˆ ๋ชฉ๋ก์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค + - ํ˜•์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค + + ``` javascript + Random.shuffle([1, 2, 3, 4, 5]); // [2, 4, 1, 3, 5] + ``` From bd8677640889e17319c3dcda754950cdb2daa6b0 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 21:25:13 +0900 Subject: [PATCH 39/53] =?UTF-8?q?feat:=20(T-4-1)=200=20~=209=20=EC=82=AC?= =?UTF-8?q?=EC=9D=B4=20=EB=AC=B4=EC=9E=91=EC=9C=84=20=EA=B0=92=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 23 ++++++++++++++++++++++- docs/README.md | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index bab9d0f19..17b68b93c 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -150,7 +150,7 @@ describe("App class", () => { test("์ž๋™์ฐจ ์ƒ์„ฑํ•˜๊ธฐ", () => { const carName = ["pobi", "woni", "jun"]; - app.MakeCar(carName); + app.makeCar(carName); expect(app.car).toEqual([ { name: "pobi" }, @@ -159,4 +159,25 @@ describe("App class", () => { ]); }); }); + + describe("getRandomNumber method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ", () => { + const results = new Set(); + + for (let i = 0; i < 100; i++) { + const randomValue = app.getRandomNumber(); + results.add(randomValue); + + expect(randomValue).toBeGreaterThanOrEqual(0); + expect(randomValue).toBeLessThanOrEqual(9); + } + + expect(results.size).toBe(10); + }); + }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 266479355..243c3b33e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -100,7 +100,7 @@ - T-3-1. [โœ”๏ธ] ์ž…๋ ฅ ๊ฐ’์— ๋”ฐ๋ฅธ ์ž๋™์ฐจ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - - T-4-1. [] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ + - T-4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ - T-4-2. [] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ - T-4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ - T-4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ From 40fb64204b57be1a8479f88a5f9e85b38aff10d9 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 21:26:55 +0900 Subject: [PATCH 40/53] =?UTF-8?q?feat:=20(4-2)=204=20=EC=9D=B4=EC=83=81?= =?UTF-8?q?=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=ED=95=9C=EC=B9=B8=20=EC=A0=84?= =?UTF-8?q?=EC=A7=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/App.js | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 243c3b33e..2558267bb 100644 --- a/docs/README.md +++ b/docs/README.md @@ -67,7 +67,7 @@ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - 4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ - - 4-2. [] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ + - 4-2. [โœ”๏ธ] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ - 4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ - 4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ - ์šฐ์Šน์ž ํ•œ ๋ช… ์ด์ƒ ๊ฐ€๋Šฅ diff --git a/src/App.js b/src/App.js index 43490c5d1..89956f9a0 100644 --- a/src/App.js +++ b/src/App.js @@ -47,10 +47,6 @@ class App { } } - makeCar(carName) { - this.car = carName.map(name => ({ name })); - } - async getRoundNumber() { const inputRound = await Console.readLineAsync("์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”?\n"); return this.sanitizeRoundNumber(inputRound); @@ -82,7 +78,24 @@ class App { } } - randomNumber() { + makeCar(carName) { + const getRandom = this.getRandomNumber; + this.car = carName.map(name =>({ + name, + distance: 0, + move() { + if (this.shouldMove()) { + this.distance += 1; + } + }, + shouldMove() { + const randomValue = getRandom(); + return randomValue >= 4; + } + })); + } + + getRandomNumber() { const randomValue = Random.pickNumberInRange(0, 9); return randomValue; } From cacf81bc893311fd0c2e5df8f053a8b2063d64ba Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 21:28:23 +0900 Subject: [PATCH 41/53] =?UTF-8?q?feat:=20(T-4-2)=204=20=EC=9D=B4=EC=83=81?= =?UTF-8?q?=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=ED=95=9C=EC=B9=B8=20=EC=A0=84?= =?UTF-8?q?=EC=A7=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 40 +++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 17b68b93c..780267d95 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -1,5 +1,6 @@ import App from "../src/App.js"; import { Console } from "@woowacourse/mission-utils" +import { Random } from "@woowacourse/mission-utils" const mockInput = (input) => { Console.readLineAsync = jest.fn(() => Promise.resolve(input)); @@ -153,9 +154,9 @@ describe("App class", () => { app.makeCar(carName); expect(app.car).toEqual([ - { name: "pobi" }, - { name: "woni" }, - { name: "jun" } + { name: "pobi", distance: 0, move: expect.any(Function), shouldMove: expect.any(Function) }, + { name: "woni", distance: 0, move: expect.any(Function), shouldMove: expect.any(Function) }, + { name: "jun", distance: 0, move: expect.any(Function), shouldMove: expect.any(Function) } ]); }); }); @@ -180,4 +181,37 @@ describe("App class", () => { expect(results.size).toBe(10); }); }); + + describe("makeCar method movement test", () => { + let app; + let car; + beforeEach(() => { + app = new App(); + const carName = ["testCar"]; + app.makeCar(carName); + car = app.car[0]; + }); + + test("๋žœ๋ค ์ˆซ์ž๊ฐ€ 4 ์ด์ƒ์ด๋ฉด ์ „์ง„", () => { + jest.spyOn(Random, 'pickNumberInRange').mockReturnValue(4); + expect(car.shouldMove()).toBeTruthy(); + + jest.spyOn(Random, 'pickNumberInRange').mockReturnValue(5); + expect(car.shouldMove()).toBeTruthy(); + + jest.spyOn(Random, 'pickNumberInRange').mockReturnValue(9); + expect(car.shouldMove()).toBeTruthy(); + }); + + test("๋žœ๋ค ์ˆซ์ž๊ฐ€ 4 ๋ฏธ๋งŒ์ด๋ฉด ์ •์ง€", () => { + jest.spyOn(Random, 'pickNumberInRange').mockReturnValue(1); + expect(car.shouldMove()).toBeFalsy(); + + jest.spyOn(Random, 'pickNumberInRange').mockReturnValue(2); + expect(car.shouldMove()).toBeFalsy(); + + jest.spyOn(Random, 'pickNumberInRange').mockReturnValue(3); + expect(car.shouldMove()).toBeFalsy(); + }); + }); }); \ No newline at end of file From 6586a2ebc63f132d77a0939645477024fe5f5ddb Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 21:29:04 +0900 Subject: [PATCH 42/53] =?UTF-8?q?docs:=20(T-4-2)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 2558267bb..c1f5d49e4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -101,7 +101,7 @@ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - T-4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ - - T-4-2. [] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ + - T-4-2. [โœ”๏ธ] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ - T-4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ - T-4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index f30688c12..d6a3c7ab2 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -466,3 +466,20 @@ ``` javascript Random.shuffle([1, 2, 3, 4, 5]); // [2, 4, 1, 3, 5] ``` + +
+ +### T-4-2. ๊ฐ’์ด 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ + +- `jest.fn()` + - Jest์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ชจ์˜ ํ•จ์ˆ˜ + - ํ˜ธ์ถœ๋˜์—ˆ์„ ๋•Œ, ์–ด๋–ป๊ฒŒ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€, ๋ช‡ ๋ฒˆ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€, ์–ด๋–ค ์ธ์ž๋กœ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ๋“ฑ์˜ ์ •๋ณด๋ฅผ ์ถ”์ ํ•œ๋‹ค +- `jest.spyOn()` + - ๊ฐ์ฒด์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ŠคํŒŒ์ดํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ + - ํ•ด๋‹น ๋ฉ”์„œ๋“œ๊ฐ€ ์–ด๋–ป๊ฒŒ ํ˜ธ์ถœ๋˜์—ˆ๋Š”์ง€ ๊ฒ€์ฆํ•˜๋ฉด์„œ, ์›๋ž˜์˜ ๊ตฌํ˜„์„ ์œ ์ง€ํ•˜๊ฑฐ๋‚˜ ๋ชจ์˜ ๊ตฌํ˜„์œผ๋กœ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค +- `mockReturnValue(value)` + - ๋ชจ์˜ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ํŠน์ • ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค +- `.mockImplementation(fn)` + - ์›๋ž˜์˜ ํ•จ์ˆ˜ ๋Œ€์‹  ์ œ๊ณต๋œ fn ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค +- `.mockImplementationOnce(fn)` + - ๋‹ค์Œ ํ˜ธ์ถœ์— ๋Œ€ํ•ด์„œ๋งŒ ์ œ๊ณต๋œ fn ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค From 7e12518caa686759aacb443aed56bc6cc8595e98 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:05:18 +0900 Subject: [PATCH 43/53] =?UTF-8?q?feat:=20(4-3)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EB=A7=8C=ED=81=BC=20=EA=B2=BD=EC=A3=BC=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/App.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index c1f5d49e4..690cf5265 100644 --- a/docs/README.md +++ b/docs/README.md @@ -68,7 +68,7 @@ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - 4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ - 4-2. [โœ”๏ธ] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ - - 4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ + - 4-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ - 4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ - ์šฐ์Šน์ž ํ•œ ๋ช… ์ด์ƒ ๊ฐ€๋Šฅ diff --git a/src/App.js b/src/App.js index 89956f9a0..08a53836a 100644 --- a/src/App.js +++ b/src/App.js @@ -9,7 +9,10 @@ class App { async play() { const carName = await this.getCarName(); + const round = await this.getRoundNumber(); + this.makeCar(carName); + this.runRace(round); } async getCarName() { @@ -79,7 +82,7 @@ class App { } makeCar(carName) { - const getRandom = this.getRandomNumber; + const getRandom = this.getRandomNumber.bind(this); this.car = carName.map(name =>({ name, distance: 0, @@ -99,6 +102,12 @@ class App { const randomValue = Random.pickNumberInRange(0, 9); return randomValue; } + + runRace(totalRound) { + for (let i = 0; i < totalRound; i++) { + this.car.forEach(car => car.move()); + } + } } const app = new App(); From 1c28513f5cec3b83dd66b7f0a3d3907f275704e9 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:06:22 +0900 Subject: [PATCH 44/53] =?UTF-8?q?feat:=20(T-4-3)=20=EC=8B=9C=EB=8F=84=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EB=A7=8C=ED=81=BC=20=EA=B2=BD=EC=A3=BC=20?= =?UTF-8?q?=EC=A7=84=ED=96=89=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 780267d95..5764a4320 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -214,4 +214,25 @@ describe("App class", () => { expect(car.shouldMove()).toBeFalsy(); }); }); + + describe("runRace method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ž๋™์ฐจ๋Š” ์ด ํšŸ์ˆ˜ ๋งŒํผ ์›€์ง์—ฌ์•ผ ํ•œ๋‹ค", async () => { + jest.spyOn(app, 'getCarName').mockResolvedValue(["pobi"]); + jest.spyOn(app, 'getRoundNumber').mockResolvedValue(3); + jest.spyOn(Console, 'readLineAsync').mockResolvedValue(""); + + jest.spyOn(app, 'getRandomNumber').mockReturnValue(4); + + await app.play(); + + const moveCount = app.car[0].distance; + + expect(moveCount).toBe(3); + }); + }); }); \ No newline at end of file From 5e9feec28b38d99984911661d25a67aa5f493e35 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:07:08 +0900 Subject: [PATCH 45/53] =?UTF-8?q?docs:=20(T-4-3)=20=EB=B0=B0=EC=9A=B4=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=A0=95=EB=A6=AC=20=EB=B0=8F=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- docs/StudyLog.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 690cf5265..d2acb06e5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -102,7 +102,7 @@ 4. [] ์ž๋™์ฐจ ๊ฒฝ์ฃผ - T-4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ - T-4-2. [โœ”๏ธ] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ - - T-4-3. [] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ + - T-4-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ - T-4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ diff --git a/docs/StudyLog.md b/docs/StudyLog.md index d6a3c7ab2..25a35e1b5 100644 --- a/docs/StudyLog.md +++ b/docs/StudyLog.md @@ -483,3 +483,66 @@ - ์›๋ž˜์˜ ํ•จ์ˆ˜ ๋Œ€์‹  ์ œ๊ณต๋œ fn ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค - `.mockImplementationOnce(fn)` - ๋‹ค์Œ ํ˜ธ์ถœ์— ๋Œ€ํ•ด์„œ๋งŒ ์ œ๊ณต๋œ fn ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค + +
+ +### T-4-3. ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ + +- `๊ธฐ๋ณธ์ ์ธ ์ปจํ…์ŠคํŠธ` + - ํ•จ์ˆ˜๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ „์—ญ ์ปจํ…์ŠคํŠธ์—์„œ ์‹คํ–‰๋œ๋‹ค + - ์ฆ‰, ์ผ๋ฐ˜ ํ•จ์ˆ˜์—์„œ this๋ฅผ ์ฐธ์กฐํ•˜๋ฉด ์ „์—ญ ๊ฐ์ฒด (๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” window)๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋œ๋‹ค + + ``` javascript + function checkThis() { + console.log(this); + } + + checkThis(); // Window + ``` + +- `๋ฉ”์„œ๋“œ ํ˜ธ์ถœ์—์„œ์˜ ์ปจํ…์ŠคํŠธ` + - ๊ฐ์ฒด์˜ ๋ฉ”์„œ๋“œ๋กœ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ, this๋Š” ํ•ด๋‹น ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋œ๋‹ค + + ``` javascript + const obj = { + checkThis: function() { + console.log(this); + } + } + + obj.checkThis(); + ``` + +- `์ปจํ…์ŠคํŠธ ์†์‹ค` + - ํ•˜์ง€๋งŒ, ๋ฉ”์„œ๋“œ ๋‚ด๋ถ€์—์„œ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋‚˜ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋˜๋ฉด this์˜ ๋ฐ”์ธ๋”ฉ์ด ์†์‹ค๋  ์ˆ˜ ์žˆ๋‹ค + + ``` javascript + const obj = { + name: "Seojin", + sayHello: function() { + function innerFunc() { + console.log(this.name); + } + innerFunc(); + } + } + + obj.sayHello(); + ``` + +- `๋ช…์‹œ์  ๋ฐ”์ธ๋”ฉ` + - ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด, bind, call, apply์™€ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•จ์ˆ˜์˜ this ๊ฐ’์„ ๋ช…์‹œ์ ์œผ๋กœ ์„ค์ •ํ•œ๋‹ค + + ``` javascript + const obj = { + name: "Seojin", + sayHello: function() { + const innerFunc = function() { + console.log(this.name); + }.bind(this); + innerFunc(); + } + } + + obj.sayHello(); + ``` From f157e6af4f070af486036e51df52263222f114aa Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:22:18 +0900 Subject: [PATCH 46/53] =?UTF-8?q?feat:=20(4-4)=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=20=EA=B2=BD=EC=A3=BC=EB=A1=9C=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EA=B5=AC=ED=95=98=EA=B8=B0=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 --- docs/README.md | 2 +- src/App.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index d2acb06e5..07aa77e20 100644 --- a/docs/README.md +++ b/docs/README.md @@ -69,7 +69,7 @@ - 4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ - 4-2. [โœ”๏ธ] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ - 4-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ - - 4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ + - 4-4. [โœ”๏ธ] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ - ์šฐ์Šน์ž ํ•œ ๋ช… ์ด์ƒ ๊ฐ€๋Šฅ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ diff --git a/src/App.js b/src/App.js index 08a53836a..403b816ad 100644 --- a/src/App.js +++ b/src/App.js @@ -108,6 +108,11 @@ class App { this.car.forEach(car => car.move()); } } + + getWinner() { + const maxDistance = Math.max(...this.car.map(car => car.distance)); + return this.car.filter(car => car.distance === maxDistance).map(car => car.name); + } } const app = new App(); From a658f7b23dce21543b04b58938dfb36108c85fbe Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:23:13 +0900 Subject: [PATCH 47/53] =?UTF-8?q?feat:=20(T-4-4)=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=20=EA=B2=BD=EC=A3=BC=EB=A1=9C=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EA=B5=AC=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 43 ++++++++++++++++++++++++++++++++ docs/README.md | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 5764a4320..66cd2a3ef 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -235,4 +235,47 @@ describe("App class", () => { expect(moveCount).toBe(3); }); }); + + describe("getWinner method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("๋‹จ๋… ์šฐ์Šน์ž ๊ฒฐ์ •ํ•˜๊ธฐ", () => { + const carName = ["pobi", "woni", "jun"]; + app.makeCar(carName); + + jest.spyOn(Random, 'pickNumberInRange').mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(3); + + app.runRace(3); + + const winner = app.getWinner(); + expect(winner).toEqual(["pobi"]); + }); + + test("๋‹ค์ค‘ ์šฐ์Šน์ž ๊ฒฐ์ •ํ•˜๊ธฐ", () => { + const carName = ["pobi", "woni", "jun"]; + app.makeCar(carName); + + jest.spyOn(Random, 'pickNumberInRange').mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4) + .mockReturnValueOnce(4); + + app.runRace(3); + + const winner = app.getWinner(); + expect(winner).toEqual(["pobi", "woni", "jun"]); + }); + }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 07aa77e20..148466ba5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -103,7 +103,7 @@ - T-4-1. [โœ”๏ธ] 0 ~ 9 ์‚ฌ์ด ๋ฌด์ž‘์œ„ ๊ฐ’ ์ƒ์„ฑ ํ…Œ์ŠคํŠธ - T-4-2. [โœ”๏ธ] 4 ์ด์ƒ์ผ ๊ฒฝ์šฐ ํ•œ์นธ ์ „์ง„ ํ…Œ์ŠคํŠธ - T-4-3. [โœ”๏ธ] ์‹œ๋„ ํšŸ์ˆ˜ ๋งŒํผ ๊ฒฝ์ฃผ ์ง„ํ–‰ ํ…Œ์ŠคํŠธ - - T-4-4. [] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ + - T-4-4. [โœ”๏ธ] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ - T-5-1. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ From 87351bde77af906fd42b52917f7468ccafcb127d Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:34:38 +0900 Subject: [PATCH 48/53] =?UTF-8?q?feat:=20(5-1)=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 3 ++- src/App.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 148466ba5..b7592cf09 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,6 +6,7 @@ ์‹œ๋„ํ•  ํšŸ์ˆ˜๋Š” ๋ช‡ ํšŒ์ธ๊ฐ€์š”? 5 + ์‹คํ–‰ ๊ฒฐ๊ณผ pobi : - woni : jun : - @@ -73,7 +74,7 @@ - ์šฐ์Šน์ž ํ•œ ๋ช… ์ด์ƒ ๊ฐ€๋Šฅ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ - - 5-1. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - 5-1. [โœ”๏ธ] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - "์‹คํ–‰ ๊ฒฐ๊ณผ" - 5-2. [] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ diff --git a/src/App.js b/src/App.js index 403b816ad..9c04eae11 100644 --- a/src/App.js +++ b/src/App.js @@ -13,6 +13,7 @@ class App { this.makeCar(carName); this.runRace(round); + this.printResultHeader(); } async getCarName() { @@ -112,7 +113,11 @@ class App { getWinner() { const maxDistance = Math.max(...this.car.map(car => car.distance)); return this.car.filter(car => car.distance === maxDistance).map(car => car.name); - } + } + + printResultHeader() { + Console.print("์‹คํ–‰ ๊ฒฐ๊ณผ"); + } } const app = new App(); From b41e312e4dc7ea27bb9fb66f49a6be059089ba03 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:35:31 +0900 Subject: [PATCH 49/53] =?UTF-8?q?feat:=20(T-5-1)=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 13 +++++++++++++ docs/README.md | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index 66cd2a3ef..ef1815fbe 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -277,5 +277,18 @@ describe("App class", () => { const winner = app.getWinner(); expect(winner).toEqual(["pobi", "woni", "jun"]); }); + }); + + describe("printResultHeader method", () => { + let app; + beforeEach(() => { + app = new App(); + jest.spyOn(Console, 'print'); + }); + + test("์‹คํ–‰ ๊ฒฐ๊ณผ ์ถœ๋ ฅ", () => { + app.printResultHeader(); + expect(Console.print).toHaveBeenCalledWith("์‹คํ–‰ ๊ฒฐ๊ณผ"); + }); }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index b7592cf09..23551989e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -107,7 +107,7 @@ - T-4-4. [โœ”๏ธ] ๋งˆ์ง€๋ง‰ ๊ฒฝ์ฃผ๋กœ ์ตœ์ข… ์šฐ์Šน์ž ๊ตฌํ•˜๊ธฐ ํ…Œ์ŠคํŠธ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ - - T-5-1. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-5-1. [โœ”๏ธ] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - T-5-2. [] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ 6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ From c4d660428da9c19fbfec10efb42af45185ff741a Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:43:32 +0900 Subject: [PATCH 50/53] =?UTF-8?q?feat:=20(5-2)=20=EA=B0=81=20=EC=B0=A8?= =?UTF-8?q?=EC=88=98=EB=B3=84=20=EC=8B=A4=ED=96=89=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/App.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 23551989e..3bdd79d8f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -76,7 +76,7 @@ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ - 5-1. [โœ”๏ธ] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - "์‹คํ–‰ ๊ฒฐ๊ณผ" - - 5-2. [] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - 5-2. [โœ”๏ธ] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ 6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ - 6-1. [] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ diff --git a/src/App.js b/src/App.js index 9c04eae11..4475fb70c 100644 --- a/src/App.js +++ b/src/App.js @@ -14,6 +14,7 @@ class App { this.makeCar(carName); this.runRace(round); this.printResultHeader(); + this.printRoundResult(); } async getCarName() { @@ -118,6 +119,12 @@ class App { printResultHeader() { Console.print("์‹คํ–‰ ๊ฒฐ๊ณผ"); } + + printRoundResult() { + this.car.forEach(car => { + Console.print(`${car.name} : ${'-'.repeat(car.distance)}`); + }); + } } const app = new App(); From 75a0f7bb29a1821bbd7c74ec6d8e5894d44e207f Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 22:44:24 +0900 Subject: [PATCH 51/53] =?UTF-8?q?feat:=20(T-5-2)=20=EA=B0=81=20=EC=B0=A8?= =?UTF-8?q?=EC=88=98=EB=B3=84=20=EC=8B=A4=ED=96=89=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 23 +++++++++++++++++++++++ docs/README.md | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index ef1815fbe..f0539957c 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -290,5 +290,28 @@ describe("App class", () => { app.printResultHeader(); expect(Console.print).toHaveBeenCalledWith("์‹คํ–‰ ๊ฒฐ๊ณผ"); }); + }); + + describe("printRoundResult method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ์ถœ๋ ฅ", () => { + const carName = ["pobi", "woni", "jun"]; + app.makeCar(carName); + jest.spyOn(Console, 'print').mockImplementation(() => {}); + + app.car[0].distance = 3; // pobi + app.car[1].distance = 2; // woni + app.car[2].distance = 1; // jun + + app.printRoundResult(); + + expect(Console.print).toHaveBeenCalledWith("pobi : ---"); + expect(Console.print).toHaveBeenCalledWith("woni : --"); + expect(Console.print).toHaveBeenCalledWith("jun : -"); + }); }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 3bdd79d8f..582ac9efd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -108,7 +108,7 @@ 5. [] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋‚˜ํƒ€๋‚ด๊ธฐ - T-5-1. [โœ”๏ธ] ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ - - T-5-2. [] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-5-2. [โœ”๏ธ] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ 6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ - T-6-1. [] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ From b5c81f3cdbab59352bbef56a056dd3ecffed9574 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 23:25:33 +0900 Subject: [PATCH 52/53] =?UTF-8?q?feat:=20(6-1)=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EB=A9=94=EC=84=B8=EC=A7=80=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/App.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 582ac9efd..3b37159e6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -79,7 +79,7 @@ - 5-2. [โœ”๏ธ] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ 6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ - - 6-1. [] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ + - 6-1. [โœ”๏ธ] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ - ์šฐ์Šน์ž๊ฐ€ ์—ฌ๋ ค๋ช…์ผ ๊ฒฝ์šฐ ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„ - ex) ์ตœ์ข… ์šฐ์Šน์ž : pobi, jun diff --git a/src/App.js b/src/App.js index 4475fb70c..6ca78b5bb 100644 --- a/src/App.js +++ b/src/App.js @@ -12,9 +12,11 @@ class App { const round = await this.getRoundNumber(); this.makeCar(carName); - this.runRace(round); this.printResultHeader(); - this.printRoundResult(); + this.runRace(round); + + const winner = this.getWinner(); + this.printWinner(winner); } async getCarName() { @@ -108,6 +110,8 @@ class App { runRace(totalRound) { for (let i = 0; i < totalRound; i++) { this.car.forEach(car => car.move()); + this.printRoundResult(); + Console.print("\n"); } } @@ -117,7 +121,7 @@ class App { } printResultHeader() { - Console.print("์‹คํ–‰ ๊ฒฐ๊ณผ"); + Console.print("\n์‹คํ–‰ ๊ฒฐ๊ณผ"); } printRoundResult() { @@ -125,6 +129,10 @@ class App { Console.print(`${car.name} : ${'-'.repeat(car.distance)}`); }); } + + printWinner(winner) { + Console.print(`์ตœ์ข… ์šฐ์Šน์ž : ${winner.join(", ")}`); + } } const app = new App(); From 0f38c8722bd53b91c867b46d226711d2b5eb7e15 Mon Sep 17 00:00:00 2001 From: lucia0929 Date: Wed, 1 Nov 2023 23:26:30 +0900 Subject: [PATCH 53/53] =?UTF-8?q?feat:=20(T-6-1)=20=EC=B5=9C=EC=A2=85=20?= =?UTF-8?q?=EC=9A=B0=EC=8A=B9=EC=9E=90=20=EB=A9=94=EC=84=B8=EC=A7=80=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/BeforeRefactor.test.js | 26 +++++++++++++++++++++++++- docs/README.md | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/__tests__/BeforeRefactor.test.js b/__tests__/BeforeRefactor.test.js index f0539957c..137f8da46 100644 --- a/__tests__/BeforeRefactor.test.js +++ b/__tests__/BeforeRefactor.test.js @@ -288,7 +288,7 @@ describe("App class", () => { test("์‹คํ–‰ ๊ฒฐ๊ณผ ์ถœ๋ ฅ", () => { app.printResultHeader(); - expect(Console.print).toHaveBeenCalledWith("์‹คํ–‰ ๊ฒฐ๊ณผ"); + expect(Console.print).toHaveBeenCalledWith("\n์‹คํ–‰ ๊ฒฐ๊ณผ"); }); }); @@ -313,5 +313,29 @@ describe("App class", () => { expect(Console.print).toHaveBeenCalledWith("woni : --"); expect(Console.print).toHaveBeenCalledWith("jun : -"); }); + }); + + describe("printWinner method", () => { + let app; + beforeEach(() => { + app = new App(); + }); + + test("์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ", () => { + app.car = [ + { name: "pobi", distance: 5 }, + { name: "woni", distance: 5 }, + { name: "jun", distance: 3 } + ]; + + const printSpy = jest.spyOn(Console, 'print'); + + const winners = app.getWinner(); + app.printWinner(winners); + + expect(printSpy).toHaveBeenCalledWith("์ตœ์ข… ์šฐ์Šน์ž : pobi, woni"); + + printSpy.mockRestore(); + }); }); }); \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 3b37159e6..0db87d98c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -111,7 +111,7 @@ - T-5-2. [โœ”๏ธ] ๊ฐ ์ฐจ์ˆ˜๋ณ„ ์‹คํ–‰ ๊ฒฐ๊ณผ ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ 6. [] ์ตœ์ข… ์šฐ์Šน์ž ๋‚˜ํƒ€๋‚ด๊ธฐ - - T-6-1. [] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ + - T-6-1. [โœ”๏ธ] ์ตœ์ข… ์šฐ์Šน์ž ๋ฉ”์„ธ์ง€ ์ถœ๋ ฅ ํ…Œ์ŠคํŠธ ---