Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
ef743b3
chore: 스크립트 설정 및 리드미 수정
seeyoujeong Jul 2, 2024
9f95561
feat: 폴더구조 설정
seeyoujeong Jul 2, 2024
de30d4e
test: 불필요한 테스트 삭제 및 tdd 방식으로 테스트 작성
seeyoujeong Jul 2, 2024
d579f9b
test: 로또 구입 관련 테스트 추가 및 Lotto 클래스에 구입 관련 로직 구현
seeyoujeong Jul 3, 2024
e855bbf
refactor: 테스트 파일에서 구현한 Lotto 클래스 분리
seeyoujeong Jul 3, 2024
e3e8ecc
feat: 이전 코드 삭제 후 Lotto 클래스 새로 구현
seeyoujeong Jul 3, 2024
f33d640
test: Lotto 클래스 테스트 코드 수정
seeyoujeong Jul 3, 2024
aced74a
refactor: isDuplicated 함수 추가 및 적용
seeyoujeong Jul 3, 2024
5a7c226
feat: 로또 번호 유효성 검사 추가
seeyoujeong Jul 3, 2024
56d244f
test: 로또 번호 유효성 검사 테스트 추가
seeyoujeong Jul 3, 2024
4afa7f0
feat: 로또 번호 유효성 검사 추가
seeyoujeong Jul 3, 2024
fd17d31
test: 로또 번호 유효성 검사 테스트 추가
seeyoujeong Jul 3, 2024
86dd7f4
feat: LottoMachine 클래스 추가
seeyoujeong Jul 3, 2024
e776555
test: LottoMachine 클래스 관련 테스트 추가
seeyoujeong Jul 3, 2024
cda3a77
refactor: getRandomNumber 함수 추가 및 적용
seeyoujeong Jul 4, 2024
6f8ddc9
refactor: 로또 관련 숫자 상수화
seeyoujeong Jul 4, 2024
eca3349
refactor: 불변성 유지를 위해 deepCopy 함수 추가 및 적용
seeyoujeong Jul 4, 2024
5f550f1
test: LottoMachine 클래스 수정사항 반영
seeyoujeong Jul 4, 2024
10e8c4d
refactor: 보너스 번호 유효성 검사에 사용할 로직 분리
seeyoujeong Jul 4, 2024
40f1f10
feat: WinningLotto 클래스 추가
seeyoujeong Jul 4, 2024
ce82980
test: WinningLotto 클래스 테스트 추가
seeyoujeong Jul 4, 2024
c4d6d2b
refactor: 상수값을 Lotto 클래스로 이동하고 적용
seeyoujeong Jul 4, 2024
eb7368d
refactor: lottos배열의 원소를 Lotto 인스턴스값으로 수정
seeyoujeong Jul 4, 2024
bc07e24
fix: WinningLotto 클래스 export 추가
seeyoujeong Jul 4, 2024
82d0a01
feat: LottoCalculator 클래스 추가
seeyoujeong Jul 4, 2024
a85d026
test: LottoCalculator 클래스 테스트 추가
seeyoujeong Jul 4, 2024
d66eca8
feat: 금액 관련 프로퍼티 및 매개변수 추가
seeyoujeong Jul 5, 2024
d4e99f2
test: 금액 관련 부분 및 중복 코드 수정
seeyoujeong Jul 5, 2024
89b8eaf
feat: 수익률 로직 추가
seeyoujeong Jul 5, 2024
e9f317e
test: 수익률 관련 테스트 추가
seeyoujeong Jul 5, 2024
fbf2d4f
refactor: 순수 함수로 수정
seeyoujeong Jul 5, 2024
a9471c4
feat: readLineAsynce 함수 추가
seeyoujeong Jul 5, 2024
7ebaa96
feat: InputManager 클래스 추가
seeyoujeong Jul 5, 2024
56a4598
feat: OutputManager 클래스 추가
seeyoujeong Jul 5, 2024
c41a1fc
fix: 정수인지 검사하는 유효성 검사로 수정
seeyoujeong Jul 5, 2024
4f78672
feat: 구입 금액 입력 구현
seeyoujeong Jul 5, 2024
df5b826
feat: 당첨 번호, 보너스 번호 입력 및 당첨 통계 출력 구현
seeyoujeong Jul 5, 2024
a5c07c1
refactor: main 정리
seeyoujeong Jul 6, 2024
0bc5f15
refactor: #count 프로퍼티 삭제
seeyoujeong Jul 6, 2024
3ccfbbc
refactor: 정수 검사 조건 수정
seeyoujeong Jul 6, 2024
88004ac
feat: 유효성 감사 유틸 추가
seeyoujeong Jul 7, 2024
502416e
refactor: 유효성 검사 유틸을 활용해 수정
seeyoujeong Jul 7, 2024
783e136
feat: 입출력 매니저에 유효성 검사 추가
seeyoujeong Jul 7, 2024
2ec79a3
refactor: 화살표 함수로 수정
seeyoujeong Jul 7, 2024
b7c3d93
refactor: 불필요한 파일 삭제
seeyoujeong Jul 7, 2024
0e4cade
feat: #createLotto에서 로또 번호 정렬되게 수정
seeyoujeong Jul 7, 2024
48d0c42
refactor: domain 폴더명을 model로 수정
seeyoujeong Jul 7, 2024
4bd886c
fix: 누락된 정수 유효성 검사 추가 및 createWithBonusNumberLater 메서드 추가
seeyoujeong Jul 7, 2024
9b86217
test: 정수 유효성 검사 테스트 추가
seeyoujeong Jul 7, 2024
b0a1390
feat: 보너스 번호를 나중에 받을 수 있게 수정
seeyoujeong Jul 7, 2024
e4e4f4f
feat: 컨트롤러 레이어 추가
seeyoujeong Jul 7, 2024
ee9f635
feat: 뷰 레이어 추가
seeyoujeong Jul 7, 2024
43c8791
feat: MVC 패턴으로 구현
seeyoujeong Jul 7, 2024
ddaf645
fix: 동일한 변수명이 있어서 attachBonusNumber로 수정
seeyoujeong Jul 7, 2024
2b4897a
fix: ci 테스트 실패 오류 해결
seeyoujeong Jul 7, 2024
046974b
feat: LottoNumber 클래스 추가
seeyoujeong Jul 13, 2024
49641e8
test: LottoNumber 클래스 테스트 추가
seeyoujeong Jul 13, 2024
af050c1
refactor: LottoNumber 클래스 적용
seeyoujeong Jul 13, 2024
85b4a72
test: 불필요한 테스트 삭제
seeyoujeong Jul 13, 2024
6e5ac02
feat: retryOnFailureAsync 함수 추가
seeyoujeong Jul 13, 2024
bc8c1a7
refactor: 입력에서 예외처리 분리
seeyoujeong Jul 13, 2024
60d2154
refactor: 로또에 관한 정보 수정 및 내부 로직 수정
seeyoujeong Jul 14, 2024
6dcaa4f
refactor: constants 폴더 생성하고 로또 순위 정보 이동
seeyoujeong Jul 14, 2024
26037c2
feat: formatKoreanCurrency 함수 추가
seeyoujeong Jul 14, 2024
8fb164f
refactor: 로또 순위 정보를 바탕으로 결과를 보여주게 수정
seeyoujeong Jul 14, 2024
0fd967b
refactor: 가격 관련 부분 수정
seeyoujeong Jul 14, 2024
f787d18
test: 상금 테스트 오류 수정
seeyoujeong Jul 14, 2024
92a4f4f
refactor: 당첨 번호 입력에 대한 예외처리 로직 수정
seeyoujeong Jul 15, 2024
58fd431
feat: 배열관련 유틸 함수 추가
seeyoujeong Jul 15, 2024
074b130
refactor: 로또 번호 생성하는 로직 수정
seeyoujeong Jul 15, 2024
d5721d7
refactor: 로또 관련 상수 분리
seeyoujeong Jul 15, 2024
258249e
refactor: 불필요한 파일 삭제
seeyoujeong Jul 15, 2024
f3c451b
refactor: LottoCalculator 클래스 분리하고 적용
seeyoujeong Jul 15, 2024
b41cc97
test: LottoCalculator 클래스 삭제하고 LottoMatcher, LottoResult 클래스 테스트 추가
seeyoujeong Jul 15, 2024
15933cb
fix: 잘못된 import 수정
seeyoujeong Jul 15, 2024
daf3e24
refactor: 클래스명 수정
seeyoujeong Jul 15, 2024
bbf6649
feat: 재시작 기능 추가
seeyoujeong Jul 15, 2024
59db060
style: 코드 배치 수정
seeyoujeong Jul 15, 2024
ff3fb40
feat: 에러 메세지 관련 상수 추가
seeyoujeong Jul 15, 2024
42f46b7
refactor: 파일명 수정
seeyoujeong Jul 15, 2024
7006658
feat: 에러 메세지 관련 유틸 추가
seeyoujeong Jul 15, 2024
e0cd64f
feat: 에러 메세지 관련 출력 함수 추가
seeyoujeong Jul 15, 2024
de23f68
refactor: 에러 메세지 수정
seeyoujeong Jul 15, 2024
4477059
test: 에러 메시지 수정으로 인한 테스트 수정
seeyoujeong Jul 15, 2024
d38145f
refactor: 에러 메세지 관련 코드 수정
seeyoujeong Jul 15, 2024
1956965
feat: 수익률이 정수인지 아닌지에 따른 반환값 수정
seeyoujeong Jul 15, 2024
19ab847
feat: 다시 시작 취소할때 아무키 입력으로 수정
seeyoujeong Jul 15, 2024
b3646fd
Merge pull request #1 from seeyoujeong/step2
seeyoujeong Jul 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 자동차 경주 미션
# 로또 미션

