From 87a94c07ae52f434fd4a92d9f7cead9d84d9b2c4 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 5 Jul 2024 15:26:12 +0900 Subject: [PATCH 01/73] =?UTF-8?q?build:=20eslint=20&=20prettier=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 3 + .prettierrc | 11 + eslint.config.js | 9 + package-lock.json | 1127 +++++++++++++++++++++++++++++++++++++++++++-- package.json | 8 +- 5 files changed, 1118 insertions(+), 40 deletions(-) create mode 100644 .eslintrc create mode 100644 .prettierrc create mode 100644 eslint.config.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..62f705b --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": ["plugin:prettier/recommended"], +} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..6923972 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,11 @@ +{ + "semi": true, + "endOfLine": "lf", + "tabWidth": 2, + "printWidth": 80, + "singleQuote": true, + "bracketSameLine": false, + "bracketSpacing": true, + "arrowParens": "always", + "singleAttributePerLine": true +} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..a027e87 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,9 @@ +import globals from 'globals'; +import pluginJs from '@eslint/js'; +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; + +export default [ + { languageOptions: { globals: { ...globals.browser, ...globals.node } } }, + pluginJs.configs.recommended, + eslintPluginPrettierRecommended, +]; diff --git a/package-lock.json b/package-lock.json index 2e1d661..4d2383f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,12 @@ "version": "1.0.0", "license": "ISC", "devDependencies": { + "@eslint/js": "^9.6.0", + "eslint": "^9.6.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.1.3", + "globals": "^15.8.0", + "prettier": "3.3.2", "vitest": "^1.6.0" } }, @@ -380,6 +386,135 @@ "node": ">=12" } }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", + "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.0.tgz", + "integrity": "sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==", + "dev": true, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/config-array": { + "version": "0.17.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.0.tgz", + "integrity": "sha512-A68TBu6/1mHHuc5YJL0U0VVeGNiklLAL6rRmhTCP2B5XjWLMnrX+HkO+IAXyHvks5cyyY1jjK5ITPQ1HGS2EVA==", + "dev": true, + "dependencies": { + "@eslint/object-schema": "^2.1.4", + "debug": "^4.3.1", + "minimatch": "^3.1.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", + "integrity": "sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==", + "dev": true, + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^10.0.1", + "globals": "^14.0.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@eslint/js": { + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.6.0.tgz", + "integrity": "sha512-D9B0/3vNg44ZeWbYMpBoXqNP4j6eQD5vNwIlGAuFRRzK/WtT/jvDQW3Bi9kkf3PMDMlM7Yi+73VLUsn5bJcl8A==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", + "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/retry": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.0.tgz", + "integrity": "sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==", + "dev": true, + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, "node_modules/@jest/schemas": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", @@ -398,6 +533,53 @@ "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", "dev": true }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.18.0", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.18.0.tgz", @@ -699,6 +881,15 @@ "node": ">=0.4.0" } }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/acorn-walk": { "version": "8.3.3", "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.3.tgz", @@ -711,6 +902,31 @@ "node": ">=0.4.0" } }, + "node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/ansi-styles": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", @@ -723,6 +939,12 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, "node_modules/assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", @@ -732,6 +954,22 @@ "node": "*" } }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -741,6 +979,15 @@ "node": ">=8" } }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/chai": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.1.tgz", @@ -759,6 +1006,37 @@ "node": ">=4" } }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chalk/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/check-error": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", @@ -771,6 +1049,30 @@ "node": "*" } }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true + }, "node_modules/confbox": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.7.tgz", @@ -820,6 +1122,12 @@ "node": ">=6" } }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, "node_modules/diff-sequences": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", @@ -867,6 +1175,189 @@ "@esbuild/win32-x64": "0.21.5" } }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.6.0.tgz", + "integrity": "sha512-ElQkdLMEEqQNM9Njff+2Y4q2afHk7JpkPvrd7Xh7xefwgQynqPxwf55J7di9+MEibWUGdNjFF9ITG9Pck5M84w==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.6.1", + "@eslint/config-array": "^0.17.0", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "9.6.0", + "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.3.0", + "@nodelib/fs.walk": "^1.2.8", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^8.0.1", + "eslint-visitor-keys": "^4.0.0", + "espree": "^10.1.0", + "esquery": "^1.5.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^8.0.0", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "is-path-inside": "^3.0.3", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3", + "strip-ansi": "^6.0.1", + "text-table": "^0.2.0" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + } + }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", + "integrity": "sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.8.6" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": "*", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, + "node_modules/eslint-scope": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.1.tgz", + "integrity": "sha512-pL8XjgP4ZOmmwfFE8mEhSxA7ZY4C+LWyqjQ3o4yWkkmD0qcMT9kkW3zWHOczhWcjTSgqycYAgwSlXvZltv65og==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", + "integrity": "sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA==", + "dev": true, + "dependencies": { + "acorn": "^8.12.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^4.0.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", + "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "dev": true, + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, "node_modules/estree-walker": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", @@ -876,71 +1367,257 @@ "@types/estree": "^1.0.0" } }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/execa": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/execa/-/execa-8.0.1.tgz", "integrity": "sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==", "dev": true, "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^8.0.1", - "human-signals": "^5.0.0", - "is-stream": "^3.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^5.1.0", - "onetime": "^6.0.0", - "signal-exit": "^4.1.0", - "strip-final-newline": "^3.0.0" + "cross-spawn": "^7.0.3", + "get-stream": "^8.0.1", + "human-signals": "^5.0.0", + "is-stream": "^3.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^5.1.0", + "onetime": "^6.0.0", + "signal-exit": "^4.1.0", + "strip-final-newline": "^3.0.0" + }, + "engines": { + "node": ">=16.17" + }, + "funding": { + "url": "https://github.com/sindresorhus/execa?sponsor=1" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "node_modules/fastq": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", + "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", + "dev": true, + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/file-entry-cache": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", + "dev": true, + "dependencies": { + "flat-cache": "^4.0.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat-cache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", + "dev": true, + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.4" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/flatted": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", + "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", + "dev": true + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-func-name": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/get-stream": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz", + "integrity": "sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==", + "dev": true, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/globals": { + "version": "15.8.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.8.0.tgz", + "integrity": "sha512-VZAJ4cewHTExBWDHR6yptdIBlx9YSSZuwojj9Nt5mBRXQzrKakDsVKQ1J63sklLvzAJm0X5+RpO4i3Y2hcOnFw==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/human-signals": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", + "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==", + "dev": true, + "engines": { + "node": ">=16.17.0" + } + }, + "node_modules/ignore": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", + "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" }, "engines": { - "node": ">=16.17" + "node": ">=6" }, "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + "node": ">=0.8.19" } }, - "node_modules/get-func-name": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", - "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, "engines": { - "node": "*" + "node": ">=0.10.0" } }, - "node_modules/get-stream": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-8.0.1.tgz", - "integrity": "sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==", + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, - "engines": { - "node": ">=16" + "dependencies": { + "is-extglob": "^2.1.1" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "engines": { + "node": ">=0.10.0" } }, - "node_modules/human-signals": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", - "integrity": "sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==", + "node_modules/is-path-inside": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", + "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", "dev": true, "engines": { - "node": ">=16.17.0" + "node": ">=8" } }, "node_modules/is-stream": { @@ -967,6 +1644,58 @@ "integrity": "sha512-WriZw1luRMlmV3LGJaR6QOJjWwgLUTf89OwT2lUOyjX2dJGBwgmIkbcz+7WFZjrZM635JOIR517++e/67CP9dQ==", "dev": true }, + "node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/local-pkg": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.5.0.tgz", @@ -983,6 +1712,27 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, "node_modules/loupe": { "version": "2.3.7", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", @@ -1019,6 +1769,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/mlly": { "version": "1.7.1", "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.7.1.tgz", @@ -1055,6 +1817,12 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true + }, "node_modules/npm-run-path": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-5.3.0.tgz", @@ -1097,6 +1865,23 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/optionator": { + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", + "dev": true, + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/p-limit": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-5.0.0.tgz", @@ -1112,6 +1897,69 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate/node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate/node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -1181,6 +2029,42 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/prettier": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz", + "integrity": "sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -1195,12 +2079,60 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/react-is": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==", "dev": true }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true, + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, "node_modules/rollup": { "version": "4.18.0", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.18.0.tgz", @@ -1236,6 +2168,29 @@ "fsevents": "~2.3.2" } }, + "node_modules/run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -1296,6 +2251,18 @@ "integrity": "sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==", "dev": true }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/strip-final-newline": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", @@ -1308,6 +2275,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/strip-literal": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-2.1.0.tgz", @@ -1320,6 +2299,40 @@ "url": "https://github.com/sponsors/antfu" } }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/synckit": { + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", + "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", + "dev": true, + "dependencies": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, + "node_modules/text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, "node_modules/tinybench": { "version": "2.8.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.8.0.tgz", @@ -1344,6 +2357,24 @@ "node": ">=14.0.0" } }, + "node_modules/tslib": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz", + "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", + "dev": true + }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", @@ -1359,6 +2390,15 @@ "integrity": "sha512-Y7HYmWaFwPUmkoQCUIAYpKqkOf+SbVj/2fJJZ4RJMCfZp0rTGwRbzQD+HghfnhKOjL9E01okqz+ncJskGYfBNw==", "dev": true }, + "node_modules/uri-js": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "dev": true, + "dependencies": { + "punycode": "^2.1.0" + } + }, "node_modules/vite": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/vite/-/vite-5.3.1.tgz", @@ -1532,6 +2572,15 @@ "node": ">=8" } }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/yocto-queue": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz", diff --git a/package.json b/package.json index 1fe342c..0426eee 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "description": "로또 미션을 통해서 학습하는 클린코드", "main": "./src/main.js", - "type": "module", + "type": "module", "scripts": { "start": "node src/main.js", "start:watch": "node --watch src/main.js", @@ -13,6 +13,12 @@ "author": "", "license": "ISC", "devDependencies": { + "@eslint/js": "^9.6.0", + "eslint": "^9.6.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.1.3", + "globals": "^15.8.0", + "prettier": "3.3.2", "vitest": "^1.6.0" } } From bff324c309c01f3d452ffe3b90e18b58867a4583 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:46:40 +0900 Subject: [PATCH 02/73] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/sum.test.js | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/__tests__/sum.test.js diff --git a/src/__tests__/sum.test.js b/src/__tests__/sum.test.js deleted file mode 100644 index efc011c..0000000 --- a/src/__tests__/sum.test.js +++ /dev/null @@ -1,11 +0,0 @@ -import { describe, test, expect } from "vitest"; - -function sum(...args) { - return args.reduce((a, b) => a+ b); -} - -describe('예제 테스트입니다.', () => { - test('sum > ', () => { - expect(sum(1,2,3,4,5)).toBe(15); - }) -}) From 3a47b4f1a6d858113e9cd9c622e03ee8a5c82ebf Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:46:50 +0900 Subject: [PATCH 03/73] =?UTF-8?q?feat:=20View=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/View.js | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/View/View.js diff --git a/src/View/View.js b/src/View/View.js new file mode 100644 index 0000000..8b4d437 --- /dev/null +++ b/src/View/View.js @@ -0,0 +1,112 @@ +import { readLineAsync } from '../utils/readline.js'; +import LottoRule from '../domain/LottoRule.js'; + +export default class View { + constructor() { + this.rl = readLineAsync; + } + + async input( + message, + options = { + postProcessFn: undefined, + errorCheckFn: undefined, + }, + ) { + const { postProcessFn, errorCheckFn } = options; + const postProcessFnError = View.getPostProcessFnError(postProcessFn); + const errorCheckFnError = View.getErrorCheckFnError(errorCheckFn); + + if (postProcessFnError !== undefined || errorCheckFnError !== undefined) { + throw new Error(postProcessFnError || errorCheckFnError); + } + + while (true) { + const inputValue = await this.rl(message); + const postInputValue = postProcessFn + ? postProcessFn(inputValue) + : inputValue; + const error = errorCheckFn + ? errorCheckFn(postInputValue) + : postInputValue; + + if (error === undefined) { + return postInputValue; + } + + console.log(error); + } + } + + async inputPurchaseLotto( + options = { + postProcessFn: undefined, + errorCheckFn: undefined, + }, + ) { + return this.input('> 구입금액을 입력해 주세요:', options); + } + + async inputWinLotto( + options = { + postProcessFn: undefined, + errorCheckFn: undefined, + }, + ) { + return this.input('> 당첨 번호를 콤마(,)로 구분해 입력해 주세요:', options); + } + + async inputBonusNumber( + options = { + postProcessFn: undefined, + errorCheckFn: undefined, + }, + ) { + return this.input('> 보너스 번호를 입력해 주세요: ', options); + } + + printPurchaseLotto(quantity) { + console.log(`${quantity}개를 구매했습니다.`); + console.log('\n'); + } + + printAllLotto(lottos) { + lottos.forEach((lotto) => { + console.log(lotto); + }); + console.log('\n'); + } + + printAccordByRank(rankInfo) { + const ranks = Object.keys(rankInfo); + + console.log('당첨 통계'); + console.log('--------------------'); + + ranks.forEach((rank) => { + console.log( + `${LottoRule.ACCROD_STRING_BY_RANK[rank]} - ${rankInfo[rank]}개`, + ); + }); + } + + printRate(rate) { + console.log(`총 수익률은 ${rate}% 입니다.`); + } + + static getPostProcessFnError(postProcessFn) { + if (postProcessFn !== undefined && typeof postProcessFn !== 'function') { + return '후처리 함수(postProcessFn)는 함수 타입이어야 합니다.'; + } + + return undefined; + } + + static getErrorCheckFnError(errorCheckFn) { + if (errorCheckFn !== undefined && typeof errorCheckFn !== 'function') { + return '에러 검사 함수(errorCheckFn)는 함수 타입이어야 합니다.'; + } + + return undefined; + } +} From 23d2915003d9383ad7cbab3aecbf5e7f9e98ddb4 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:47:50 +0900 Subject: [PATCH 04/73] =?UTF-8?q?feat:=20=EB=8F=88=EC=9D=84=20=EC=BD=A4?= =?UTF-8?q?=EB=A7=88=EA=B0=80=20=EC=9E=88=EB=8A=94=20=EB=AC=B8=EC=9E=90?= =?UTF-8?q?=EC=97=B4=EB=A1=9C=20=EB=B3=80=EA=B2=BD=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=9C=A0=ED=8B=B8=20=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/String.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/utils/String.js diff --git a/src/utils/String.js b/src/utils/String.js new file mode 100644 index 0000000..0b23773 --- /dev/null +++ b/src/utils/String.js @@ -0,0 +1,13 @@ +export function makeMoneyForm(money) { + const reversedMoney = String(money).split('').reverse(); + const stack = []; + + reversedMoney.forEach((num, index) => { + if (reversedMoney[index + 1] !== undefined && index % 3 === 0) { + stack.push(','); + } + stack.push(num); + }); + + return stack.reverse().join(''); +} From 1465ccef6f85b954cd708d1b17beb4e77626cf60 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:48:01 +0900 Subject: [PATCH 05/73] =?UTF-8?q?feat:=20readline=20=EC=9C=A0=ED=8B=B8?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/readline.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/utils/readline.js diff --git a/src/utils/readline.js b/src/utils/readline.js new file mode 100644 index 0000000..78e3d39 --- /dev/null +++ b/src/utils/readline.js @@ -0,0 +1,23 @@ +import readline from 'readline'; + +export function readLineAsync(query) { + return new Promise((resolve, reject) => { + if (arguments.length !== 1) { + reject(new Error('arguments must be 1')); + } + + if (typeof query !== 'string') { + reject(new Error('query must be string')); + } + + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + + rl.question(query, (input) => { + rl.close(); + resolve(input); + }); + }); +} From a3ca1f473f925244b9be6ca1b2d9d3d0a5b7a23d Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:48:24 +0900 Subject: [PATCH 06/73] =?UTF-8?q?refactoring:=20=EC=9C=A0=ED=8B=B8=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/String.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/String.js b/src/utils/String.js index 0b23773..f909541 100644 --- a/src/utils/String.js +++ b/src/utils/String.js @@ -1,4 +1,4 @@ -export function makeMoneyForm(money) { +export function changeStandardMoneyString(money) { const reversedMoney = String(money).split('').reverse(); const stack = []; From 42993bf304d3a2d6d515f8ca61644016dc443d04 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:48:37 +0900 Subject: [PATCH 07/73] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=B4=EC=A3=BC?= =?UTF-8?q?=EB=8A=94=20=EC=9C=A0=ED=8B=B8=ED=95=A8=EC=88=98=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 --- src/utils/Number.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/utils/Number.js diff --git a/src/utils/Number.js b/src/utils/Number.js new file mode 100644 index 0000000..14f3a6a --- /dev/null +++ b/src/utils/Number.js @@ -0,0 +1,3 @@ +export function generateRandomNumber(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} From 5ec290a342a6ecab370ec9fd71c7b1e0e7bd27b8 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:50:37 +0900 Subject: [PATCH 08/73] =?UTF-8?q?feat:=20=EB=B0=B0=EC=97=B4=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=EA=B3=BC=20=EA=B4=80=EB=A0=A8=EB=90=9C=20=EC=9C=A0?= =?UTF-8?q?=ED=8B=B8=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - accord: 비교할 두 배열을 받아서 일치하는 개수를 반환하는 함수 - generateRandomNumberArray: 배열의 개수를 받아서 그 개수만큼 랜덤 번호를 생성하는 함수 --- src/utils/Array.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/utils/Array.js diff --git a/src/utils/Array.js b/src/utils/Array.js new file mode 100644 index 0000000..9148894 --- /dev/null +++ b/src/utils/Array.js @@ -0,0 +1,20 @@ +import { generateRandomNumber } from './Number.js'; + +export function accord(base, compare) { + const baseSet = new Set(base); + + return compare.reduce( + (prev, curr) => (baseSet.has(curr) ? prev + 1 : prev), + 0, + ); +} + +export function generateRandomNumberArray(amount, min, max) { + const set = new Set(); + + while (set.size < amount) { + set.add(generateRandomNumber(min, max)); + } + + return [...set].sort((a, b) => a - b); +} From a49de74abfcf7e6d5ad0b50f60f0c5eb53f1e079 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:52:31 +0900 Subject: [PATCH 09/73] =?UTF-8?q?feat:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/Lotto.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/domain/Lotto.js diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js new file mode 100644 index 0000000..8de624f --- /dev/null +++ b/src/domain/Lotto.js @@ -0,0 +1,35 @@ +export default class Lotto { + _lotto; + + constructor(lotto) { + this.set(lotto); + } + + set(lotto) { + const lottoError = Lotto.getLottoError(lotto); + + if (lottoError !== undefined) { + return lottoError; + } + + this._lotto = lotto; + } + + get() { + return [...this._lotto]; + } + + static getLottoError(lotto) { + const commonError = Lotto.getCommonLottoError(lotto); + + if (commonError !== undefined) return commonError; + + const lottoSet = new Set(lotto); + + if (lottoSet.size !== Lotto.DEFAULT_LENGTH) { + return `일반 로또 번호의 개수는 ${Lotto.DEFAULT_LENGTH}개 여야 합니다.`; + } + + return undefined; + } +} From aefd1e2bd8957e9fab37dc3d24e74fc71b2cf3e3 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:52:44 +0900 Subject: [PATCH 10/73] =?UTF-8?q?feat:=20LottoRule=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoRule.js | 90 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/domain/LottoRule.js diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js new file mode 100644 index 0000000..ae8b3ef --- /dev/null +++ b/src/domain/LottoRule.js @@ -0,0 +1,90 @@ +import { generateRandomNumberArray } from '../utils/Array.js'; +import { changeStandardMoneyString } from '../utils/String.js'; + +export default class LottoRule { + static RANK_BY_ACCORD = Object.freeze({ + 3: { bonus: 5, base: 3 }, + 4: { bonus: 4, base: 4 }, + 5: { bonus: 2, base: 3 }, + 6: { bonus: 1, base: 1 }, + }); + static REWARD = Object.freeze({ + 1: 200000000, + 2: 30000000, + 3: 1500000, + 4: 50000, + 5: 5000, + }); + static ACCROD_STRING_BY_RANK = Object.freeze({ + 1: `6개 일치 ${changeStandardMoneyString(LottoRule.REWARD[1])}`, + 2: `5개 일치, 보너스 볼 일치 ${changeStandardMoneyString(LottoRule.REWARD[2])}`, + 3: `5개 일치 ${changeStandardMoneyString(LottoRule.REWARD[3])}`, + 4: `4개 일치 ${changeStandardMoneyString(LottoRule.REWARD[4])}`, + 5: `3개 일치 ${changeStandardMoneyString(LottoRule.REWARD[5])}`, + }); + + static get MAX_NUMBER() { + return 45; + } + + static get MIN_NUMBER() { + return 1; + } + + static get MONEY() { + return 1000; + } + + static get DEFAULT_LENGTH() { + return 6; + } + + static generateLottoNumber() { + return generateRandomNumberArray( + LottoRule.DEFAULT_LENGTH, + LottoRule.MIN_NUMBER, + LottoRule.MAX_NUMBER, + ); + } + + static calculateQuantity(money) { + const moneyError = LottoRule.getMoneyError(money); + + if (moneyError !== undefined) { + throw new Error(moneyError); + } + + return Math.floor(money / LottoRule.MONEY); + } + + static getMoneyError(money) { + if (typeof money !== 'number') { + return '돈은 숫자 타입으로 입력받아야 합니다.'; + } + + if (money < LottoRule.MONEY) { + return `구입금액은 최소 ${LottoRule.MONEY}원부터 가능합니다.`; + } + + return undefined; + } + + static getCommonLottoError(lotto) { + if (Array.isArray(lotto) === false) { + return 'lotto는 배열 형식이어야 합니다.'; + } + + if ( + lotto.some( + (num) => + typeof num !== 'number' || + num < LottoRule.MIN_NUMBER || + num > LottoRule.MAX_NUMBER, + ) + ) { + return 'lotto배열의 요소는 숫자로 이뤄져야 합니다.'; + } + + return undefined; + } +} From 28bd6f29dab3e2d9a2c3f304840407404cbe8b9c Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:52:59 +0900 Subject: [PATCH 11/73] =?UTF-8?q?feat:=20WinLotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/WinLotto.js | 78 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/domain/WinLotto.js diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js new file mode 100644 index 0000000..b2b3b75 --- /dev/null +++ b/src/domain/WinLotto.js @@ -0,0 +1,78 @@ +import Lotto from './Lotto.js'; +import LottoRule from './LottoRule.js'; +import { accord } from '../utils/Array.js'; + +export default class WinLotto extends Lotto { + _winLotto; + + constructor(lotto) { + super(lotto); + this._winLotto = undefined; + this.set(lotto); + } + + static get DEFAULT_LENGTH() { + return 7; + } + + set(lotto) { + const lottoError = WinLotto.getLottoError(lotto); + + if (lottoError !== undefined) { + throw new Error(lottoError); + } + + this._winLotto = lotto; + } + + get() { + return [...this._winLotto]; + } + + checkRank(compareLotto) { + const compareLottoError = Lotto.getLottoError(compareLotto); + const winLottoError = WinLotto.getLottoError(this._winLotto); + + if (compareLottoError !== undefined || winLottoError !== undefined) { + return compareLottoError || winLottoError; + } + + const accordCount = accord( + this._winLotto.slice(0, LottoRule.DEFAULT_LENGTH), + compareLotto, + ); + const isBonusCorrect = compareLotto.includes(this._winLotto.at(-1)); + + return isBonusCorrect + ? WinLotto.RANK_BY_ACCORD[accordCount].bonus + : WinLotto.RANK_BY_ACCORD[accordCount].base; + } + + static getLottoError(lotto) { + const commonError = Lotto.getCommonLottoError(lotto); + + if (commonError !== undefined) { + return commonError; + } + + const lottoSet = new Set(lotto); + + if (lottoSet.size !== WinLotto.DEFAULT_LENGTH) { + return `당첨 로또 번호의 개수는 ${WinLotto.DEFAULT_LENGTH}개 여야 합니다.`; + } + + return undefined; + } + + static getBonusNumberError(bonusNumber) { + if (typeof bonusNumber !== 'number') { + return 'bonusNumber 가 숫자가 아닙니다.'; + } + + if (bonusNumber < Lotto.MIN_NUMBER || Lotto.MAX_NUMBER < bonusNumber) { + return 'bonusNumber 는 1 ~ 45 사이여야 합니다.'; + } + + return undefined; + } +} From 68aa915cf0d31a2096bf822f96632b3e0404fe6f Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:53:04 +0900 Subject: [PATCH 12/73] =?UTF-8?q?feat:=20main=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 96bab59..1e2e102 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,48 @@ -function main() { - console.log('main의 내용을 채워주세요'); +import View from './View/View.js'; +import LottoRule from './domain/LottoRule.js'; +import Lotto from './domain/Lotto.js'; +import WinLotto from './domain/WinLotto.js'; + +async function main() { + const view = new View(); + const money = await view.inputPurchaseLotto({ + postProcessFn: (input) => Number(input), + errorCheckFn: (input) => LottoRule.getMoneyError(input), + }); + const quantity = LottoRule.calculateQuantity(money); + const lottos = [...new Array(quantity)].map( + () => new Lotto(LottoRule.generateLottoNumber()), + ); + + view.printPurchaseLotto(quantity); + view.printAllLotto(lottos.map((lotto) => lotto.get())); + + const winPureLotto = await view.inputWinLotto({ + postProcessFn: (input) => input.split(',').map((el) => Number(el.trim())), + errorCheckFn: (input) => Lotto.getLottoError(input), + }); + const bonusNumber = await view.inputBonusNumber({ + postProcessFn: (input) => Number(input), + errorCheckFn: (input) => WinLotto.getBonusNumberError(input), + }); + const winLotto = new WinLotto([...winPureLotto, bonusNumber]); + const rankInfo = { + 1: 0, + 2: 0, + 3: 0, + 4: 0, + 5: 0, + }; + lottos.forEach((lotto) => { + rankInfo[winLotto.checkRank(lotto.get())] += 1; + }); + const totalMoney = Object.keys(rankInfo).reduce( + (money, rank) => money + rankInfo[rank] * LottoRule.REWARD[rank], + 0, + ); + + view.printAccordByRank(rankInfo); + view.printRate(totalMoney / money); } main(); From 40e6b10c2d387bdd5e92fc8cfc752cbe3f313df2 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 13:58:24 +0900 Subject: [PATCH 13/73] =?UTF-8?q?fix:=20=EC=9E=98=EB=AA=BB=EB=90=9C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=98=B8=EC=B6=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/Lotto.js | 4 +++- src/domain/WinLotto.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 8de624f..73f7748 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -1,3 +1,5 @@ +import LottoRule from './LottoRule.js'; + export default class Lotto { _lotto; @@ -20,7 +22,7 @@ export default class Lotto { } static getLottoError(lotto) { - const commonError = Lotto.getCommonLottoError(lotto); + const commonError = LottoRule.getCommonLottoError(lotto); if (commonError !== undefined) return commonError; diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index b2b3b75..0b7345d 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -49,7 +49,7 @@ export default class WinLotto extends Lotto { } static getLottoError(lotto) { - const commonError = Lotto.getCommonLottoError(lotto); + const commonError = LottoRule.getCommonLottoError(lotto); if (commonError !== undefined) { return commonError; From 34d906c15699dd9ccb902c0f788bb8742be1be18 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 14:05:13 +0900 Subject: [PATCH 14/73] =?UTF-8?q?fix:=20WinLotto=20=EC=9D=98=20checkRank?= =?UTF-8?q?=20=EB=A9=94=EC=84=A3=EB=93=9C=EA=B0=80=20=EC=A0=9C=EB=8C=80?= =?UTF-8?q?=EB=A1=9C=20=EB=8F=99=EC=9E=91=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - LottoRule 의 RANK_BY_ACCORD 프로퍼티가 잘못 작성되어 있던 문제 - Lotto 가 LottoRule 을 상속받지 않도록 변경 --- src/domain/Lotto.js | 4 ++-- src/domain/LottoRule.js | 2 +- src/domain/WinLotto.js | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 73f7748..8bca27f 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -28,8 +28,8 @@ export default class Lotto { const lottoSet = new Set(lotto); - if (lottoSet.size !== Lotto.DEFAULT_LENGTH) { - return `일반 로또 번호의 개수는 ${Lotto.DEFAULT_LENGTH}개 여야 합니다.`; + if (lottoSet.size !== LottoRule.DEFAULT_LENGTH) { + return `일반 로또 번호의 개수는 ${LottoRule.DEFAULT_LENGTH}개 여야 합니다.`; } return undefined; diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js index ae8b3ef..22ca3b8 100644 --- a/src/domain/LottoRule.js +++ b/src/domain/LottoRule.js @@ -3,7 +3,7 @@ import { changeStandardMoneyString } from '../utils/String.js'; export default class LottoRule { static RANK_BY_ACCORD = Object.freeze({ - 3: { bonus: 5, base: 3 }, + 3: { bonus: 5, base: 5 }, 4: { bonus: 4, base: 4 }, 5: { bonus: 2, base: 3 }, 6: { bonus: 1, base: 1 }, diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index 0b7345d..dc883da 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -7,7 +7,6 @@ export default class WinLotto extends Lotto { constructor(lotto) { super(lotto); - this._winLotto = undefined; this.set(lotto); } @@ -38,14 +37,14 @@ export default class WinLotto extends Lotto { } const accordCount = accord( - this._winLotto.slice(0, LottoRule.DEFAULT_LENGTH), + this.get().slice(0, LottoRule.DEFAULT_LENGTH), compareLotto, ); const isBonusCorrect = compareLotto.includes(this._winLotto.at(-1)); return isBonusCorrect - ? WinLotto.RANK_BY_ACCORD[accordCount].bonus - : WinLotto.RANK_BY_ACCORD[accordCount].base; + ? LottoRule.RANK_BY_ACCORD[accordCount].bonus + : LottoRule.RANK_BY_ACCORD[accordCount].base; } static getLottoError(lotto) { From fdc615b500438c8f1e2d2c015a663a2ed5d48c90 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 14:42:32 +0900 Subject: [PATCH 15/73] =?UTF-8?q?feat:=20WinLotto=20=EC=9D=98=20getBonusNu?= =?UTF-8?q?mberError=20=EA=B0=80=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=EA=B0=80=20=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Lotto 의 static 이 아니라 LottoRule 의 static 을 참조하도록 변경 --- src/domain/WinLotto.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index dc883da..3a92a49 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -68,7 +68,10 @@ export default class WinLotto extends Lotto { return 'bonusNumber 가 숫자가 아닙니다.'; } - if (bonusNumber < Lotto.MIN_NUMBER || Lotto.MAX_NUMBER < bonusNumber) { + if ( + bonusNumber < LottoRule.MIN_NUMBER || + LottoRule.MAX_NUMBER < bonusNumber + ) { return 'bonusNumber 는 1 ~ 45 사이여야 합니다.'; } From 445e96e92e616be6cb21685a1199dbe878c133fb Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 14:42:45 +0900 Subject: [PATCH 16/73] =?UTF-8?q?feat:=20WinLotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20=EB=8C=80=ED=95=9C=20=EB=8B=A8=EC=9C=84=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/WinLotto.test.js | 148 +++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/__tests__/WinLotto.test.js diff --git a/src/__tests__/WinLotto.test.js b/src/__tests__/WinLotto.test.js new file mode 100644 index 0000000..045f8ca --- /dev/null +++ b/src/__tests__/WinLotto.test.js @@ -0,0 +1,148 @@ +import { describe, expect, test } from 'vitest'; +import WinLotto from '../domain/WinLotto'; + +describe('WinLotto 클래스 단위 테스트', () => { + const initialLotto = [1, 2, 3, 4, 5, 6, 7]; + + test('winLotto 를 초기화할 때 배열 길이가 7이 아니면 에러를 반환한다.', () => { + expect(() => { + makeWinLottoMockingData([1]); + }).toThrow(); + }); + + test('winLotto 를 초기화할 때 숫자로 이뤄진 배열이 아니면 에러를 반환한다.', () => { + expect(() => { + makeWinLottoMockingData(initialLotto.map(String)); + }).toThrow(); + }); + + test('winLotto 를 초기화할 때 중복되는 숫자가 있으면 에러를 반환한다.', () => { + expect(() => { + makeWinLottoMockingData([1, 1, 2, 3, 4, 5, 6]); + }).toThrow(); + }); + + test('winLotto 가 위 조건을 모두 통과하면 에러를 반환하지 않는다.', () => { + expect(() => { + makeWinLottoMockingData(initialLotto); + }).not.toThrow(); + }); + + test.each([ + { + lotto: [1, 2, 3, 4, 5, 6], + rank: 1, + }, + { + lotto: [1, 2, 3, 4, 5, 7], + rank: 2, + }, + { + lotto: [1, 2, 3, 4, 5, 8], + rank: 3, + }, + { + lotto: [1, 2, 3, 4, 8, 9], + rank: 4, + }, + { + lotto: [1, 2, 3, 8, 9, 10], + rank: 5, + }, + ])( + 'checkRank 메서드에 일반 로또($lotto)를 넣으면 당첨 로또와 일치하는 랭크($rank)를 반환한다.', + ({ lotto, rank }) => { + const winLotto = makeWinLottoMockingData(initialLotto); + + expect(winLotto.checkRank(lotto)).toBe(rank); + }, + ); + + test('get 메서드를 사용하면 현재 당첨 로또 번호 7자리를 가져온다.', () => { + const winLotto = makeWinLottoMockingData(initialLotto); + + expect(winLotto.get()).toStrictEqual(initialLotto); + }); + + test('set 메서드를 사용하면 해당 로또 번호를 바꿀 수 있다.', () => { + const winLotto = makeWinLottoMockingData(initialLotto); + const nextLotto = [2, 3, 4, 5, 6, 7, 8]; + winLotto.set(nextLotto); + + expect(winLotto.get()).toStrictEqual(nextLotto); + }); + + test.each([ + { lotto: 1 }, + { lotto: '1' }, + { lotto: {} }, + { lotto: null }, + { lotto: undefined }, + { lotto: function () {} }, + ])( + 'WinLotto의 getLottoError 메서드는 인수인 lotto($lotto)가 배열이 아닌 경우 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(WinLotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([ + { lotto: [0, 1, 2, 3, 4, 5, 6] }, + { lotto: [1, 2, 3, 4, 5, 6, 99] }, + ])( + 'winLotto의 getLottoError 메서드는 1 미만, 45 초과 숫자가 하나라도 있으면 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(WinLotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [1, 1, 2, 3, 4, 5, 6] }])( + 'winLotto의 getLottoError 메서드는 중복되는 숫자가 하나라도 있으면 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(WinLotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [1, 2, 3, 4, 5] }, { lotto: [1, 2, 3, 4, 5, 6, 7, 8] }])( + 'winLotto의 getLottoError 메서드는 배열의 길이가 7이 아닌 경우 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(WinLotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [1, 2, 3, 4, 5, 6, 7] }])( + 'winLotto의 getLottoError 메서드는 위 조건을 모두 충족하면 undefined 를 반환한다.', + ({ lotto }) => { + expect(WinLotto.getLottoError(lotto)).toBeUndefined(); + }, + ); + + test.each([ + { bonusNumber: '1' }, + { bonusNumber: undefined }, + { bonusNumber: null }, + { bonusNumber: [] }, + { bonusNumber: {} }, + { bonusNumber: function () {} }, + ])( + 'winLotto 의 getBonusNumberError 는 bonusNumber($bonusNumber)가 숫자가 아닌 경우 undefined 를 반환하지 않는다.', + ({ bonusNumber }) => { + expect(WinLotto.getBonusNumberError(bonusNumber)).toBeDefined(); + }, + ); + + test.each([{ bonusNumber: 0 }, { bonusNumber: 46 }])( + 'winLotto 의 getBonusNumberError 는 bonusNumber($bonusNumber)가 1~45 사이의 숫자가 아닌 경우 undefined 를 반환하지 않는다..', + ({ bonusNumber }) => { + expect(WinLotto.getBonusNumberError(bonusNumber)).toBeDefined(); + }, + ); + + test('winLotto 의 getBonusNumberError 는 위 조건을 모두 통과하면 undefined 를 반환한다.', () => { + expect(WinLotto.getBonusNumberError(4)).toBeUndefined(); + }); +}); + +function makeWinLottoMockingData(initialLotto) { + return new WinLotto(initialLotto); +} From c1a762105974364565016d441c700c65e925d3b1 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 14:54:21 +0900 Subject: [PATCH 17/73] =?UTF-8?q?fix:=20Lotto=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4=EA=B0=80=20?= =?UTF-8?q?=EC=98=AC=EB=B0=94=EB=A5=B8=20=EA=B0=92=EC=9D=B4=20=EC=95=84?= =?UTF-8?q?=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=97=90=EB=9F=AC=EB=A5=BC=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/Lotto.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 8bca27f..df8b743 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -11,7 +11,7 @@ export default class Lotto { const lottoError = Lotto.getLottoError(lotto); if (lottoError !== undefined) { - return lottoError; + throw new Error(lottoError); } this._lotto = lotto; From eacbbfca9e9faa0767d9bb4a32fa82204dfbe295 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 14:54:34 +0900 Subject: [PATCH 18/73] =?UTF-8?q?feat:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/Lotto.test.js | 94 +++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/__tests__/Lotto.test.js diff --git a/src/__tests__/Lotto.test.js b/src/__tests__/Lotto.test.js new file mode 100644 index 0000000..f234edc --- /dev/null +++ b/src/__tests__/Lotto.test.js @@ -0,0 +1,94 @@ +import { describe, expect, test } from 'vitest'; +import Lotto from '../domain/Lotto'; + +describe('Lotto 클래스에 대한 단위 테스트 작성', () => { + const initialLotto = [1, 2, 3, 4, 5, 6]; + + test.each([ + { lotto: '1' }, + { lotto: {} }, + { lotto: undefined }, + { lotto: null }, + { lotto: function () {} }, + ])( + 'lotto 초기화 시 인스턴스($lotto)가 배열이 아니면 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeLottoMockingData(lotto); + }).toThrow(); + }, + ); + + test.each([{ lotto: [0, 1, 2, 3, 4, 5] }, { lotto: [1, 2, 3, 4, 5, 99] }])( + 'lotto 초기화 시 인스턴스($lotto)의 요소가 1~45 범위를 벗어나는 숫자를 가지고 있으면 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeLottoMockingData(lotto); + }).toThrow(); + }, + ); + + test.each([{ lotto: [1, 2, 3, 4, 5, 5] }])( + 'lotto 초기화 시 인스턴스($lotto)의 요소에 중복되지 않는 6개의 숫자로 이뤄지지 않았다면 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeLottoMockingData(lotto); + }).toThrow(); + }, + ); + + test('lotto 초기화시 인스턴스가 위 조건을 모두 충족하면 에러를 반환하지 않는다.', () => { + expect(() => { + makeLottoMockingData([1, 2, 3, 4, 5, 6]); + }).not.toThrow(); + }); + + test('get 메서드는 현재 lotto 의 값을 가져올 수 있다.', () => { + const lotto = makeLottoMockingData(initialLotto); + + expect(lotto.get()).toStrictEqual(initialLotto); + }); + + test('set 메서드는 현재 lotto 의 값을 바꿀 수 있다.', () => { + const lotto = makeLottoMockingData(initialLotto); + const nextLotto = [2, 3, 4, 5, 6, 7]; + lotto.set(nextLotto); + + expect(lotto.get()).toStrictEqual(nextLotto); + }); + + test.each([ + { lotto: '1' }, + { lotto: {} }, + { lotto: undefined }, + { lotto: null }, + { lotto: function () {} }, + ])( + 'getLottoError 메서드는 인수($lotto)가 배열이 아니면 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(Lotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [0, 1, 2, 3, 4, 5] }, { lotto: [1, 2, 3, 4, 5, 99] }])( + 'getLottoError 메서드는 인수($lotto)가 1~45 사이의 숫자로 이뤄져 있지 않으면 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(Lotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [1, 2, 3, 4, 5, 5] }, { lotto: [1, 2, 3, 4, 5] }])( + 'getLottoError 메서드는 인수($lotto)가 중복되지 않는 1~45사이의 6개의 숫자로 이뤄져 있지 않으면 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(Lotto.getLottoError(lotto)).toBeDefined(); + }, + ); + + test('getLottoError 메서드는 위 조건을 모두 충족하면 undefined 를 반환한다.', () => { + expect(Lotto.getLottoError(initialLotto)).toBeUndefined(); + }); +}); + +function makeLottoMockingData(initialLotto) { + return new Lotto(initialLotto); +} From 25ddc4b4ca887bb648e4968a0a89dd7c02b27625 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Tue, 9 Jul 2024 15:15:08 +0900 Subject: [PATCH 19/73] =?UTF-8?q?feat:=20LottoRule=20=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BC=80=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/LottoRule.test.js | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/__tests__/LottoRule.test.js diff --git a/src/__tests__/LottoRule.test.js b/src/__tests__/LottoRule.test.js new file mode 100644 index 0000000..2335209 --- /dev/null +++ b/src/__tests__/LottoRule.test.js @@ -0,0 +1,77 @@ +import { describe, expect, test } from 'vitest'; +import LottoRule from '../domain/LottoRule'; + +describe('LottoRule 클래스에 대한 단위 테스트 진행', () => { + test('generateLottoNumber 메서드는 1~45 사이의 숫자로 이뤄진 6개의 배열을 반환한다.', () => { + const lotto = LottoRule.generateLottoNumber(); + + lotto.forEach((num) => + expect(num).greaterThanOrEqual(1).lessThanOrEqual(45), + ); + }); + + test.each([ + { money: 1000, answer: 1 }, + { money: 1222, answer: 1 }, + { money: 2000, answer: 2 }, + ])( + `calculateQuantity 는 숫자 타입의 money($money) 를 받아 ${LottoRule.MONEY} 으로 나눈 몫($answer)을 반환한다.`, + ({ money, answer }) => { + expect(LottoRule.calculateQuantity(money)).toBe(answer); + }, + ); + + test.each([ + { money: '1000' }, + { money: {} }, + { money: [] }, + { money: function () {} }, + ])( + 'getMoneyError 는 money($money)가 숫자 타입이 아닌 경우 undefined 를 반환하지 않는다.', + ({ money }) => { + expect(LottoRule.getMoneyError(money)).toBeDefined(); + }, + ); + + test.each([{ money: 0 }, { money: -100 }])( + `getMoneyError 는 money($money)가 ${LottoRule.MONEY}보다 작은 숫자인 경우 undefined 를 반환하지 않는다.`, + ({ money }) => { + expect(LottoRule.getMoneyError(money)).toBeDefined(); + }, + ); + + test.each([{ money: 10000 }, { money: 1000 }])( + `getMoneyError 는 money($money)가 ${LottoRule.MONEY} 이상의 숫자인 경우 undefined 를 반환한다.`, + ({ money }) => { + expect(LottoRule.getMoneyError(money)).toBeUndefined(); + }, + ); + + test.each([ + { lotto: 1 }, + { lotto: '1' }, + { lotto: {} }, + { lotto: undefined }, + { lotto: null }, + { lotto: function () {} }, + ])( + 'getCommonLottoError는 인자 lotto ($lotto) 가 배열 타입이 아닌 경우 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(LottoRule.getCommonLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [1, 2, 3, 4, 5, 99] }, { lotto: [0, 1, 2, 3, 4, 5] }])( + 'getCommonLottoError는 인자 lotto ($lotto) 의 요소가 1~45사이의 숫자를 가지지 않은 경우 undefined 를 반환하지 않는다.', + ({ lotto }) => { + expect(LottoRule.getCommonLottoError(lotto)).toBeDefined(); + }, + ); + + test.each([{ lotto: [1, 2, 3, 4, 5, 6] }, { lotto: [1, 2, 3, 4, 5, 6, 7] }])( + 'getCommonLottoError 의 인자 lotto ($lotto) 가 위 조건을 모두 통과하면 undefined 를 반환한다.', + ({ lotto }) => { + expect(LottoRule.getCommonLottoError(lotto)).toBeUndefined(); + }, + ); +}); From 918b2d87ca46880d036118d0d4cc42ff320f04bd Mon Sep 17 00:00:00 2001 From: Suyeon Date: Wed, 10 Jul 2024 14:37:07 +0900 Subject: [PATCH 20/73] =?UTF-8?q?init:=20=ED=8F=B4=EB=8D=94=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/View.js | 112 ------------------------ src/__tests__/Lotto.test.js | 94 -------------------- src/__tests__/LottoRule.test.js | 77 ----------------- src/__tests__/WinLotto.test.js | 148 -------------------------------- src/domain/Lotto.js | 37 -------- src/domain/LottoRule.js | 90 ------------------- src/domain/WinLotto.js | 80 ----------------- src/main.js | 48 ----------- src/utils/Array.js | 20 ----- src/utils/Number.js | 3 - src/utils/String.js | 13 --- 11 files changed, 722 deletions(-) delete mode 100644 src/View/View.js delete mode 100644 src/__tests__/Lotto.test.js delete mode 100644 src/__tests__/LottoRule.test.js delete mode 100644 src/__tests__/WinLotto.test.js delete mode 100644 src/domain/Lotto.js delete mode 100644 src/domain/LottoRule.js delete mode 100644 src/domain/WinLotto.js delete mode 100644 src/main.js delete mode 100644 src/utils/Array.js delete mode 100644 src/utils/Number.js delete mode 100644 src/utils/String.js diff --git a/src/View/View.js b/src/View/View.js deleted file mode 100644 index 8b4d437..0000000 --- a/src/View/View.js +++ /dev/null @@ -1,112 +0,0 @@ -import { readLineAsync } from '../utils/readline.js'; -import LottoRule from '../domain/LottoRule.js'; - -export default class View { - constructor() { - this.rl = readLineAsync; - } - - async input( - message, - options = { - postProcessFn: undefined, - errorCheckFn: undefined, - }, - ) { - const { postProcessFn, errorCheckFn } = options; - const postProcessFnError = View.getPostProcessFnError(postProcessFn); - const errorCheckFnError = View.getErrorCheckFnError(errorCheckFn); - - if (postProcessFnError !== undefined || errorCheckFnError !== undefined) { - throw new Error(postProcessFnError || errorCheckFnError); - } - - while (true) { - const inputValue = await this.rl(message); - const postInputValue = postProcessFn - ? postProcessFn(inputValue) - : inputValue; - const error = errorCheckFn - ? errorCheckFn(postInputValue) - : postInputValue; - - if (error === undefined) { - return postInputValue; - } - - console.log(error); - } - } - - async inputPurchaseLotto( - options = { - postProcessFn: undefined, - errorCheckFn: undefined, - }, - ) { - return this.input('> 구입금액을 입력해 주세요:', options); - } - - async inputWinLotto( - options = { - postProcessFn: undefined, - errorCheckFn: undefined, - }, - ) { - return this.input('> 당첨 번호를 콤마(,)로 구분해 입력해 주세요:', options); - } - - async inputBonusNumber( - options = { - postProcessFn: undefined, - errorCheckFn: undefined, - }, - ) { - return this.input('> 보너스 번호를 입력해 주세요: ', options); - } - - printPurchaseLotto(quantity) { - console.log(`${quantity}개를 구매했습니다.`); - console.log('\n'); - } - - printAllLotto(lottos) { - lottos.forEach((lotto) => { - console.log(lotto); - }); - console.log('\n'); - } - - printAccordByRank(rankInfo) { - const ranks = Object.keys(rankInfo); - - console.log('당첨 통계'); - console.log('--------------------'); - - ranks.forEach((rank) => { - console.log( - `${LottoRule.ACCROD_STRING_BY_RANK[rank]} - ${rankInfo[rank]}개`, - ); - }); - } - - printRate(rate) { - console.log(`총 수익률은 ${rate}% 입니다.`); - } - - static getPostProcessFnError(postProcessFn) { - if (postProcessFn !== undefined && typeof postProcessFn !== 'function') { - return '후처리 함수(postProcessFn)는 함수 타입이어야 합니다.'; - } - - return undefined; - } - - static getErrorCheckFnError(errorCheckFn) { - if (errorCheckFn !== undefined && typeof errorCheckFn !== 'function') { - return '에러 검사 함수(errorCheckFn)는 함수 타입이어야 합니다.'; - } - - return undefined; - } -} diff --git a/src/__tests__/Lotto.test.js b/src/__tests__/Lotto.test.js deleted file mode 100644 index f234edc..0000000 --- a/src/__tests__/Lotto.test.js +++ /dev/null @@ -1,94 +0,0 @@ -import { describe, expect, test } from 'vitest'; -import Lotto from '../domain/Lotto'; - -describe('Lotto 클래스에 대한 단위 테스트 작성', () => { - const initialLotto = [1, 2, 3, 4, 5, 6]; - - test.each([ - { lotto: '1' }, - { lotto: {} }, - { lotto: undefined }, - { lotto: null }, - { lotto: function () {} }, - ])( - 'lotto 초기화 시 인스턴스($lotto)가 배열이 아니면 에러를 반환한다.', - ({ lotto }) => { - expect(() => { - makeLottoMockingData(lotto); - }).toThrow(); - }, - ); - - test.each([{ lotto: [0, 1, 2, 3, 4, 5] }, { lotto: [1, 2, 3, 4, 5, 99] }])( - 'lotto 초기화 시 인스턴스($lotto)의 요소가 1~45 범위를 벗어나는 숫자를 가지고 있으면 에러를 반환한다.', - ({ lotto }) => { - expect(() => { - makeLottoMockingData(lotto); - }).toThrow(); - }, - ); - - test.each([{ lotto: [1, 2, 3, 4, 5, 5] }])( - 'lotto 초기화 시 인스턴스($lotto)의 요소에 중복되지 않는 6개의 숫자로 이뤄지지 않았다면 에러를 반환한다.', - ({ lotto }) => { - expect(() => { - makeLottoMockingData(lotto); - }).toThrow(); - }, - ); - - test('lotto 초기화시 인스턴스가 위 조건을 모두 충족하면 에러를 반환하지 않는다.', () => { - expect(() => { - makeLottoMockingData([1, 2, 3, 4, 5, 6]); - }).not.toThrow(); - }); - - test('get 메서드는 현재 lotto 의 값을 가져올 수 있다.', () => { - const lotto = makeLottoMockingData(initialLotto); - - expect(lotto.get()).toStrictEqual(initialLotto); - }); - - test('set 메서드는 현재 lotto 의 값을 바꿀 수 있다.', () => { - const lotto = makeLottoMockingData(initialLotto); - const nextLotto = [2, 3, 4, 5, 6, 7]; - lotto.set(nextLotto); - - expect(lotto.get()).toStrictEqual(nextLotto); - }); - - test.each([ - { lotto: '1' }, - { lotto: {} }, - { lotto: undefined }, - { lotto: null }, - { lotto: function () {} }, - ])( - 'getLottoError 메서드는 인수($lotto)가 배열이 아니면 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(Lotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [0, 1, 2, 3, 4, 5] }, { lotto: [1, 2, 3, 4, 5, 99] }])( - 'getLottoError 메서드는 인수($lotto)가 1~45 사이의 숫자로 이뤄져 있지 않으면 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(Lotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [1, 2, 3, 4, 5, 5] }, { lotto: [1, 2, 3, 4, 5] }])( - 'getLottoError 메서드는 인수($lotto)가 중복되지 않는 1~45사이의 6개의 숫자로 이뤄져 있지 않으면 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(Lotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test('getLottoError 메서드는 위 조건을 모두 충족하면 undefined 를 반환한다.', () => { - expect(Lotto.getLottoError(initialLotto)).toBeUndefined(); - }); -}); - -function makeLottoMockingData(initialLotto) { - return new Lotto(initialLotto); -} diff --git a/src/__tests__/LottoRule.test.js b/src/__tests__/LottoRule.test.js deleted file mode 100644 index 2335209..0000000 --- a/src/__tests__/LottoRule.test.js +++ /dev/null @@ -1,77 +0,0 @@ -import { describe, expect, test } from 'vitest'; -import LottoRule from '../domain/LottoRule'; - -describe('LottoRule 클래스에 대한 단위 테스트 진행', () => { - test('generateLottoNumber 메서드는 1~45 사이의 숫자로 이뤄진 6개의 배열을 반환한다.', () => { - const lotto = LottoRule.generateLottoNumber(); - - lotto.forEach((num) => - expect(num).greaterThanOrEqual(1).lessThanOrEqual(45), - ); - }); - - test.each([ - { money: 1000, answer: 1 }, - { money: 1222, answer: 1 }, - { money: 2000, answer: 2 }, - ])( - `calculateQuantity 는 숫자 타입의 money($money) 를 받아 ${LottoRule.MONEY} 으로 나눈 몫($answer)을 반환한다.`, - ({ money, answer }) => { - expect(LottoRule.calculateQuantity(money)).toBe(answer); - }, - ); - - test.each([ - { money: '1000' }, - { money: {} }, - { money: [] }, - { money: function () {} }, - ])( - 'getMoneyError 는 money($money)가 숫자 타입이 아닌 경우 undefined 를 반환하지 않는다.', - ({ money }) => { - expect(LottoRule.getMoneyError(money)).toBeDefined(); - }, - ); - - test.each([{ money: 0 }, { money: -100 }])( - `getMoneyError 는 money($money)가 ${LottoRule.MONEY}보다 작은 숫자인 경우 undefined 를 반환하지 않는다.`, - ({ money }) => { - expect(LottoRule.getMoneyError(money)).toBeDefined(); - }, - ); - - test.each([{ money: 10000 }, { money: 1000 }])( - `getMoneyError 는 money($money)가 ${LottoRule.MONEY} 이상의 숫자인 경우 undefined 를 반환한다.`, - ({ money }) => { - expect(LottoRule.getMoneyError(money)).toBeUndefined(); - }, - ); - - test.each([ - { lotto: 1 }, - { lotto: '1' }, - { lotto: {} }, - { lotto: undefined }, - { lotto: null }, - { lotto: function () {} }, - ])( - 'getCommonLottoError는 인자 lotto ($lotto) 가 배열 타입이 아닌 경우 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(LottoRule.getCommonLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [1, 2, 3, 4, 5, 99] }, { lotto: [0, 1, 2, 3, 4, 5] }])( - 'getCommonLottoError는 인자 lotto ($lotto) 의 요소가 1~45사이의 숫자를 가지지 않은 경우 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(LottoRule.getCommonLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [1, 2, 3, 4, 5, 6] }, { lotto: [1, 2, 3, 4, 5, 6, 7] }])( - 'getCommonLottoError 의 인자 lotto ($lotto) 가 위 조건을 모두 통과하면 undefined 를 반환한다.', - ({ lotto }) => { - expect(LottoRule.getCommonLottoError(lotto)).toBeUndefined(); - }, - ); -}); diff --git a/src/__tests__/WinLotto.test.js b/src/__tests__/WinLotto.test.js deleted file mode 100644 index 045f8ca..0000000 --- a/src/__tests__/WinLotto.test.js +++ /dev/null @@ -1,148 +0,0 @@ -import { describe, expect, test } from 'vitest'; -import WinLotto from '../domain/WinLotto'; - -describe('WinLotto 클래스 단위 테스트', () => { - const initialLotto = [1, 2, 3, 4, 5, 6, 7]; - - test('winLotto 를 초기화할 때 배열 길이가 7이 아니면 에러를 반환한다.', () => { - expect(() => { - makeWinLottoMockingData([1]); - }).toThrow(); - }); - - test('winLotto 를 초기화할 때 숫자로 이뤄진 배열이 아니면 에러를 반환한다.', () => { - expect(() => { - makeWinLottoMockingData(initialLotto.map(String)); - }).toThrow(); - }); - - test('winLotto 를 초기화할 때 중복되는 숫자가 있으면 에러를 반환한다.', () => { - expect(() => { - makeWinLottoMockingData([1, 1, 2, 3, 4, 5, 6]); - }).toThrow(); - }); - - test('winLotto 가 위 조건을 모두 통과하면 에러를 반환하지 않는다.', () => { - expect(() => { - makeWinLottoMockingData(initialLotto); - }).not.toThrow(); - }); - - test.each([ - { - lotto: [1, 2, 3, 4, 5, 6], - rank: 1, - }, - { - lotto: [1, 2, 3, 4, 5, 7], - rank: 2, - }, - { - lotto: [1, 2, 3, 4, 5, 8], - rank: 3, - }, - { - lotto: [1, 2, 3, 4, 8, 9], - rank: 4, - }, - { - lotto: [1, 2, 3, 8, 9, 10], - rank: 5, - }, - ])( - 'checkRank 메서드에 일반 로또($lotto)를 넣으면 당첨 로또와 일치하는 랭크($rank)를 반환한다.', - ({ lotto, rank }) => { - const winLotto = makeWinLottoMockingData(initialLotto); - - expect(winLotto.checkRank(lotto)).toBe(rank); - }, - ); - - test('get 메서드를 사용하면 현재 당첨 로또 번호 7자리를 가져온다.', () => { - const winLotto = makeWinLottoMockingData(initialLotto); - - expect(winLotto.get()).toStrictEqual(initialLotto); - }); - - test('set 메서드를 사용하면 해당 로또 번호를 바꿀 수 있다.', () => { - const winLotto = makeWinLottoMockingData(initialLotto); - const nextLotto = [2, 3, 4, 5, 6, 7, 8]; - winLotto.set(nextLotto); - - expect(winLotto.get()).toStrictEqual(nextLotto); - }); - - test.each([ - { lotto: 1 }, - { lotto: '1' }, - { lotto: {} }, - { lotto: null }, - { lotto: undefined }, - { lotto: function () {} }, - ])( - 'WinLotto의 getLottoError 메서드는 인수인 lotto($lotto)가 배열이 아닌 경우 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(WinLotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([ - { lotto: [0, 1, 2, 3, 4, 5, 6] }, - { lotto: [1, 2, 3, 4, 5, 6, 99] }, - ])( - 'winLotto의 getLottoError 메서드는 1 미만, 45 초과 숫자가 하나라도 있으면 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(WinLotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [1, 1, 2, 3, 4, 5, 6] }])( - 'winLotto의 getLottoError 메서드는 중복되는 숫자가 하나라도 있으면 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(WinLotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [1, 2, 3, 4, 5] }, { lotto: [1, 2, 3, 4, 5, 6, 7, 8] }])( - 'winLotto의 getLottoError 메서드는 배열의 길이가 7이 아닌 경우 undefined 를 반환하지 않는다.', - ({ lotto }) => { - expect(WinLotto.getLottoError(lotto)).toBeDefined(); - }, - ); - - test.each([{ lotto: [1, 2, 3, 4, 5, 6, 7] }])( - 'winLotto의 getLottoError 메서드는 위 조건을 모두 충족하면 undefined 를 반환한다.', - ({ lotto }) => { - expect(WinLotto.getLottoError(lotto)).toBeUndefined(); - }, - ); - - test.each([ - { bonusNumber: '1' }, - { bonusNumber: undefined }, - { bonusNumber: null }, - { bonusNumber: [] }, - { bonusNumber: {} }, - { bonusNumber: function () {} }, - ])( - 'winLotto 의 getBonusNumberError 는 bonusNumber($bonusNumber)가 숫자가 아닌 경우 undefined 를 반환하지 않는다.', - ({ bonusNumber }) => { - expect(WinLotto.getBonusNumberError(bonusNumber)).toBeDefined(); - }, - ); - - test.each([{ bonusNumber: 0 }, { bonusNumber: 46 }])( - 'winLotto 의 getBonusNumberError 는 bonusNumber($bonusNumber)가 1~45 사이의 숫자가 아닌 경우 undefined 를 반환하지 않는다..', - ({ bonusNumber }) => { - expect(WinLotto.getBonusNumberError(bonusNumber)).toBeDefined(); - }, - ); - - test('winLotto 의 getBonusNumberError 는 위 조건을 모두 통과하면 undefined 를 반환한다.', () => { - expect(WinLotto.getBonusNumberError(4)).toBeUndefined(); - }); -}); - -function makeWinLottoMockingData(initialLotto) { - return new WinLotto(initialLotto); -} diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js deleted file mode 100644 index df8b743..0000000 --- a/src/domain/Lotto.js +++ /dev/null @@ -1,37 +0,0 @@ -import LottoRule from './LottoRule.js'; - -export default class Lotto { - _lotto; - - constructor(lotto) { - this.set(lotto); - } - - set(lotto) { - const lottoError = Lotto.getLottoError(lotto); - - if (lottoError !== undefined) { - throw new Error(lottoError); - } - - this._lotto = lotto; - } - - get() { - return [...this._lotto]; - } - - static getLottoError(lotto) { - const commonError = LottoRule.getCommonLottoError(lotto); - - if (commonError !== undefined) return commonError; - - const lottoSet = new Set(lotto); - - if (lottoSet.size !== LottoRule.DEFAULT_LENGTH) { - return `일반 로또 번호의 개수는 ${LottoRule.DEFAULT_LENGTH}개 여야 합니다.`; - } - - return undefined; - } -} diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js deleted file mode 100644 index 22ca3b8..0000000 --- a/src/domain/LottoRule.js +++ /dev/null @@ -1,90 +0,0 @@ -import { generateRandomNumberArray } from '../utils/Array.js'; -import { changeStandardMoneyString } from '../utils/String.js'; - -export default class LottoRule { - static RANK_BY_ACCORD = Object.freeze({ - 3: { bonus: 5, base: 5 }, - 4: { bonus: 4, base: 4 }, - 5: { bonus: 2, base: 3 }, - 6: { bonus: 1, base: 1 }, - }); - static REWARD = Object.freeze({ - 1: 200000000, - 2: 30000000, - 3: 1500000, - 4: 50000, - 5: 5000, - }); - static ACCROD_STRING_BY_RANK = Object.freeze({ - 1: `6개 일치 ${changeStandardMoneyString(LottoRule.REWARD[1])}`, - 2: `5개 일치, 보너스 볼 일치 ${changeStandardMoneyString(LottoRule.REWARD[2])}`, - 3: `5개 일치 ${changeStandardMoneyString(LottoRule.REWARD[3])}`, - 4: `4개 일치 ${changeStandardMoneyString(LottoRule.REWARD[4])}`, - 5: `3개 일치 ${changeStandardMoneyString(LottoRule.REWARD[5])}`, - }); - - static get MAX_NUMBER() { - return 45; - } - - static get MIN_NUMBER() { - return 1; - } - - static get MONEY() { - return 1000; - } - - static get DEFAULT_LENGTH() { - return 6; - } - - static generateLottoNumber() { - return generateRandomNumberArray( - LottoRule.DEFAULT_LENGTH, - LottoRule.MIN_NUMBER, - LottoRule.MAX_NUMBER, - ); - } - - static calculateQuantity(money) { - const moneyError = LottoRule.getMoneyError(money); - - if (moneyError !== undefined) { - throw new Error(moneyError); - } - - return Math.floor(money / LottoRule.MONEY); - } - - static getMoneyError(money) { - if (typeof money !== 'number') { - return '돈은 숫자 타입으로 입력받아야 합니다.'; - } - - if (money < LottoRule.MONEY) { - return `구입금액은 최소 ${LottoRule.MONEY}원부터 가능합니다.`; - } - - return undefined; - } - - static getCommonLottoError(lotto) { - if (Array.isArray(lotto) === false) { - return 'lotto는 배열 형식이어야 합니다.'; - } - - if ( - lotto.some( - (num) => - typeof num !== 'number' || - num < LottoRule.MIN_NUMBER || - num > LottoRule.MAX_NUMBER, - ) - ) { - return 'lotto배열의 요소는 숫자로 이뤄져야 합니다.'; - } - - return undefined; - } -} diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js deleted file mode 100644 index 3a92a49..0000000 --- a/src/domain/WinLotto.js +++ /dev/null @@ -1,80 +0,0 @@ -import Lotto from './Lotto.js'; -import LottoRule from './LottoRule.js'; -import { accord } from '../utils/Array.js'; - -export default class WinLotto extends Lotto { - _winLotto; - - constructor(lotto) { - super(lotto); - this.set(lotto); - } - - static get DEFAULT_LENGTH() { - return 7; - } - - set(lotto) { - const lottoError = WinLotto.getLottoError(lotto); - - if (lottoError !== undefined) { - throw new Error(lottoError); - } - - this._winLotto = lotto; - } - - get() { - return [...this._winLotto]; - } - - checkRank(compareLotto) { - const compareLottoError = Lotto.getLottoError(compareLotto); - const winLottoError = WinLotto.getLottoError(this._winLotto); - - if (compareLottoError !== undefined || winLottoError !== undefined) { - return compareLottoError || winLottoError; - } - - const accordCount = accord( - this.get().slice(0, LottoRule.DEFAULT_LENGTH), - compareLotto, - ); - const isBonusCorrect = compareLotto.includes(this._winLotto.at(-1)); - - return isBonusCorrect - ? LottoRule.RANK_BY_ACCORD[accordCount].bonus - : LottoRule.RANK_BY_ACCORD[accordCount].base; - } - - static getLottoError(lotto) { - const commonError = LottoRule.getCommonLottoError(lotto); - - if (commonError !== undefined) { - return commonError; - } - - const lottoSet = new Set(lotto); - - if (lottoSet.size !== WinLotto.DEFAULT_LENGTH) { - return `당첨 로또 번호의 개수는 ${WinLotto.DEFAULT_LENGTH}개 여야 합니다.`; - } - - return undefined; - } - - static getBonusNumberError(bonusNumber) { - if (typeof bonusNumber !== 'number') { - return 'bonusNumber 가 숫자가 아닙니다.'; - } - - if ( - bonusNumber < LottoRule.MIN_NUMBER || - LottoRule.MAX_NUMBER < bonusNumber - ) { - return 'bonusNumber 는 1 ~ 45 사이여야 합니다.'; - } - - return undefined; - } -} diff --git a/src/main.js b/src/main.js deleted file mode 100644 index 1e2e102..0000000 --- a/src/main.js +++ /dev/null @@ -1,48 +0,0 @@ -import View from './View/View.js'; -import LottoRule from './domain/LottoRule.js'; -import Lotto from './domain/Lotto.js'; -import WinLotto from './domain/WinLotto.js'; - -async function main() { - const view = new View(); - const money = await view.inputPurchaseLotto({ - postProcessFn: (input) => Number(input), - errorCheckFn: (input) => LottoRule.getMoneyError(input), - }); - const quantity = LottoRule.calculateQuantity(money); - const lottos = [...new Array(quantity)].map( - () => new Lotto(LottoRule.generateLottoNumber()), - ); - - view.printPurchaseLotto(quantity); - view.printAllLotto(lottos.map((lotto) => lotto.get())); - - const winPureLotto = await view.inputWinLotto({ - postProcessFn: (input) => input.split(',').map((el) => Number(el.trim())), - errorCheckFn: (input) => Lotto.getLottoError(input), - }); - const bonusNumber = await view.inputBonusNumber({ - postProcessFn: (input) => Number(input), - errorCheckFn: (input) => WinLotto.getBonusNumberError(input), - }); - const winLotto = new WinLotto([...winPureLotto, bonusNumber]); - const rankInfo = { - 1: 0, - 2: 0, - 3: 0, - 4: 0, - 5: 0, - }; - lottos.forEach((lotto) => { - rankInfo[winLotto.checkRank(lotto.get())] += 1; - }); - const totalMoney = Object.keys(rankInfo).reduce( - (money, rank) => money + rankInfo[rank] * LottoRule.REWARD[rank], - 0, - ); - - view.printAccordByRank(rankInfo); - view.printRate(totalMoney / money); -} - -main(); diff --git a/src/utils/Array.js b/src/utils/Array.js deleted file mode 100644 index 9148894..0000000 --- a/src/utils/Array.js +++ /dev/null @@ -1,20 +0,0 @@ -import { generateRandomNumber } from './Number.js'; - -export function accord(base, compare) { - const baseSet = new Set(base); - - return compare.reduce( - (prev, curr) => (baseSet.has(curr) ? prev + 1 : prev), - 0, - ); -} - -export function generateRandomNumberArray(amount, min, max) { - const set = new Set(); - - while (set.size < amount) { - set.add(generateRandomNumber(min, max)); - } - - return [...set].sort((a, b) => a - b); -} diff --git a/src/utils/Number.js b/src/utils/Number.js deleted file mode 100644 index 14f3a6a..0000000 --- a/src/utils/Number.js +++ /dev/null @@ -1,3 +0,0 @@ -export function generateRandomNumber(min, max) { - return Math.floor(Math.random() * (max - min) + min); -} diff --git a/src/utils/String.js b/src/utils/String.js deleted file mode 100644 index f909541..0000000 --- a/src/utils/String.js +++ /dev/null @@ -1,13 +0,0 @@ -export function changeStandardMoneyString(money) { - const reversedMoney = String(money).split('').reverse(); - const stack = []; - - reversedMoney.forEach((num, index) => { - if (reversedMoney[index + 1] !== undefined && index % 3 === 0) { - stack.push(','); - } - stack.push(num); - }); - - return stack.reverse().join(''); -} From 6d9a9475e27af12e66ead9e8e0a6d5730eb60bb9 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Thu, 11 Jul 2024 16:58:40 +0900 Subject: [PATCH 21/73] =?UTF-8?q?feat:=20validator=20=EB=A5=BC=20=EB=A7=8C?= =?UTF-8?q?=EB=93=9C=EB=8A=94=20createValidator=20=ED=95=A8=EC=88=98=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/validator/createValidator.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/validator/createValidator.js diff --git a/src/validator/createValidator.js b/src/validator/createValidator.js new file mode 100644 index 0000000..9cc6904 --- /dev/null +++ b/src/validator/createValidator.js @@ -0,0 +1,32 @@ +const createValidator = (validation) => { + const validateKeyValue = (key, value) => { + if (validation[key] === undefined) { + throw new Error('해당 키 값이 validation 내부에 존재하지 않습니다.'); + } + const validate = validation[key](value); + + if (validate !== true) { + throw new Error(validate); + } + }; + + return (keys, values) => { + if (typeof keys === 'string' && typeof values === 'string') { + validateKeyValue(keys, values); + return; + } + if (Array.isArray(keys) && Array.isArray(values)) { + if (keys.length !== values.length) { + throw new Error('키 배열의 개수와 값 배열의 개수가 일치해야 합니다.'); + } + keys.forEach((key, index) => validateKeyValue(key, values[index])); + return; + } + + throw new Error( + '매개변수로 전달한 keys 와 values 의 타입은 동일해야 합니다.', + ); + }; +}; + +export default createValidator; From 0dd9649d5c2063c02ff0a44365c79025e3ccd84f Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 13:37:04 +0900 Subject: [PATCH 22/73] =?UTF-8?q?refactoring:=20=EB=A7=A4=EA=B0=9C?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=ED=83=80=EC=9E=85=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/InputValidator.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/validator/InputValidator.js diff --git a/src/validator/InputValidator.js b/src/validator/InputValidator.js new file mode 100644 index 0000000..9c1e08f --- /dev/null +++ b/src/validator/InputValidator.js @@ -0,0 +1,30 @@ +const InputValidator = { + message: { + messageType: (value) => + typeof value === 'string' || 'message 는 문자열 타입이어야 합니다.', + messageLength: (value) => + value.trim().length >= 1 || 'message 는 1글자 이상이어야 합니다', + }, + options: { + optionsType: (value) => + typeof value === 'object' || 'options 는 개체 타입이어야 합니다.', + optionsHasPostProcessFn: (value) => + value.hasProperty('postProcessFn') || + 'options 는 postProcessFn 프로퍼티를 가지고 있어야 합니다.', + optionsHasValidation: (value) => + value.hasProperty('validation') || + 'options 는 validation 프로퍼티를 가지고 있어야 합니다.', + }, + postProcessFn: { + PostPrcoessFnType: (value) => + (value !== undefined && typeof value !== 'function') || + 'postProcessFn 는 함수여야 합니다.', + }, + validate: { + validateType: (value) => + (value !== undefined && typeof value !== 'function') || + 'validate 는 함수여야 합니다.', + }, +}; + +export default InputValidator; From db61a5698dae15222579693fcba267c2d94682a7 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 13:40:28 +0900 Subject: [PATCH 23/73] =?UTF-8?q?feat:=20validator=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=8B=9C=20=ED=83=80=EC=9E=85:=EA=B0=92=20?= =?UTF-8?q?=ED=98=95=ED=83=9C=EB=A1=9C=20=EC=82=AC=EC=9A=A9=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/createValidator.js | 37 +++++++++++++------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/validator/createValidator.js b/src/validator/createValidator.js index 9cc6904..8d125a9 100644 --- a/src/validator/createValidator.js +++ b/src/validator/createValidator.js @@ -1,31 +1,24 @@ const createValidator = (validation) => { - const validateKeyValue = (key, value) => { - if (validation[key] === undefined) { - throw new Error('해당 키 값이 validation 내부에 존재하지 않습니다.'); - } - const validate = validation[key](value); + const validateKeyValue = (keyType, value) => { + Object.keys(validation[keyType]).forEach((validationKey) => { + const validate = validation[keyType][validationKey](value); - if (validate !== true) { - throw new Error(validate); - } + if (validate !== true) { + throw new Error(validate); + } + }); }; - return (keys, values) => { - if (typeof keys === 'string' && typeof values === 'string') { - validateKeyValue(keys, values); - return; - } - if (Array.isArray(keys) && Array.isArray(values)) { - if (keys.length !== values.length) { - throw new Error('키 배열의 개수와 값 배열의 개수가 일치해야 합니다.'); + return (values) => { + Object.entries(values).map(([keyType, value]) => { + if (validation[keyType] === undefined) { + throw new Error( + `${keyType} 가 초기화 시 전달한 validation 내부에 존재하지 않습니다.`, + ); } - keys.forEach((key, index) => validateKeyValue(key, values[index])); - return; - } - throw new Error( - '매개변수로 전달한 keys 와 values 의 타입은 동일해야 합니다.', - ); + validateKeyValue(keyType, value); + }); }; }; From 1b52b542af7617c13fb063dc09912da1ad2180d5 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 13:45:51 +0900 Subject: [PATCH 24/73] =?UTF-8?q?feat:=20Input=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/Input.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/View/Input.js diff --git a/src/View/Input.js b/src/View/Input.js new file mode 100644 index 0000000..863d173 --- /dev/null +++ b/src/View/Input.js @@ -0,0 +1,35 @@ +import readlineAsync from '../utils/readline.js'; +import InputValidator from '../validator/InputValidator.js'; +import createValidator from '../validator/createValidator.js'; + +export default class Input { + #rl; + + constructor() { + this.#rl = readlineAsync; + this.validator = createValidator(InputValidator); + } + + async readInput( + message, + options = { + postProcessFn: undefined, + validate: undefined, + }, + ) { + try { + const { postProcessFn, validate } = options; + this.validator({ message, options, postProcessFn, validate }); + + const input = await this.#rl(message); + const postInput = postProcessFn ? postProcessFn(input) : input; + validate && validate(postInput); + + return postInput; + } catch (error) { + console.log(error); + + return this.input(message, options); + } + } +} From 1e5dd8b1431c7501e8bf7b3118f82601f628f35f Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:01:09 +0900 Subject: [PATCH 25/73] =?UTF-8?q?refactoring:=20validator=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/{ => View}/InputValidator.js | 0 src/validator/View/OutputValidator.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/validator/{ => View}/InputValidator.js (100%) create mode 100644 src/validator/View/OutputValidator.js diff --git a/src/validator/InputValidator.js b/src/validator/View/InputValidator.js similarity index 100% rename from src/validator/InputValidator.js rename to src/validator/View/InputValidator.js diff --git a/src/validator/View/OutputValidator.js b/src/validator/View/OutputValidator.js new file mode 100644 index 0000000..e69de29 From 0403738c2f401c3b8c3cb3d8ede86a822d9986ea Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:01:27 +0900 Subject: [PATCH 26/73] =?UTF-8?q?chore:=20InputValidator=20=EA=B2=BD?= =?UTF-8?q?=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 --- src/View/Input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Input.js b/src/View/Input.js index 863d173..0c1f637 100644 --- a/src/View/Input.js +++ b/src/View/Input.js @@ -1,5 +1,5 @@ import readlineAsync from '../utils/readline.js'; -import InputValidator from '../validator/InputValidator.js'; +import InputValidator from '../validator/View/InputValidator.js'; import createValidator from '../validator/createValidator.js'; export default class Input { From 6a37410456e04ff9c9c4e621e99d1bf782b0d265 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:24:34 +0900 Subject: [PATCH 27/73] =?UTF-8?q?chore:=20createValidator=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EA=B2=BD=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{validator => utils}/createValidator.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{validator => utils}/createValidator.js (100%) diff --git a/src/validator/createValidator.js b/src/utils/createValidator.js similarity index 100% rename from src/validator/createValidator.js rename to src/utils/createValidator.js From 33cc2faa586080d854ccd8a58e81fc4f3723a0c4 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:25:02 +0900 Subject: [PATCH 28/73] =?UTF-8?q?feat:=20OutputValidator=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/View/OutputValidator.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/validator/View/OutputValidator.js b/src/validator/View/OutputValidator.js index e69de29..456c9f8 100644 --- a/src/validator/View/OutputValidator.js +++ b/src/validator/View/OutputValidator.js @@ -0,0 +1,13 @@ +const OutputValidator = { + templateKey: { + templateKeyType: (value) => + typeof value === 'string' || 'templateKey 의 타입이 문자열이 아닙니다.', + }, + templateVariables: { + templateVariablesType: (value) => + typeof value === 'object' || + 'templateVariables 의 타입이 객체가 아닙니다.', + }, +}; + +export default OutputValidator; From f8626a8dd16ff5d0dfd5f8ecf81baf25d6ea9dac Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:25:11 +0900 Subject: [PATCH 29/73] =?UTF-8?q?feat:=20Output=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/Output.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/View/Output.js diff --git a/src/View/Output.js b/src/View/Output.js new file mode 100644 index 0000000..51fc61a --- /dev/null +++ b/src/View/Output.js @@ -0,0 +1,29 @@ +import createValidator from '../utils/createValidator.js'; +import OutputValidator from '../validator/View/OutputValidator.js'; + +export default class Output { + #template; + constructor({ template }) { + this.#template = template; + this.validator = createValidator(OutputValidator); + } + + print(...message) { + console.log(...message); + } + + lineBreak() { + console.log(''); + } + + format(templateKey, templateVariables) { + this.validator({ templateKey, templateVariables }); + let templateString = this.#template[templateKey]; + + Object.entires(templateVariables).forEach(([variable, value]) => { + templateString = templateString.replaceAll(`%{${variable}}`, value); + }); + + return templateString; + } +} From e0ddf1b83aa0c4f22305997ca5b1d5dc635d613f Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:25:43 +0900 Subject: [PATCH 30/73] =?UTF-8?q?chore:=20cretaeValidator=20=EC=9D=98=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EB=90=9C=20=EA=B2=BD=EB=A1=9C=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/Input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Input.js b/src/View/Input.js index 0c1f637..2dc6020 100644 --- a/src/View/Input.js +++ b/src/View/Input.js @@ -1,6 +1,6 @@ import readlineAsync from '../utils/readline.js'; import InputValidator from '../validator/View/InputValidator.js'; -import createValidator from '../validator/createValidator.js'; +import createValidator from '../utils/createValidator.js'; export default class Input { #rl; From 09f80276d0b287a1d9f01e29ae32f0b40f5808df Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:55:15 +0900 Subject: [PATCH 31/73] =?UTF-8?q?feat:=20=ED=94=84=EB=A1=9C=ED=8D=BC?= =?UTF-8?q?=ED=8B=B0=EC=99=80=20=EA=B4=80=EB=A0=A8=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=8A=94=20=EC=A0=95=EC=A0=81=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EC=A0=84=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/Output.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/View/Output.js b/src/View/Output.js index 51fc61a..69b7365 100644 --- a/src/View/Output.js +++ b/src/View/Output.js @@ -8,11 +8,11 @@ export default class Output { this.validator = createValidator(OutputValidator); } - print(...message) { + static print(...message) { console.log(...message); } - lineBreak() { + static lineBreak() { console.log(''); } From b39eaa73f23a3a3b548df54d0e2a0839be858a1d Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 14:55:24 +0900 Subject: [PATCH 32/73] =?UTF-8?q?feat:=20View=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/View.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/View/View.js diff --git a/src/View/View.js b/src/View/View.js new file mode 100644 index 0000000..c5118ef --- /dev/null +++ b/src/View/View.js @@ -0,0 +1,55 @@ +import Input from './Input.js'; +import Output from './Output.js'; + +export default class View { + constructor() { + this.input = new Input(); + this.output = new Output({ + template: { + printPurchaseQuantity: `%{quantity}개를 구매했습니다.`, + printLotto: `%{lotto}`, + printResult: ` + 당첨 통계\n + ----------------------\n + 3개 일치 (5,000원) - %{fifth}개 + 4개 일치 (50,000원) - %{fourth}개 + 5개 일치 (1,500,000 원) - %{third}개 + 5개 일치, 보너스 볼 일치 (30,000,000원) - %{second}개 + 6개 일치 (2,000,000,000원) - %{first}개\n + `, + printRevenue: `총 수익률은 %{revenue}%입니다.`, + }, + }); + } + + async inputMoney(options) { + return this.input.readInput('> 구매 금액을 입력해주세요. : ', options); + } + + async inputWinningLotto(options) { + return this.input.readInput('> 당첨 번호를 입력해주세요. : ', options); + } + + async inputBonusNumber(options) { + return this.input.readInput('> 보너스 번호를 입력해주세요. : ', options); + } + + printPurchaseQuantity(quantity) { + Output.print(this.output.format('printPurchaseQuantity', { quantity })); + } + + printLottos(lottos) { + lottos.forEach((lotto) => { + Output.print(this.output.format('printLotto', { lotto })); + }); + Output.lineBreak(); + } + + printResult(resultInfo) { + Output.print(this.output.format('printResult', resultInfo)); + } + + printRevenue(revenue) { + Output.print(this.output.format('printRevenue', { revenue })); + } +} From 8a08be95dacc01e41df92c7db7a9b7dc3a6045f2 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 15:44:04 +0900 Subject: [PATCH 33/73] =?UTF-8?q?feat:=20Lotto=20=EA=B0=80=20=EC=97=AC?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=EB=90=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=8B=A4=ED=98=95=EC=84=B1=EC=9D=84=20=EA=B3=A0?= =?UTF-8?q?=EB=A0=A4=ED=95=98=EC=97=AC=20=EA=B5=AC=ED=98=84=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/Lotto.test.js | 35 +++++++++++++++++++++++++++++++++++ src/domain/Lotto.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/__tests__/Lotto.test.js create mode 100644 src/domain/Lotto.js diff --git a/src/__tests__/Lotto.test.js b/src/__tests__/Lotto.test.js new file mode 100644 index 0000000..d26745a --- /dev/null +++ b/src/__tests__/Lotto.test.js @@ -0,0 +1,35 @@ +import { describe, expect, test } from 'vitest'; +import Lotto from '../domain/Lotto.js'; + +describe('Lotto 도메인 클래스에 대한 단위 테스트', () => { + const correctLotto = [1, 2, 3, 4, 5, 6]; + + test('Lotto 클래스는 콤마로 숫자를 구분한 문자열로 초기화할 수 있다.', () => { + const lotto = makeLottoMocking('1, 2, 3, 4, 5, 6'); + expect(lotto.accord(correctLotto)).toBe(6); + }); + + test('Lotto 클래스는 숫자 요소로 이뤄진 배열로 초기화할 수 있다.', () => { + const lotto = makeLottoMocking([1, 2, 3, 4, 5, 6]); + expect(lotto.accord(correctLotto)).toBe(6); + }); + + test('Lotto 클래스는 숫자로 치환할 수 잇는 문자 요소로 이뤄진 배열로 초기화할 수 있다.', () => { + const lotto = makeLottoMocking(['1', '2', '3', '4', '5', '6']); + expect(lotto.accord(correctLotto)).toBe(6); + }); + + test('Lotto 클래스는 숫자를 열거한 매개변수로 초기화할 수 있다.', () => { + const lotto = makeLottoMocking(1, 2, 3, 4, 5, 6); + expect(lotto.accord(correctLotto)).toBe(6); + }); + + test('Lotto 클래스는 문자열을 열거한 매개변수로 초기화할 수 있다.', () => { + const lotto = makeLottoMocking('1', '2', '3', '4', '5', '6'); + expect(lotto.accord(correctLotto)).toBe(6); + }); +}); + +function makeLottoMocking(...lotto) { + return new Lotto(...lotto); +} diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js new file mode 100644 index 0000000..0b3ebb3 --- /dev/null +++ b/src/domain/Lotto.js @@ -0,0 +1,35 @@ +import createValidator from '../utils/createValidator.js'; +import LottoValidator from '../validator/domain/LottoValidator.js'; + +export default class Lotto { + #lotto; + + constructor(...lotto) { + this.validator = createValidator(LottoValidator); + this.setLotto(...lotto); + } + + setLotto(...lotto) { + if (Array.isArray(lotto[0])) { + lotto = lotto.flat(); + } + if (lotto.length === 1) { + lotto = lotto[0].split(',').map((number) => number.trim()); + } + const nextLotto = [...lotto] + .map((number) => Number(number)) + .sort((a, b) => a - b); + + // this.validator({ lotto: nextLotto }); + this.#lotto = [...nextLotto]; + } + + accord(compare) { + compare.sort((a, b) => a - b); + + return compare.reduce( + (prev, curr, index) => (curr === this.#lotto[index] ? prev + 1 : prev), + 0, + ); + } +} From a42dd9b6e0f34be673fa4e89548fe3e0063dc4f3 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 16:10:16 +0900 Subject: [PATCH 34/73] =?UTF-8?q?chore:=20Prettier=20=EC=84=A4=EC=A0=95=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 --- .prettierrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 6923972..188f27f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -7,5 +7,7 @@ "bracketSameLine": false, "bracketSpacing": true, "arrowParens": "always", - "singleAttributePerLine": true + "singleAttributePerLine": true, + "quoteProps": "as-needed", + "trailingComma": "all" } From d295ddfcca655ecbadfd996bb5cd7917655be191 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Fri, 12 Jul 2024 16:10:43 +0900 Subject: [PATCH 35/73] =?UTF-8?q?feat:=20Lotto=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EC=8B=9C=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=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 --- src/__tests__/Lotto.test.js | 46 ++++++++++++++++++++++++++ src/domain/Lotto.js | 2 +- src/validator/domain/LottoValidator.js | 19 +++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/validator/domain/LottoValidator.js diff --git a/src/__tests__/Lotto.test.js b/src/__tests__/Lotto.test.js index d26745a..e12871c 100644 --- a/src/__tests__/Lotto.test.js +++ b/src/__tests__/Lotto.test.js @@ -28,6 +28,52 @@ describe('Lotto 도메인 클래스에 대한 단위 테스트', () => { const lotto = makeLottoMocking('1', '2', '3', '4', '5', '6'); expect(lotto.accord(correctLotto)).toBe(6); }); + + test.each([ + { lotto: '안, 녕, 하, 세, 요, !' }, + { lotto: [1, 2, 3, 4, 5, '꽝'] }, + ])( + '숫자로 치환할 수 없는 문자($lotto)로 초기화할 경우 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeLottoMocking(lotto); + }).toThrowError('숫자로 변환할 수 없는 문자가 포함되어 있습니다.'); + }, + ); + + test.each([{ lotto: '1, 1, 2, 3, 4, 5' }, { lotto: [1, 1, 2, 3, 4, 5, 6] }])( + '중복되는 숫자($lotto)로 초기화할 경우 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeLottoMocking(lotto); + }).toThrowError('중복되는 숫자가 포함되어 있습니다.'); + }, + ); + + test.each([ + { lotto: '1' }, + { lotto: [1, 2, 3] }, + { lotto: '1, 2, 3, 4, 5, 6, 7' }, + { lotto: [1, 2, 3, 4, 5, 6, 7] }, + ])('로또번호($lotto)의 개수가 6이 아니면 에러를 반환한다.', ({ lotto }) => { + expect(() => { + makeLottoMocking(lotto); + }).toThrowError('로또번호의 개수는 6개여야 합니다.'); + }); + + test.each([ + { lotto: '0, 1, 2, 3, 4, 5' }, + { lotto: '1, 2, 3, 4, 5, 99' }, + { lotto: [0, 1, 2, 3, 4, 5] }, + { lotto: [1, 2, 3, 4, 5, 99] }, + ])( + '로또번호($lotto)의 각 번호가 1~45 사이의 숫자가 아니면 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeLottoMocking(lotto); + }).toThrowError('로또번호의 각 번호는 1~45 사이여야 합니다.'); + }, + ); }); function makeLottoMocking(...lotto) { diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 0b3ebb3..c26e950 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -20,7 +20,7 @@ export default class Lotto { .map((number) => Number(number)) .sort((a, b) => a - b); - // this.validator({ lotto: nextLotto }); + this.validator({ lotto: nextLotto }); this.#lotto = [...nextLotto]; } diff --git a/src/validator/domain/LottoValidator.js b/src/validator/domain/LottoValidator.js new file mode 100644 index 0000000..0d63475 --- /dev/null +++ b/src/validator/domain/LottoValidator.js @@ -0,0 +1,19 @@ +const LottoValidator = { + lotto: { + checkNaN: (value) => + value.every((number) => !isNaN(number)) || + '숫자로 변환할 수 없는 문자가 포함되어 있습니다.', + checkDuplicate: (value) => { + const set = new Set(value); + + return set.size === value.length || '중복되는 숫자가 포함되어 있습니다.'; + }, + checkLength: (value) => + value.length === 6 || '로또번호의 개수는 6개여야 합니다.', + checkNumberRange: (value) => + value.every((number) => 1 <= number && number <= 45) || + '로또번호의 각 번호는 1~45 사이여야 합니다.', + }, +}; + +export default LottoValidator; From 368e2daa9e77727b9e8c0fdf9b6fe3e3db445e84 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Sat, 13 Jul 2024 15:31:59 +0900 Subject: [PATCH 36/73] =?UTF-8?q?refactoring:=20validator=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=9D=BC=EA=B4=80=EC=84=B1=20?= =?UTF-8?q?=EC=9E=88=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/View/InputValidator.js | 14 +++++++------- src/validator/View/OutputValidator.js | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/validator/View/InputValidator.js b/src/validator/View/InputValidator.js index 9c1e08f..1112399 100644 --- a/src/validator/View/InputValidator.js +++ b/src/validator/View/InputValidator.js @@ -1,27 +1,27 @@ const InputValidator = { message: { - messageType: (value) => + checkType: (value) => typeof value === 'string' || 'message 는 문자열 타입이어야 합니다.', - messageLength: (value) => + checkLength: (value) => value.trim().length >= 1 || 'message 는 1글자 이상이어야 합니다', }, options: { - optionsType: (value) => + checkType: (value) => typeof value === 'object' || 'options 는 개체 타입이어야 합니다.', - optionsHasPostProcessFn: (value) => + checkHasPostProcessFn: (value) => value.hasProperty('postProcessFn') || 'options 는 postProcessFn 프로퍼티를 가지고 있어야 합니다.', - optionsHasValidation: (value) => + checkHasValidation: (value) => value.hasProperty('validation') || 'options 는 validation 프로퍼티를 가지고 있어야 합니다.', }, postProcessFn: { - PostPrcoessFnType: (value) => + checkType: (value) => (value !== undefined && typeof value !== 'function') || 'postProcessFn 는 함수여야 합니다.', }, validate: { - validateType: (value) => + checkType: (value) => (value !== undefined && typeof value !== 'function') || 'validate 는 함수여야 합니다.', }, diff --git a/src/validator/View/OutputValidator.js b/src/validator/View/OutputValidator.js index 456c9f8..2f65b4c 100644 --- a/src/validator/View/OutputValidator.js +++ b/src/validator/View/OutputValidator.js @@ -1,10 +1,10 @@ const OutputValidator = { templateKey: { - templateKeyType: (value) => + checkType: (value) => typeof value === 'string' || 'templateKey 의 타입이 문자열이 아닙니다.', }, templateVariables: { - templateVariablesType: (value) => + checkType: (value) => typeof value === 'object' || 'templateVariables 의 타입이 객체가 아닙니다.', }, From caceb345506fd0b8aa613dcdd8a8793ac5b0acea Mon Sep 17 00:00:00 2001 From: Suyeon Date: Sat, 13 Jul 2024 15:35:40 +0900 Subject: [PATCH 37/73] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/Lotto.test.js | 6 ++++++ src/domain/Lotto.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/__tests__/Lotto.test.js b/src/__tests__/Lotto.test.js index e12871c..76b17d7 100644 --- a/src/__tests__/Lotto.test.js +++ b/src/__tests__/Lotto.test.js @@ -74,6 +74,12 @@ describe('Lotto 도메인 클래스에 대한 단위 테스트', () => { }).toThrowError('로또번호의 각 번호는 1~45 사이여야 합니다.'); }, ); + + test('로또 번호를 가져올 수 있다.', () => { + expect(makeLottoMocking([1, 2, 3, 4, 5, 6]).get()).toStrictEqual([ + 1, 2, 3, 4, 5, 6, + ]); + }); }); function makeLottoMocking(...lotto) { diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index c26e950..5c0bd21 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -32,4 +32,8 @@ export default class Lotto { 0, ); } + + get() { + return [...this.#lotto]; + } } From 8c1fe700f6361e85f9be8adf2bec6776df9710a5 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Sun, 14 Jul 2024 16:06:27 +0900 Subject: [PATCH 38/73] =?UTF-8?q?feat:=20=EC=99=B8=EB=B6=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20validator=20=ED=94=84=EB=A1=9C=ED=8D=BC=ED=8B=B0?= =?UTF-8?q?=EC=97=90=20=EC=A0=91=EA=B7=BC=ED=95=98=EC=A7=80=20=EB=AA=BB?= =?UTF-8?q?=ED=95=98=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/Lotto.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 5c0bd21..4924539 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -2,10 +2,11 @@ import createValidator from '../utils/createValidator.js'; import LottoValidator from '../validator/domain/LottoValidator.js'; export default class Lotto { + #validator; #lotto; constructor(...lotto) { - this.validator = createValidator(LottoValidator); + this.#validator = createValidator(LottoValidator); this.setLotto(...lotto); } @@ -20,7 +21,7 @@ export default class Lotto { .map((number) => Number(number)) .sort((a, b) => a - b); - this.validator({ lotto: nextLotto }); + this.#validator({ lotto: nextLotto }); this.#lotto = [...nextLotto]; } From 9dffa3a47d30bd6066d0d48e2fcb59133ec9be00 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Sun, 14 Jul 2024 16:06:54 +0900 Subject: [PATCH 39/73] =?UTF-8?q?fix:=20lotto=20=EC=9D=98=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B2=94=EC=9C=84=20=EC=B2=B4=ED=81=AC=EA=B0=80=20?= =?UTF-8?q?=EC=9D=B4=EB=A4=84=EC=A7=80=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/domain/LottoValidator.js | 31 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/validator/domain/LottoValidator.js b/src/validator/domain/LottoValidator.js index 0d63475..bbe59c0 100644 --- a/src/validator/domain/LottoValidator.js +++ b/src/validator/domain/LottoValidator.js @@ -1,6 +1,22 @@ +import LottoRule from '../../domain/LottoRule.js'; + const LottoValidator = { + money: { + checkType: (value) => + isNaN(value) === false || + '입력으로 받은 금액은 숫자로 변환가능해야 합니다.', + checkRange: (value) => + LottoRule.lottoPrice <= value || + value <= LottoRule.limitPrice || + `구매 금액은 ${LottoRule.lottoPrice} 원 이상, ${LottoRule.limitPrice} 원 이하만 가능합니다.`, + }, + number: { + checkNumberRange: (value) => + (LottoRule.minNumber <= value && value <= LottoRule.maxNumber) || + `로또 번호는 ${LottoRule.minNumber}~${LottoRule.maxNumber}사이의 숫자여야 합니다.`, + }, lotto: { - checkNaN: (value) => + checkType: (value) => value.every((number) => !isNaN(number)) || '숫자로 변환할 수 없는 문자가 포함되어 있습니다.', checkDuplicate: (value) => { @@ -8,11 +24,16 @@ const LottoValidator = { return set.size === value.length || '중복되는 숫자가 포함되어 있습니다.'; }, - checkLength: (value) => - value.length === 6 || '로또번호의 개수는 6개여야 합니다.', checkNumberRange: (value) => - value.every((number) => 1 <= number && number <= 45) || - '로또번호의 각 번호는 1~45 사이여야 합니다.', + value.every((number) => + Object.values(LottoValidator.number).every( + (validate) => validate(number) === true, + ), + ) || + `로또번호의 각 번호는 ${LottoRule.minNumber}~${LottoRule.maxNumber} 사이여야 합니다.`, + checkLength: (value) => + value.length === LottoRule.length || + `로또번호의 개수는 ${LottoRule.length}개여야 합니다.`, }, }; From 0b7634b72408bfdbe439089438d9308142364c54 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 13:20:47 +0900 Subject: [PATCH 40/73] =?UTF-8?q?feat:=20WinLotto=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EA=B8=B0=EB=B0=98=20=EA=B8=B0=EB=8A=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 --- src/__tests__/WinLotto.test.js | 81 ++++++++++++++++++++++++++++++++++ src/domain/WinLotto.js | 17 +++++++ 2 files changed, 98 insertions(+) create mode 100644 src/__tests__/WinLotto.test.js create mode 100644 src/domain/WinLotto.js diff --git a/src/__tests__/WinLotto.test.js b/src/__tests__/WinLotto.test.js new file mode 100644 index 0000000..4522219 --- /dev/null +++ b/src/__tests__/WinLotto.test.js @@ -0,0 +1,81 @@ +import { describe, test, expect } from 'vitest'; +import WinLotto from '../domain/WinLotto'; + +describe('WinLotto 클래스에 대한 단위 테스트', () => { + const correctLotto = [1, 2, 3, 4, 5, 6, 7]; + + test('WinLotto 클래스의 lotto 프로퍼티를 콤마로 숫자를 구분한 문자열로 초기화할 수 있다.', () => { + const winLotto = makeWinLottoMocking('1, 2, 3, 4, 5, 6, 7'); + expect(winLotto.accord(correctLotto)).toBe(7); + }); + + test('WinLotto 클래스의 lotto 프로퍼티를 숫자 요소로 이뤄진 배열로 초기화할 수 있다.', () => { + const winLotto = makeWinLottoMocking([1, 2, 3, 4, 5, 6, 7]); + expect(winLotto.accord(correctLotto)).toBe(7); + }); + + test('WinLotto 클래스의 lotto 프로퍼티를 숫자로 치환할 수 잇는 문자 요소로 이뤄진 배열로 초기화할 수 있다.', () => { + const winLotto = makeWinLottoMocking(['1', '2', '3', '4', '5', '6', '7']); + expect(winLotto.accord(correctLotto)).toBe(7); + }); + + test('WinLotto 클래스의 lotto 프로퍼티를 숫자를 열거한 매개변수로 초기화할 수 있다.', () => { + const winLotto = makeWinLottoMocking(1, 2, 3, 4, 5, 6, 7); + expect(winLotto.accord(correctLotto)).toBe(7); + }); + + test('WinLotto 클래스의 lotto 프로퍼티를 문자열을 열거한 매개변수로 초기화할 수 있다.', () => { + const winLotto = makeWinLottoMocking('1', '2', '3', '4', '5', '6', '7'); + expect(winLotto.accord(correctLotto)).toBe(7); + }); + + test.each([ + { lotto: '안, 녕, 하, 세, 요, !, !' }, + { lotto: [1, 2, 3, 4, 5, '꽝', '꽝!'] }, + ])( + '숫자로 치환할 수 없는 문자($lotto)로 초기화할 경우 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeWinLottoMocking(lotto); + }).toThrowError('숫자로 변환할 수 없는 문자가 포함되어 있습니다.'); + }, + ); + + test.each([ + { lotto: '1, 1, 2, 3, 4, 5, 6' }, + { lotto: [1, 1, 2, 3, 4, 5, 6] }, + ])('중복되는 숫자($lotto)로 초기화할 경우 에러를 반환한다.', ({ lotto }) => { + expect(() => { + makeWinLottoMocking(lotto); + }).toThrowError('중복되는 숫자가 포함되어 있습니다.'); + }); + + test.each([ + { lotto: '1' }, + { lotto: [1, 2, 3] }, + { lotto: '1, 2, 3, 4, 5, 6' }, + { lotto: [1, 2, 3, 4, 5, 6] }, + ])('로또번호($lotto)의 개수가 7이 아니면 에러를 반환한다.', ({ lotto }) => { + expect(() => { + makeWinLottoMocking(lotto); + }).toThrowError('로또번호의 개수는 7개여야 합니다.'); + }); + + test.each([ + { lotto: '0, 1, 2, 3, 4, 5, 6' }, + { lotto: '1, 2, 3, 4, 5, 6, 99' }, + { lotto: [0, 1, 2, 3, 4, 5, 6] }, + { lotto: [1, 2, 3, 4, 5, 6, 99] }, + ])( + '로또번호($lotto)의 각 번호가 1~45 사이의 숫자가 아니면 에러를 반환한다.', + ({ lotto }) => { + expect(() => { + makeWinLottoMocking(lotto); + }).toThrowError('로또번호의 각 번호는 1~45 사이여야 합니다.'); + }, + ); +}); + +function makeWinLottoMocking(...lotto) { + return new WinLotto(...lotto); +} diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js new file mode 100644 index 0000000..99b9aeb --- /dev/null +++ b/src/domain/WinLotto.js @@ -0,0 +1,17 @@ +import Lotto from './Lotto.js'; +import LottoValidator from '../validator/domain/LottoValidator.js'; +import createValidator from '../utils/createValidator.js'; + +export default class WinLotto extends Lotto { + constructor(...lotto) { + super(...lotto); + } + + set(...lotto) { + const validator = createValidator(LottoValidator); + const normalizedLotto = Lotto.normalize(...lotto); + + validator({ common: normalizedLotto, winLotto: normalizedLotto }); + this.lotto = normalizedLotto; + } +} From 7355163f2a191141ce1982be0455ad355760ee14 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 13:32:50 +0900 Subject: [PATCH 41/73] =?UTF-8?q?feat:=20Lotto=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EA=B8=B0=EB=8A=A5=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - set 함수에서 lotto 를 배열타입으로 만들어주는 코드를 normalize 함수로 분리 - lotto 를 private 이 프로퍼티로 관리하지 않는 것으로 변경 - validator 를 메서드 안에서 선언하는 것으로 변경 --- src/domain/Lotto.js | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 4924539..0217e1a 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -2,39 +2,45 @@ import createValidator from '../utils/createValidator.js'; import LottoValidator from '../validator/domain/LottoValidator.js'; export default class Lotto { - #validator; - #lotto; + lotto; constructor(...lotto) { - this.#validator = createValidator(LottoValidator); - this.setLotto(...lotto); + this.set(...lotto); } - setLotto(...lotto) { + static normalize(...lotto) { if (Array.isArray(lotto[0])) { lotto = lotto.flat(); } if (lotto.length === 1) { lotto = lotto[0].split(',').map((number) => number.trim()); } - const nextLotto = [...lotto] - .map((number) => Number(number)) - .sort((a, b) => a - b); + return [...lotto].map((number) => Number(number)).sort((a, b) => a - b); + } - this.#validator({ lotto: nextLotto }); - this.#lotto = [...nextLotto]; + get() { + return [...this.lotto]; } - accord(compare) { - compare.sort((a, b) => a - b); + set(...lotto) { + const validator = createValidator(LottoValidator); + const normalizedLotto = Lotto.normalize(...lotto); - return compare.reduce( - (prev, curr, index) => (curr === this.#lotto[index] ? prev + 1 : prev), - 0, - ); + validator({ common: normalizedLotto, defaultLotto: normalizedLotto }); + this.lotto = normalizedLotto; } - get() { - return [...this.#lotto]; + accord(...compareLotto) { + const normalizedCompareLotto = Lotto.normalize(...compareLotto); + const set = new Set( + this.lotto.length > normalizedCompareLotto.length + ? this.lotto + : normalizedCompareLotto, + ); + + return normalizedCompareLotto.reduce( + (prev, curr) => (set.has(curr) ? prev + 1 : prev), + 0, + ); } } From bf124270da741ea625aa7fae8e9cc9ad6a8d7158 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 13:33:16 +0900 Subject: [PATCH 42/73] =?UTF-8?q?refactoring:=20readLine=20=EC=9C=A0?= =?UTF-8?q?=ED=8B=B8=ED=95=A8=EC=88=98=EB=A5=BC=20default=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EB=A1=9C=20=EB=82=B4=EB=B3=B4=EB=82=B4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/readline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/readline.js b/src/utils/readline.js index 78e3d39..0267157 100644 --- a/src/utils/readline.js +++ b/src/utils/readline.js @@ -1,6 +1,6 @@ import readline from 'readline'; -export function readLineAsync(query) { +export default function readLineAsync(query) { return new Promise((resolve, reject) => { if (arguments.length !== 1) { reject(new Error('arguments must be 1')); From 2c4b9be83e9d00ce00d416cbe0d2b3da3fba43f9 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 13:33:46 +0900 Subject: [PATCH 43/73] =?UTF-8?q?refactoring:=20LottoValidator=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EA=B3=B5=ED=86=B5=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20?= =?UTF-8?q?=EA=B2=80=EC=82=AC=EC=99=80=20=EA=B8=B0=EB=B3=B8=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90,=20=EC=9A=B0=EC=8A=B9=20=EB=A1=9C=EB=98=90=EB=A5=BC?= =?UTF-8?q?=20=EA=B5=AC=EB=B6=84=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/domain/LottoValidator.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/validator/domain/LottoValidator.js b/src/validator/domain/LottoValidator.js index bbe59c0..4d45346 100644 --- a/src/validator/domain/LottoValidator.js +++ b/src/validator/domain/LottoValidator.js @@ -15,7 +15,7 @@ const LottoValidator = { (LottoRule.minNumber <= value && value <= LottoRule.maxNumber) || `로또 번호는 ${LottoRule.minNumber}~${LottoRule.maxNumber}사이의 숫자여야 합니다.`, }, - lotto: { + common: { checkType: (value) => value.every((number) => !isNaN(number)) || '숫자로 변환할 수 없는 문자가 포함되어 있습니다.', @@ -31,9 +31,16 @@ const LottoValidator = { ), ) || `로또번호의 각 번호는 ${LottoRule.minNumber}~${LottoRule.maxNumber} 사이여야 합니다.`, + }, + defaultLotto: { + checkLength: (value) => + value.length === LottoRule.defaultLength || + `로또번호의 개수는 ${LottoRule.defaultLength}개여야 합니다.`, + }, + winLotto: { checkLength: (value) => - value.length === LottoRule.length || - `로또번호의 개수는 ${LottoRule.length}개여야 합니다.`, + value.length === LottoRule.winLength || + `로또번호의 개수는 ${LottoRule.winLength}개여야 합니다.`, }, }; From 892eaf0a6350eab5c0a9fbd9276231359b252419 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 13:34:00 +0900 Subject: [PATCH 44/73] =?UTF-8?q?feat:=20Lotto=20=EC=9D=98=20=EC=84=B8?= =?UTF-8?q?=ED=8C=85=EA=B3=BC=20=EA=B4=80=EB=A0=A8=EB=90=9C=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoRule.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/domain/LottoRule.js diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js new file mode 100644 index 0000000..6cdfbf8 --- /dev/null +++ b/src/domain/LottoRule.js @@ -0,0 +1,22 @@ +import generateRandomNumbers from '../utils/generateRandomNumbers.js'; + +const LottoRule = { + lottoPrice: 1000, + limitPrice: 10_000_000, + minNumber: 1, + maxNumber: 45, + defaultLength: 6, + winLength: 7, + exchange: (money) => { + return Math.floor(money / LottoRule.lottoPrice); + }, + generateLottoNumbers: () => { + return generateRandomNumbers( + LottoRule.defaultLength, + LottoRule.minNumber, + LottoRule.maxNumber, + ); + }, +}; + +export default LottoRule; From 309a23065e97dc4be5255a744a7b9bbebdc1f33b Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 13:34:50 +0900 Subject: [PATCH 45/73] =?UTF-8?q?feat:=20=EC=9E=AC=EC=8B=9C=EC=9E=91=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=EC=97=90=20=EA=B4=80=ED=95=9C=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/validator/View/InputValidator.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/validator/View/InputValidator.js b/src/validator/View/InputValidator.js index 1112399..77d3408 100644 --- a/src/validator/View/InputValidator.js +++ b/src/validator/View/InputValidator.js @@ -25,6 +25,14 @@ const InputValidator = { (value !== undefined && typeof value !== 'function') || 'validate 는 함수여야 합니다.', }, + restart: { + checkValue: (value) => + value === 'y' || + value === 'Y' || + value === 'n' || + value === 'N' || + '재시작 여부는 영문자 y 혹은 n 의 값이어야 합니다.', + }, }; export default InputValidator; From bdfaeb0510a52720aead8dc436b73fa19b050f13 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 14:13:09 +0900 Subject: [PATCH 46/73] =?UTF-8?q?refactoring:=20=EB=9E=9C=EB=8D=A4=20?= =?UTF-8?q?=EB=B0=B0=EC=97=B4=EC=9D=84=20=EC=83=9D=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=97=AD=ED=95=A0=EC=9D=84=20LottoRule=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=B2=98=EB=A6=AC=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoRule.js | 15 +++++++++------ src/utils/generateRandomNumber.js | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 src/utils/generateRandomNumber.js diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js index 6cdfbf8..c5bfd53 100644 --- a/src/domain/LottoRule.js +++ b/src/domain/LottoRule.js @@ -1,5 +1,6 @@ -import generateRandomNumbers from '../utils/generateRandomNumbers.js'; +import generateRandomNumber from '../utils/generateRandomNumber.js'; +// 어떤 변수들은 대문자로 변경하는 게 좋지 않을까요 const LottoRule = { lottoPrice: 1000, limitPrice: 10_000_000, @@ -11,11 +12,13 @@ const LottoRule = { return Math.floor(money / LottoRule.lottoPrice); }, generateLottoNumbers: () => { - return generateRandomNumbers( - LottoRule.defaultLength, - LottoRule.minNumber, - LottoRule.maxNumber, - ); + const set = new Set(); + + while (set.size < LottoRule.defaultLength) { + set.add(generateRandomNumber(LottoRule.minNumber, LottoRule.maxNumber)); + } + + return [...set]; }, }; diff --git a/src/utils/generateRandomNumber.js b/src/utils/generateRandomNumber.js new file mode 100644 index 0000000..9c646bb --- /dev/null +++ b/src/utils/generateRandomNumber.js @@ -0,0 +1,5 @@ +const generateRandomNumber = (min, max) => { + return Math.random() * (max - min) + min; +}; + +export default generateRandomNumber; From 7dc05e4eff773500cdf293b0a2b984a45c03ef43 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:34:42 +0900 Subject: [PATCH 47/73] =?UTF-8?q?feat:=20WinLotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=EC=84=9C=20=EB=A1=9C=EB=98=90=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=A5=BC=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/WinLotto.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index 99b9aeb..92c864d 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -1,6 +1,7 @@ import Lotto from './Lotto.js'; import LottoValidator from '../validator/domain/LottoValidator.js'; import createValidator from '../utils/createValidator.js'; +import LottoRule from './LottoRule.js'; export default class WinLotto extends Lotto { constructor(...lotto) { @@ -14,4 +15,47 @@ export default class WinLotto extends Lotto { validator({ common: normalizedLotto, winLotto: normalizedLotto }); this.lotto = normalizedLotto; } + + isBonusCorrect(lotto) { + const bonusNumber = this.lotto.at(-1); + + return lotto.includes(bonusNumber); + } + + getRank(lotto) { + const bonusCorrect = this.isBonusCorrect(lotto); + const accordCount = this.accord(lotto) - bonusCorrect ? 1 : 0; + + for (const rank of LottoRule.winningInfo) { + if (accordCount === LottoRule.winningInfo[rank].accord) { + if (LottoRule.winningInfo[rank].checkBonus && bonusCorrect) { + return rank; + } + + return rank; + } + } + } + + getWinningResult(lottos) { + const winningResult = { + prize: 0, + purchases: lottos.length * LottoRule.lottoPrice, + details: {}, + prizes: {}, + }; + + Object.entries(LottoRule.moneyByRank).forEach(([rank, money]) => { + winningResult.details[rank] = 0; + winningResult.prizes[rank + 'Money'] = money; + }); + lottos.forEach((lotto) => { + const rank = this.getRank(lotto.get()); + + winningResult.details[rank] += 1; + winningResult.prize += LottoRule.moneyByRank[rank]; + }); + + return winningResult; + } } From f0dd84c9e092d0545c4d958b48b60ea74210de0a Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:34:57 +0900 Subject: [PATCH 48/73] =?UTF-8?q?feat:=20controller=20=ED=98=B8=EC=B6=9C?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main.js diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..1adcc5c --- /dev/null +++ b/src/main.js @@ -0,0 +1,18 @@ +import View from './View/View.js'; +import Lotto from './domain/Lotto.js'; +import LottoController from './domain/LottoController.js'; +import WinLotto from './domain/WinLotto.js'; + +async function main() { + const lottoController = new LottoController({ + view: View, + lotto: Lotto, + winLotto: WinLotto, + }); + + await lottoController.run(); +} + +main(); + +export default main; From 940c02e00f7a843782437ed8e972c3906e9e5880 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:35:08 +0900 Subject: [PATCH 49/73] =?UTF-8?q?feat:=20LottoController=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/domain/LottoController.js diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js new file mode 100644 index 0000000..9783ed8 --- /dev/null +++ b/src/domain/LottoController.js @@ -0,0 +1,70 @@ +import createValidator from '../utils/createValidator.js'; +import InputValidator from '../validator/View/InputValidator.js'; +import LottoValidation from '../validator/domain/LottoValidator.js'; +import LottoRule from './LottoRule.js'; + +export default class LottoController { + constructor({ view, lotto, winLotto }) { + this.view = new view(); + this.lotto = lotto; + this.winLotto = winLotto; + } + + async run() { + while (true) { + const lottos = await this.getLottos(); + this.view.printLottos(lottos.map((lotto) => lotto.get())); + + const winLotto = await this.getwinLotto(); + const { prize, purchases, details, prizes } = + winLotto.getWinninResult(lottos); + + this.view.printwinsResult({ ...details, prizes }); + this.view.printRevenue(prize / purchases); + + const restart = await this.restart(); + + if (restart === 'n' || restart === 'N') { + break; + } + } + } + + async getLottos() { + const validator = createValidator(LottoValidation); + const money = await this.view.inputMoney({ + postProcessFn: (value) => Number(value), + validate: validator({ money }), + }); + const quantity = LottoRule.exchange(money); + + return [...new Array(quantity)].map( + new this.lotto(LottoRule.generateLottoNumbers()), + ); + } + + async getwinLotto() { + const validator = createValidator(LottoValidation); + const winLotto = await this.view.inputwinLotto({ + postProcessFn: (value) => + value.split(',').map((number) => Number(number)), + validate: validator({ common: winLotto }), + }); + const bonusNumber = await this.view.inputBonusNumber({ + postProcessFn: (value) => Number(value), + validate: validator({ number: bonusNumber }), + }); + + return new this.winLotto([...winLotto, bonusNumber]); + } + + async getRestart() { + const validator = createValidator(InputValidator); + const restart = await this.view.inputRestart({ + postProcessFn: (value) => value.trim(), + validate: validator({ restart }), + }); + + return restart; + } +} From 1f36f47972f97525c1c29a65bd5457e7b6c3a803 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:40:29 +0900 Subject: [PATCH 50/73] =?UTF-8?q?refactoring:=20LottoRule=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=8B=B9=EC=B2=A8=EA=B2=B0=EA=B3=BC=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EB=8B=B4=EA=B3=A0=EC=9E=88=EB=8A=94=20?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EA=B5=AC=EC=A1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoRule.js | 30 ++++++++++++++++++++++++++++-- src/domain/WinLotto.js | 9 +++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js index c5bfd53..066d53b 100644 --- a/src/domain/LottoRule.js +++ b/src/domain/LottoRule.js @@ -1,13 +1,39 @@ import generateRandomNumber from '../utils/generateRandomNumber.js'; -// 어떤 변수들은 대문자로 변경하는 게 좋지 않을까요 const LottoRule = { - lottoPrice: 1000, + lottoPrice: 1_000, limitPrice: 10_000_000, minNumber: 1, maxNumber: 45, defaultLength: 6, winLength: 7, + winningInfo: { + first: { + prize: 2_000_000_000, + checkBonus: false, + accord: 6, + }, + second: { + prize: 30_000_000, + checkBonus: true, + accord: 5, + }, + third: { + prize: 1_500_000, + checkBonus: false, + accord: 5, + }, + fourth: { + prize: 50_000, + checkBonus: false, + accord: 4, + }, + fifth: { + prize: 5_000, + checkBonus: false, + accord: 3, + }, + }, exchange: (money) => { return Math.floor(money / LottoRule.lottoPrice); }, diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index 92c864d..57d5b08 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -31,10 +31,11 @@ export default class WinLotto extends Lotto { if (LottoRule.winningInfo[rank].checkBonus && bonusCorrect) { return rank; } - return rank; } } + + return 'none'; } getWinningResult(lottos) { @@ -45,15 +46,15 @@ export default class WinLotto extends Lotto { prizes: {}, }; - Object.entries(LottoRule.moneyByRank).forEach(([rank, money]) => { + Object.entries(LottoRule.winningInfo).forEach(([rank, rankInfo]) => { winningResult.details[rank] = 0; - winningResult.prizes[rank + 'Money'] = money; + winningResult.prizes[rank + 'Money'] = rankInfo.prize; }); lottos.forEach((lotto) => { const rank = this.getRank(lotto.get()); winningResult.details[rank] += 1; - winningResult.prize += LottoRule.moneyByRank[rank]; + winningResult.prize += LottoRule.winningInfo[rank].prize; }); return winningResult; From ebefaebffe45a7116e664313bbd2c3ebd375cc71 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:40:56 +0900 Subject: [PATCH 51/73] =?UTF-8?q?feat:=20view=20=EC=9D=98=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=EA=B8=88=EC=95=A1=EC=9D=84=20=EC=99=B8=EB=B6=80?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A3=BC=EC=9E=85=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/View.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/View/View.js b/src/View/View.js index c5118ef..23ee4e3 100644 --- a/src/View/View.js +++ b/src/View/View.js @@ -8,14 +8,14 @@ export default class View { template: { printPurchaseQuantity: `%{quantity}개를 구매했습니다.`, printLotto: `%{lotto}`, - printResult: ` + printNumberOfWins: ` 당첨 통계\n ----------------------\n - 3개 일치 (5,000원) - %{fifth}개 - 4개 일치 (50,000원) - %{fourth}개 - 5개 일치 (1,500,000 원) - %{third}개 - 5개 일치, 보너스 볼 일치 (30,000,000원) - %{second}개 - 6개 일치 (2,000,000,000원) - %{first}개\n + 3개 일치 (%{fifthMoney}원) - %{fifth}개 + 4개 일치 (%{fourthMoney}원) - %{fourth}개 + 5개 일치 (%{thirdMoney}원) - %{third}개 + 5개 일치, 보너스 볼 일치 (%{secondMoney}원) - %{second}개 + 6개 일치 (%{firstMoney}원) - %{first}개\n `, printRevenue: `총 수익률은 %{revenue}%입니다.`, }, @@ -34,6 +34,13 @@ export default class View { return this.input.readInput('> 보너스 번호를 입력해주세요. : ', options); } + async inputRestart(options) { + return this.input.readInput( + '> 로또를 다시 구매하시겠습니까? (예: y, 아니오: n) : ', + options, + ); + } + printPurchaseQuantity(quantity) { Output.print(this.output.format('printPurchaseQuantity', { quantity })); } @@ -45,8 +52,8 @@ export default class View { Output.lineBreak(); } - printResult(resultInfo) { - Output.print(this.output.format('printResult', resultInfo)); + printNumberOfWins(lottoResult) { + Output.print(this.output.format('printNumberOfWins', lottoResult)); } printRevenue(revenue) { From 26289834ec5d8bc75fcff284a16d31bb3ca0f43d Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:44:34 +0900 Subject: [PATCH 52/73] =?UTF-8?q?fix:=20input=20Validate=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=EC=97=90=20=EC=84=A0=EC=96=B8=20?= =?UTF-8?q?=EC=A0=84=EC=9D=98=20=EA=B0=92=EC=9D=84=20=EB=84=A3=EC=96=B4?= =?UTF-8?q?=EC=A3=BC=EB=8D=98=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index 9783ed8..a3a34cf 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -34,7 +34,7 @@ export default class LottoController { const validator = createValidator(LottoValidation); const money = await this.view.inputMoney({ postProcessFn: (value) => Number(value), - validate: validator({ money }), + validate: (value) => validator({ money: value }), }); const quantity = LottoRule.exchange(money); @@ -48,11 +48,11 @@ export default class LottoController { const winLotto = await this.view.inputwinLotto({ postProcessFn: (value) => value.split(',').map((number) => Number(number)), - validate: validator({ common: winLotto }), + validate: (value) => validator({ common: value }), }); const bonusNumber = await this.view.inputBonusNumber({ postProcessFn: (value) => Number(value), - validate: validator({ number: bonusNumber }), + validate: (value) => validator({ number: value }), }); return new this.winLotto([...winLotto, bonusNumber]); @@ -62,7 +62,7 @@ export default class LottoController { const validator = createValidator(InputValidator); const restart = await this.view.inputRestart({ postProcessFn: (value) => value.trim(), - validate: validator({ restart }), + validate: (value) => validator({ restart: value }), }); return restart; From f84caac73dc8be3d418ea87fb00317f3f36a071a Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 15:46:05 +0900 Subject: [PATCH 53/73] =?UTF-8?q?fix:=20Input=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 재귀 호출 시 메서드 이름 정정 --- src/View/Input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Input.js b/src/View/Input.js index 2dc6020..532c0a6 100644 --- a/src/View/Input.js +++ b/src/View/Input.js @@ -29,7 +29,7 @@ export default class Input { } catch (error) { console.log(error); - return this.input(message, options); + return this.readInput(message, options); } } } From b44fadaf3e72fba2b992ff15e6faaf2993c55bdf Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:02:40 +0900 Subject: [PATCH 54/73] =?UTF-8?q?fix:=20InputValidator=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - hasOwnProperty 가 아닌 hasProperty 메서드를 사용해서 난 에러 - hasOwnProperty 대신 in 으로 프로퍼티 검사 --- src/validator/View/InputValidator.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/validator/View/InputValidator.js b/src/validator/View/InputValidator.js index 77d3408..f76a6af 100644 --- a/src/validator/View/InputValidator.js +++ b/src/validator/View/InputValidator.js @@ -7,22 +7,24 @@ const InputValidator = { }, options: { checkType: (value) => - typeof value === 'object' || 'options 는 개체 타입이어야 합니다.', + typeof value === 'object' || 'options 는 객체 타입이어야 합니다.', checkHasPostProcessFn: (value) => - value.hasProperty('postProcessFn') || + 'postProcessFn' in value || 'options 는 postProcessFn 프로퍼티를 가지고 있어야 합니다.', - checkHasValidation: (value) => - value.hasProperty('validation') || + checkHasValidate: (value) => + 'validate' in value || 'options 는 validation 프로퍼티를 가지고 있어야 합니다.', }, postProcessFn: { checkType: (value) => - (value !== undefined && typeof value !== 'function') || + value === undefined || + typeof value === 'function' || 'postProcessFn 는 함수여야 합니다.', }, validate: { checkType: (value) => - (value !== undefined && typeof value !== 'function') || + value === undefined || + typeof value === 'function' || 'validate 는 함수여야 합니다.', }, restart: { From d56821f4ccfffaf850f3d0e3271687159b6a8c5b Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:33:24 +0900 Subject: [PATCH 55/73] =?UTF-8?q?fix:=20generateRandomNumber=20=EB=8F=99?= =?UTF-8?q?=EC=9E=91=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 수ㅗ수점이 반환되는 문제 수정 --- src/utils/generateRandomNumber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/generateRandomNumber.js b/src/utils/generateRandomNumber.js index 9c646bb..622aae5 100644 --- a/src/utils/generateRandomNumber.js +++ b/src/utils/generateRandomNumber.js @@ -1,5 +1,5 @@ const generateRandomNumber = (min, max) => { - return Math.random() * (max - min) + min; + return Math.floor(Math.random() * (max - min) + min); }; export default generateRandomNumber; From f4f5efbc01f5b1940d67490408de448393432726 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:36:14 +0900 Subject: [PATCH 56/73] =?UTF-8?q?fix:=20lotto=20=EC=9D=B8=EC=8A=A4?= =?UTF-8?q?=ED=84=B4=EC=8A=A4=EA=B0=80=20=EC=83=9D=EC=84=B1=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8D=98=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index a3a34cf..6b36b9c 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -39,7 +39,7 @@ export default class LottoController { const quantity = LottoRule.exchange(money); return [...new Array(quantity)].map( - new this.lotto(LottoRule.generateLottoNumbers()), + () => new this.lotto(LottoRule.generateLottoNumbers()), ); } From b34869598b42651df2154107f10cd14e8b1df259 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:37:16 +0900 Subject: [PATCH 57/73] =?UTF-8?q?fix:=20Output=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/Output.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Output.js b/src/View/Output.js index 69b7365..7c79cfa 100644 --- a/src/View/Output.js +++ b/src/View/Output.js @@ -20,7 +20,7 @@ export default class Output { this.validator({ templateKey, templateVariables }); let templateString = this.#template[templateKey]; - Object.entires(templateVariables).forEach(([variable, value]) => { + Object.entries(templateVariables).forEach(([variable, value]) => { templateString = templateString.replaceAll(`%{${variable}}`, value); }); From 656ac447ecee16a5f46af148d08765b93c9b12dc Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:38:14 +0900 Subject: [PATCH 58/73] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EC=8B=9C=20=EB=8C=80=EA=B4=84=ED=98=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/View.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/View.js b/src/View/View.js index 23ee4e3..3f2e7c6 100644 --- a/src/View/View.js +++ b/src/View/View.js @@ -7,7 +7,7 @@ export default class View { this.output = new Output({ template: { printPurchaseQuantity: `%{quantity}개를 구매했습니다.`, - printLotto: `%{lotto}`, + printLotto: `[%{lotto}]`, printNumberOfWins: ` 당첨 통계\n ----------------------\n From 9bc8407decdd705e668c2326440a276bcc632544 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:38:28 +0900 Subject: [PATCH 59/73] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EA=B0=9C=EC=88=98=20=EC=BD=98=EC=86=94=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index 6b36b9c..374600e 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -13,6 +13,8 @@ export default class LottoController { async run() { while (true) { const lottos = await this.getLottos(); + + this.view.printPurchaseQuantity(lottos.length); this.view.printLottos(lottos.map((lotto) => lotto.get())); const winLotto = await this.getwinLotto(); From d62b255155b5539a257b38e42691f8196f74ac93 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:39:50 +0900 Subject: [PATCH 60/73] =?UTF-8?q?fix:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B0=9B=EC=95=84=EC=98=A4=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/View/View.js | 2 +- src/domain/LottoController.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/View/View.js b/src/View/View.js index 3f2e7c6..87351a8 100644 --- a/src/View/View.js +++ b/src/View/View.js @@ -26,7 +26,7 @@ export default class View { return this.input.readInput('> 구매 금액을 입력해주세요. : ', options); } - async inputWinningLotto(options) { + async inputWinLotto(options) { return this.input.readInput('> 당첨 번호를 입력해주세요. : ', options); } diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index 374600e..f7dfda4 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -47,7 +47,7 @@ export default class LottoController { async getwinLotto() { const validator = createValidator(LottoValidation); - const winLotto = await this.view.inputwinLotto({ + const winLotto = await this.view.inputWinLotto({ postProcessFn: (value) => value.split(',').map((number) => Number(number)), validate: (value) => validator({ common: value }), From 925ae3e40812ae860044ef51cd913f12b7a0e722 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:41:23 +0900 Subject: [PATCH 61/73] =?UTF-8?q?fix:=20LottoController=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index f7dfda4..c72e34a 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -19,9 +19,9 @@ export default class LottoController { const winLotto = await this.getwinLotto(); const { prize, purchases, details, prizes } = - winLotto.getWinninResult(lottos); + winLotto.getWinningResult(lottos); - this.view.printwinsResult({ ...details, prizes }); + this.view.printwinningResult({ ...details, prizes }); this.view.printRevenue(prize / purchases); const restart = await this.restart(); From 72b901c9a7bfea8dc9bc294f10c0d6c88e872cdc Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:45:29 +0900 Subject: [PATCH 62/73] =?UTF-8?q?fix:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EC=99=80=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EC=97=90=20=EB=8C=80=ED=95=B4=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=82=AC=EB=A5=BC=20=EC=A0=9C=EB=8C=80?= =?UTF-8?q?=EB=A1=9C=20=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index c72e34a..b316a01 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -50,11 +50,12 @@ export default class LottoController { const winLotto = await this.view.inputWinLotto({ postProcessFn: (value) => value.split(',').map((number) => Number(number)), - validate: (value) => validator({ common: value }), + validate: (value) => validator({ common: value, defaultLotto: value }), }); const bonusNumber = await this.view.inputBonusNumber({ postProcessFn: (value) => Number(value), - validate: (value) => validator({ number: value }), + validate: (value) => + validator({ number: value, common: [...winLotto, value] }), }); return new this.winLotto([...winLotto, bonusNumber]); From c8368c32a0be3215c9e87e95d2e3f812ab13f987 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:46:41 +0900 Subject: [PATCH 63/73] =?UTF-8?q?fix:=20WinLotto=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 객체를 순회하지 못했던 문제 해결 --- src/domain/WinLotto.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index 57d5b08..dccfc42 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -26,7 +26,7 @@ export default class WinLotto extends Lotto { const bonusCorrect = this.isBonusCorrect(lotto); const accordCount = this.accord(lotto) - bonusCorrect ? 1 : 0; - for (const rank of LottoRule.winningInfo) { + for (const rank in LottoRule.winningInfo) { if (accordCount === LottoRule.winningInfo[rank].accord) { if (LottoRule.winningInfo[rank].checkBonus && bonusCorrect) { return rank; From 1b83b71ae86c8f41593d38ae85666691da4a2c79 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 16:50:45 +0900 Subject: [PATCH 64/73] =?UTF-8?q?feat:=20LottoRule=20=EC=9D=98=20=EC=9A=B0?= =?UTF-8?q?=EC=8A=B9=20=EC=A0=95=EB=B3=B4=EC=97=90=20none=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=8D=BC=ED=8B=B0=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoRule.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/domain/LottoRule.js b/src/domain/LottoRule.js index 066d53b..decc486 100644 --- a/src/domain/LottoRule.js +++ b/src/domain/LottoRule.js @@ -33,6 +33,11 @@ const LottoRule = { checkBonus: false, accord: 3, }, + none: { + prize: 0, + checkBonus: false, + accord: null, + }, }, exchange: (money) => { return Math.floor(money / LottoRule.lottoPrice); From e3c43be73e33d6f28add44036f0c54c07a2fc86a Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:13:24 +0900 Subject: [PATCH 65/73] =?UTF-8?q?fix:=20LottoController=20=EC=98=A4?= =?UTF-8?q?=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/LottoController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index b316a01..7ab184f 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -21,7 +21,7 @@ export default class LottoController { const { prize, purchases, details, prizes } = winLotto.getWinningResult(lottos); - this.view.printwinningResult({ ...details, prizes }); + this.view.printWinningResult({ ...details, prizes }); this.view.printRevenue(prize / purchases); const restart = await this.restart(); From c4947be715d339f2b01957558e05c046a4677864 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:14:07 +0900 Subject: [PATCH 66/73] =?UTF-8?q?fix:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - accord 메서드가 제대로 동작하지 않는 문제 - 배열의 길이가 더 큰 값을 집합으로 만들어 비교하도록 함 --- src/domain/Lotto.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/domain/Lotto.js b/src/domain/Lotto.js index 0217e1a..dec009d 100644 --- a/src/domain/Lotto.js +++ b/src/domain/Lotto.js @@ -31,16 +31,13 @@ export default class Lotto { } accord(...compareLotto) { - const normalizedCompareLotto = Lotto.normalize(...compareLotto); + compareLotto = Lotto.normalize(...compareLotto); const set = new Set( - this.lotto.length > normalizedCompareLotto.length - ? this.lotto - : normalizedCompareLotto, + this.lotto.length > compareLotto.length ? this.lotto : compareLotto, ); + const base = + this.lotto.length > compareLotto.length ? compareLotto : this.lotto; - return normalizedCompareLotto.reduce( - (prev, curr) => (set.has(curr) ? prev + 1 : prev), - 0, - ); + return base.reduce((prev, curr) => (set.has(curr) ? prev + 1 : prev), 0); } } From f1d6bf4ad47875e6c51c5b308bc934bb4122888c Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:14:34 +0900 Subject: [PATCH 67/73] =?UTF-8?q?refactoring:=20View=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 당첨 결과를 나타낼 수 있는 메서드 이름으로 수정 --- src/View/View.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/View/View.js b/src/View/View.js index 87351a8..f1213f3 100644 --- a/src/View/View.js +++ b/src/View/View.js @@ -8,7 +8,7 @@ export default class View { template: { printPurchaseQuantity: `%{quantity}개를 구매했습니다.`, printLotto: `[%{lotto}]`, - printNumberOfWins: ` + printWinningResult: ` 당첨 통계\n ----------------------\n 3개 일치 (%{fifthMoney}원) - %{fifth}개 @@ -52,8 +52,8 @@ export default class View { Output.lineBreak(); } - printNumberOfWins(lottoResult) { - Output.print(this.output.format('printNumberOfWins', lottoResult)); + printWinningResult(lottoResult) { + Output.print(this.output.format('printWinningResult', lottoResult)); } printRevenue(revenue) { From ad492b752c36a10a33ae37738035eb185ea42d73 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:15:38 +0900 Subject: [PATCH 68/73] =?UTF-8?q?fix:=20WinLotto=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - getRank 에서 bonusCorrect 의 연산 범위를 제대로 지정해주지 않은 문제 수정 - 일치하는 번호 개수와 보너스 번호 개수에 따라 랭크가 제대로 매겨지지 않는 문제 수정 --- src/domain/WinLotto.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index dccfc42..6c9e8d9 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -24,14 +24,16 @@ export default class WinLotto extends Lotto { getRank(lotto) { const bonusCorrect = this.isBonusCorrect(lotto); - const accordCount = this.accord(lotto) - bonusCorrect ? 1 : 0; + const accordCount = this.accord(lotto) - (bonusCorrect ? 1 : 0); for (const rank in LottoRule.winningInfo) { if (accordCount === LottoRule.winningInfo[rank].accord) { + if (LottoRule.winningInfo[rank].checkBonus === false) { + return rank; + } if (LottoRule.winningInfo[rank].checkBonus && bonusCorrect) { return rank; } - return rank; } } From 70a7edca6c4e14ffb8565a23dff0e07685fa9404 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:36:50 +0900 Subject: [PATCH 69/73] =?UTF-8?q?fix:=20LottoController=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 잘못된 메서드 이름으로 호출하던 문제 수정 --- src/domain/LottoController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index 7ab184f..4cfdbc4 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -24,7 +24,7 @@ export default class LottoController { this.view.printWinningResult({ ...details, prizes }); this.view.printRevenue(prize / purchases); - const restart = await this.restart(); + const restart = await this.getRestart(); if (restart === 'n' || restart === 'N') { break; From a5f8aa17b96ac50e652aea9630a2b21f58514148 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:37:03 +0900 Subject: [PATCH 70/73] =?UTF-8?q?feat:=20winLotto=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/WinLotto.test.js | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/__tests__/WinLotto.test.js b/src/__tests__/WinLotto.test.js index 4522219..00b4832 100644 --- a/src/__tests__/WinLotto.test.js +++ b/src/__tests__/WinLotto.test.js @@ -1,5 +1,6 @@ import { describe, test, expect } from 'vitest'; import WinLotto from '../domain/WinLotto'; +import LottoRule from '../domain/LottoRule'; describe('WinLotto 클래스에 대한 단위 테스트', () => { const correctLotto = [1, 2, 3, 4, 5, 6, 7]; @@ -74,6 +75,55 @@ describe('WinLotto 클래스에 대한 단위 테스트', () => { }).toThrowError('로또번호의 각 번호는 1~45 사이여야 합니다.'); }, ); + + test('isBonusCorrect 메서드는 보너스 번호가 로또 번호 안에 포함되면 true 를 반환한다.', () => { + const winLotto = makeWinLottoMocking(correctLotto); + + expect(winLotto.isBonusCorrect([1, 2, 3, 4, 5, 7])).toBeTruthy(); + }); + + test.each([ + { lotto: [1, 2, 3, 4, 5, 6], result: 'first' }, + { lotto: [1, 2, 3, 4, 5, 7], result: 'second' }, + { lotto: [1, 2, 3, 4, 5, 8], result: 'third' }, + { lotto: [1, 2, 3, 4, 8, 9], result: 'fourth' }, + { lotto: [1, 2, 3, 8, 9, 10], result: 'fifth' }, + ])( + 'getRank 는 lotto($lotto)가 winLotto와 일치하는 개수에 따라 rank($result)를 반환한다.', + ({ lotto, result }) => { + const winLotto = makeWinLottoMocking(correctLotto); + + expect(winLotto.getRank(lotto)).toBe(result); + }, + ); + + test('getWinningResult 메서드는 lottos 배열을 받아 당첨 결과를 반환한다.', () => { + const winningResult = { + prize: 5000, + purchases: 1000, + details: { + first: 0, + second: 0, + third: 0, + fourth: 0, + fifth: 1, + none: 0, + }, + prizes: { + firstMoney: LottoRule.winningInfo.first.prize, + secondMoney: LottoRule.winningInfo.second.prize, + thirdMoney: LottoRule.winningInfo.third.prize, + fourthMoney: LottoRule.winningInfo.fourth.prize, + fifthMoney: LottoRule.winningInfo.fifth.prize, + noneMoney: LottoRule.winningInfo.none.prize, + }, + }; + const winningLotto = makeWinLottoMocking(correctLotto); + + expect(winningLotto.getWinningResult([[1, 2, 3, 8, 9, 10]])).toStrictEqual( + winningResult, + ); + }); }); function makeWinLottoMocking(...lotto) { From c9c33cd4905f3f6473669af55fe1cd441a35d5de Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:37:34 +0900 Subject: [PATCH 71/73] =?UTF-8?q?feat:=20getWinningResult=20=EA=B0=80=20?= =?UTF-8?q?=EC=97=AC=EB=9F=AC=20=ED=98=95=ED=83=9C=EC=9D=98=20lottos=20?= =?UTF-8?q?=EB=A5=BC=20=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/WinLotto.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index 6c9e8d9..9f694a2 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -47,13 +47,16 @@ export default class WinLotto extends Lotto { details: {}, prizes: {}, }; + lottos = lottos.map((lotto) => + Array.isArray(lotto) ? lotto : lotto.get(), + ); Object.entries(LottoRule.winningInfo).forEach(([rank, rankInfo]) => { winningResult.details[rank] = 0; winningResult.prizes[rank + 'Money'] = rankInfo.prize; }); lottos.forEach((lotto) => { - const rank = this.getRank(lotto.get()); + const rank = this.getRank(lotto); winningResult.details[rank] += 1; winningResult.prize += LottoRule.winningInfo[rank].prize; From d85cb811b9b59ad44f58ddd14ef2beeb1c5ff2a2 Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:47:54 +0900 Subject: [PATCH 72/73] =?UTF-8?q?feat:=20=EC=BD=A4=EB=A7=88=EB=A1=9C=20?= =?UTF-8?q?=EC=88=AB=EC=9E=90=20=EA=B5=AC=EB=B6=84=ED=95=B4=EC=84=9C=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/WinLotto.test.js | 13 ++++++------- src/domain/WinLotto.js | 3 ++- src/utils/formatCurrency.js | 11 +++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 src/utils/formatCurrency.js diff --git a/src/__tests__/WinLotto.test.js b/src/__tests__/WinLotto.test.js index 00b4832..b8bbc41 100644 --- a/src/__tests__/WinLotto.test.js +++ b/src/__tests__/WinLotto.test.js @@ -1,6 +1,5 @@ import { describe, test, expect } from 'vitest'; import WinLotto from '../domain/WinLotto'; -import LottoRule from '../domain/LottoRule'; describe('WinLotto 클래스에 대한 단위 테스트', () => { const correctLotto = [1, 2, 3, 4, 5, 6, 7]; @@ -110,12 +109,12 @@ describe('WinLotto 클래스에 대한 단위 테스트', () => { none: 0, }, prizes: { - firstMoney: LottoRule.winningInfo.first.prize, - secondMoney: LottoRule.winningInfo.second.prize, - thirdMoney: LottoRule.winningInfo.third.prize, - fourthMoney: LottoRule.winningInfo.fourth.prize, - fifthMoney: LottoRule.winningInfo.fifth.prize, - noneMoney: LottoRule.winningInfo.none.prize, + firstMoney: '2,000,000,000', + secondMoney: '30,000,000', + thirdMoney: '1,500,000', + fourthMoney: '50,000', + fifthMoney: '5,000', + noneMoney: '0', }, }; const winningLotto = makeWinLottoMocking(correctLotto); diff --git a/src/domain/WinLotto.js b/src/domain/WinLotto.js index 9f694a2..cbeb013 100644 --- a/src/domain/WinLotto.js +++ b/src/domain/WinLotto.js @@ -2,6 +2,7 @@ import Lotto from './Lotto.js'; import LottoValidator from '../validator/domain/LottoValidator.js'; import createValidator from '../utils/createValidator.js'; import LottoRule from './LottoRule.js'; +import formatCurrency from '../utils/formatCurrency.js'; export default class WinLotto extends Lotto { constructor(...lotto) { @@ -53,7 +54,7 @@ export default class WinLotto extends Lotto { Object.entries(LottoRule.winningInfo).forEach(([rank, rankInfo]) => { winningResult.details[rank] = 0; - winningResult.prizes[rank + 'Money'] = rankInfo.prize; + winningResult.prizes[rank + 'Money'] = formatCurrency(rankInfo.prize); }); lottos.forEach((lotto) => { const rank = this.getRank(lotto); diff --git a/src/utils/formatCurrency.js b/src/utils/formatCurrency.js new file mode 100644 index 0000000..64a5c36 --- /dev/null +++ b/src/utils/formatCurrency.js @@ -0,0 +1,11 @@ +const formatCurrency = (amount, currency = 'ko-KR') => { + const formatter = new Intl.NumberFormat(currency, { + style: 'decimal', + minimumFractionDigits: 0, + maximumFractionDigits: 0, + }); + + return formatter.format(amount); +}; + +export default formatCurrency; From b16ed8e4afe9fc3fdf32543a8ea873fdefcdf78a Mon Sep 17 00:00:00 2001 From: Suyeon Date: Mon, 15 Jul 2024 17:48:23 +0900 Subject: [PATCH 73/73] =?UTF-8?q?fix:=20prizes=20=EA=B0=80=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EC=B6=9C=EB=A0=A5=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EB=AA=BB=ED=95=98=EB=8D=98=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 얕은 복사를 하지 않고 프로퍼티를 추가하던 문제 수정 --- src/domain/LottoController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/LottoController.js b/src/domain/LottoController.js index 4cfdbc4..5c8116c 100644 --- a/src/domain/LottoController.js +++ b/src/domain/LottoController.js @@ -21,7 +21,7 @@ export default class LottoController { const { prize, purchases, details, prizes } = winLotto.getWinningResult(lottos); - this.view.printWinningResult({ ...details, prizes }); + this.view.printWinningResult({ ...details, ...prizes }); this.view.printRevenue(prize / purchases); const restart = await this.getRestart();