## 참고링크 및 저장소

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"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",
"test": "vitest"
"test": "vitest run",
"test:watch": "vitest"
},
"keywords": [],
"author": "",
Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/Lotto.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, test, expect } from "vitest";
import { Lotto } from "../model/index.js";

describe("Lotto 클래스 테스트.", () => {
test.each([
{ value: 1 },
{ value: "1" },
{ value: true },
{ value: null },
{ value: undefined },
{ value: {} },
])(
"로또 번호로 적합하지 않은 값($value)을 받으면 오류가 발생한다.",
({ value }) => {
expect(() => new Lotto(value)).toThrowError(
"[ERR_002] Lotto 클래스의 생성자 인수는 배열이어야 합니다."
);
}
);

test("로또 번호가 6개 초과이면 오류가 발생한다.", () => {
expect(() => new Lotto([1, 2, 3, 4, 5, 6, 7])).toThrowError(
"[ERR_002] Lotto 클래스의 생성자 인수의 길이는 6이어야 합니다."
);
});

test("로또 번호가 6개 미만이면 오류가 발생한다.", () => {
expect(() => new Lotto([1, 2, 3, 4, 5])).toThrowError(
"[ERR_002] Lotto 클래스의 생성자 인수의 길이는 6이어야 합니다."
);
});

test("로또 번호를 가져옵니다.", () => {
const lotto = new Lotto([1, 2, 3, 4, 5, 6]);

expect(lotto.numbers).toEqual([1, 2, 3, 4, 5, 6]);
});
});
38 changes: 38 additions & 0 deletions src/__tests__/LottoMachine.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, test, expect } from "vitest";
import { LottoMachine } from "../model/index.js";

describe("LottoMachine 클래스 테스트", () => {
test("로또를 구입할 때 정수가 아닌 값을 받으면 오류가 발생한다.", () => {
expect(() => new LottoMachine("1")).toThrowError(
"[ERR_004] LottoMachine 클래스의 생성자 인수는 정수여야 합니다."
);
});

test("로또를 구입할 때 1000원미만의 값을 받으면 오류가 발생한다.", () => {
expect(() => new LottoMachine(999)).toThrowError(
"[ERR_004] LottoMachine 클래스의 생성자 인수는 1000이상이어야 합니다."
);
});

test.each([
{ price: 1001, count: 1 },
{ price: 2500, count: 2 },
{ price: 3999, count: 3 },
{ price: 10999, count: 10 },
])(
"로또를 $price원만큼 구매하면 $count장을 발행한다.",
({ price, count }) => {
const lottoMachine = new LottoMachine(price);

expect(lottoMachine.count).toBe(count);
}
);

test("무작위 번호 6개가 적힌 로또를 받는다.", () => {
const lottoMachine = new LottoMachine(1000);

const lotto = lottoMachine.lottos[0];

expect(lotto.numbers).toHaveLength(6);
});
});
85 changes: 85 additions & 0 deletions src/__tests__/LottoMatcher.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { describe, expect, test, vi } from "vitest";
import {
LottoMachine,
WinningLotto,
LottoMatcher,
Lotto,
} from "../model/index.js";
import { LOTTO } from "../constants/index.js";

describe("LottoMatcher 클래스 테스트", () => {
test("1등부터 5등까지 당첨된 수를 가져온다.", () => {
const { lottos } = new LottoMachine(6000);
const winningLotto = new WinningLotto([1, 2, 3, 4, 5, 6], 7);

const { winningCounts } = new LottoMatcher(lottos, winningLotto);

expect(winningCounts).toHaveProperty("1");
expect(winningCounts).toHaveProperty("2");
expect(winningCounts).toHaveProperty("3");
expect(winningCounts).toHaveProperty("4");
expect(winningCounts).toHaveProperty("5");

expect(typeof winningCounts[1]).toBe("number");
expect(typeof winningCounts[2]).toBe("number");
expect(typeof winningCounts[3]).toBe("number");
expect(typeof winningCounts[4]).toBe("number");
expect(typeof winningCounts[5]).toBe("number");
});

test("로또 번호 중에 1등 당첨이 하나있다.", () => {
const { lottos } = createLottoMachineMock([[1, 2, 3, 4, 5, 6]]);
const winningLotto = new WinningLotto([1, 2, 3, 4, 5, 6], 7);

const { winningCounts } = new LottoMatcher(lottos, winningLotto);

expect(winningCounts).toHaveProperty("1", 1);
});

test("로또 번호 중에 2등 당첨이 하나있다.", () => {
const { lottos } = createLottoMachineMock([[1, 2, 3, 4, 5, 7]]);
const winningLotto = new WinningLotto([1, 2, 3, 4, 5, 6], 7);

const { winningCounts } = new LottoMatcher(lottos, winningLotto);

expect(winningCounts).toHaveProperty("2", 1);
});

test("로또 번호 중에 3등 당첨이 하나있다.", () => {
const { lottos } = createLottoMachineMock([[1, 2, 3, 4, 5, 8]]);
const winningLotto = new WinningLotto([1, 2, 3, 4, 5, 6], 7);

const { winningCounts } = new LottoMatcher(lottos, winningLotto);

expect(winningCounts).toHaveProperty("3", 1);
});

test("로또 번호 중에 4등 당첨이 하나있다.", () => {
const { lottos } = createLottoMachineMock([[1, 2, 3, 4, 8, 9]]);
const winningLotto = new WinningLotto([1, 2, 3, 4, 5, 6], 7);

const { winningCounts } = new LottoMatcher(lottos, winningLotto);

expect(winningCounts).toHaveProperty("4", 1);
});

test("로또 번호 중에 5등 당첨이 하나있다.", () => {
const { lottos } = createLottoMachineMock([[1, 2, 3, 8, 9, 10]]);
const winningLotto = new WinningLotto([1, 2, 3, 4, 5, 6], 7);

const { winningCounts } = new LottoMatcher(lottos, winningLotto);

expect(winningCounts).toHaveProperty("5", 1);
});
});

function createLottoMachineMock(numbersArray) {
const lottos = numbersArray.map((numbers) => new Lotto(numbers));
const lottoMachineMock = vi.fn();
lottoMachineMock.mockReturnValueOnce({
price: lottos.length * LOTTO.PRICE,
lottos,
});

return lottoMachineMock();
}
41 changes: 41 additions & 0 deletions src/__tests__/LottoNumber.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, test } from "vitest";
import { LottoNumber } from "../model/index.js";

describe("LottoNumber 클래스 테스트", () => {
test.each([
{ value: "a" },
{ value: true },
{ value: false },
{ value: undefined },
{ value: null },
{ value: [] },
{ value: {} },
])(
"로또 번호로 적합하지 않은 값($value)을 할당하면 오류가 발생한다.",
({ value }) => {
expect(() => new LottoNumber(value)).toThrowError(
"[ERR_001] LottoNumber 클래스의 생성자 인수는 정수여야 합니다."
);
}
);

test("로또 번호가 1보다 작으면 오류가 발생한다.", () => {
expect(() => new LottoNumber(0)).toThrowError(
"[ERR_001] LottoNumber 클래스의 생성자 인수는 1이상이어야 합니다."
);
});

test("로또 번호가 45보다 크면 오류가 발생한다.", () => {
expect(() => new LottoNumber(46)).toThrowError(
"[ERR_001] LottoNumber 클래스의 생성자 인수는 45이하여야 합니다."
);
});

test("로또 번호를 정한다.", () => {
const number = 1;

const lottoNumber = new LottoNumber(number);

expect(lottoNumber.value).toBe(1);
});
});
19 changes: 19 additions & 0 deletions src/__tests__/LottoReturnCalculator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, test } from "vitest";
import { LottoReturnCalculator } from "../model/index.js";

describe("LottoReturnCalculator 클래스 테스트", () => {
test("수익률을 가져온다.", () => {
const winningCounts = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 1,
};
const price = 2000;

const { rateOfReturn } = new LottoReturnCalculator(winningCounts, price);

expect(rateOfReturn).toBe(250);
});
});
22 changes: 22 additions & 0 deletions src/__tests__/WinningLotto.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, test } from "vitest";
import { WinningLotto } from "../model/index.js";

describe("WinningLotto 클래스 테스트", () => {
test("당첨 번호 중에 보너스 번호와 중복되는 번호가 있으면 오류가 발생한다.", () => {
const lottoNumbers = [1, 2, 3, 4, 5, 6];
const bonusNumber = 6;

expect(() => new WinningLotto(lottoNumbers, bonusNumber)).toThrowError(
"[ERR_003] WinningLotto 클래스의 생성자 인수인 winningNumbers 중에 bonusNumber와 중복됩니다."
);
});

test("보너스 번호를 가져온다.", () => {
const lottoNumbers = [1, 2, 3, 4, 5, 6];
const bonusNumber = 45;

const winningLotto = new WinningLotto(lottoNumbers, bonusNumber);

expect(winningLotto.bonusNumber).toBe(45);
});
});
11 changes: 0 additions & 11 deletions src/__tests__/sum.test.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/constants/errorMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const USER_FRIENDLY_ERROR_MESSAGES = {
ERR_001:
"입력하신 값은 로또 번호로 사용할 수 없습니다. 1부터 45 사이의 숫자를 입력해 주세요.",
ERR_002: "로또 번호는 중복 없이 6개의 서로 다른 숫자를 입력해 주세요.",
ERR_003:
"보너스 번호가 당첨 번호와 중복되었습니다. 당첨 번호 6개와 중복되지 않는 보너스 번호 1개를 포함하여 총 7개의 번호를 다시 입력해 주세요.",
ERR_004: "로또 구매 금액은 1,000원 단위로 입력해 주세요.",
};
2 changes: 2 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./lotto.js";
export * from "./errorMessage.js";
34 changes: 34 additions & 0 deletions src/constants/lotto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const LOTTO = {
NUMBERS_SIZE: 6,
MIN_NUMBER: 1,
MAX_NUMBER: 45,
PRICE: 1000,
RANKING_INFO: [
{
ranking: 1,
matchingCount: 6,
prizeMoney: 2_000_000_000,
},
{
ranking: 2,
matchingCount: 5,
isBonusMatch: true,
prizeMoney: 30_000_000,
},
{
ranking: 3,
matchingCount: 5,
prizeMoney: 1_500_000,
},
{
ranking: 4,
matchingCount: 4,
prizeMoney: 50_000,
},
{
ranking: 5,
matchingCount: 3,
prizeMoney: 5_000,
},
],
};
14 changes: 14 additions & 0 deletions src/controller/calculateWinningResults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LOTTO } from "../constants/index.js";
import { LottoMatcher, LottoReturnCalculator } from "../model/index.js";

const calculateWinningResults = ({ lottos, winningLotto }) => {
const { winningCounts } = new LottoMatcher(lottos, winningLotto);

const price = lottos.length * LOTTO.PRICE;

const { rateOfReturn } = new LottoReturnCalculator(winningCounts, price);

return { winningCounts, rateOfReturn };
};

export default calculateWinningResults;
Loading