Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
43db77e
docs:기능 목록 README.md 추가
pigpgw Feb 4, 2024
a84c3de
chore: eslintrc(airbnb), prettier 설치
pigpgw Feb 4, 2024
24fe8bb
feat: make lotto fnc in LottoTicketGenerator
pigpgw Feb 4, 2024
4140f31
delete: DonhangLottery.js
pigpgw Feb 4, 2024
81364db
test:add generate lotto number test code
pigpgw Feb 4, 2024
154463a
feat: LottoPlayer class iwth seed and buyLottoList method
pigpgw Feb 4, 2024
b69bdae
chore: Update file extensions in module imports
pigpgw Feb 4, 2024
1db1996
feat: add sort fnc in makeLotto fnc
pigpgw Feb 4, 2024
08cbe5f
feat:add checkLotto fnc in LottoMachine.js
pigpgw Feb 4, 2024
de4a9c5
fix:LottoPlayer constructor
pigpgw Feb 4, 2024
cb3ca76
docs: UPDATE README.md
pigpgw Feb 4, 2024
5ef9299
style: sort code format
pigpgw Feb 4, 2024
d1db2a0
feat: add user buy lotto fnc in LottoPlayer class
pigpgw Feb 5, 2024
c6d9e8d
test: 구매한 만큼 로또가 생성되는지 테스트하는 코드 추가
pigpgw Feb 5, 2024
ce5e4d2
test: add lotto duplicate test code
pigpgw Feb 5, 2024
0f7bb99
test check lotto fnc in LottoMachine class
pigpgw Feb 5, 2024
d7bffa0
add: getWinnigNumber from user fnc in LottoMachine class
pigpgw Feb 5, 2024
e86f6bb
add: getBonusNumber from user fnc in LottoMachine class
pigpgw Feb 5, 2024
41bf54e
feat: lotto Player input purchase amount fnc
pigpgw Feb 5, 2024
73f650b
refactor: rename setSeed to setPurchaseAmount
pigpgw Feb 5, 2024
2e1f8c2
feat:add check user input purchaseAmount validator
pigpgw Feb 5, 2024
fe7178c
feat:add check user input purchaseAmount validator
pigpgw Feb 5, 2024
94b4b53
feat:modify check user input purchaseAmount validator
pigpgw Feb 5, 2024
2dfca27
delete: 불필요한 코드 삭제
pigpgw Feb 5, 2024
ce0ad2b
feat: add bonus number validator
pigpgw Feb 5, 2024
77ed8db
feat: add print userBuyLottoList fnc in lottoplayer.js
pigpgw Feb 5, 2024
c33fe30
docs: UPDATE README.md
pigpgw Feb 5, 2024
cb09169
feat: print WinnigUserResult fnc
pigpgw Feb 5, 2024
ba174bf
feat: add calculate and print ravinue fnc
pigpgw Feb 5, 2024
525caff
chore: 불필요한 코드 삭제
pigpgw Feb 5, 2024
b9fc7e2
fix: 로또 리스트 출력 테스트 오류 수정
pigpgw Feb 5, 2024
9d844c3
fix: 구매 금액 예외 처리 오류 해결
pigpgw Feb 5, 2024
f0a384f
docs: UPDATE README.md
pigpgw Feb 5, 2024
bada28e
Refactor: Separate game message constants
pigpgw Feb 6, 2024
1979e71
refactor: rename winningDetails to winningDetailsCount in LottoMachine
pigpgw Feb 6, 2024
10730e3
feat: add isValidScoprNumber fnc in validator
pigpgw Feb 6, 2024
ed744b8
docs,UPADET.md
pigpgw Feb 6, 2024
d93b211
최종 제출
pigpgw Feb 6, 2024
0e3f64f
Refactor: Extract methods for checking winning and bonus numbers
pigpgw Feb 6, 2024
8a18878
docs: UPDATE READEME.md
pigpgw Feb 6, 2024
0256645
Update README.md
pigpgw Feb 6, 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
8 changes: 8 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: ['airbnb', 'plugin:prettier/recommended'],
rules: {
'prettier/prettier': ['error', { endOfLine: 'auto' }], // 공백 문자 호환 설정
'operator-linebreak': ['error', 'before'], // 할당 연산자 줄바꿈 설정
'max-depth': ['error', 2], // 들여쓰기 깊이(depth) 제한 (2주차 미션 요구 사항)
},
};
12 changes: 12 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
printWidth: 80, // 한 줄 최대 문자 수
tabWidth: 2, // 들여쓰기 시, 탭 너비
useTabs: false, // 스페이스 대신 탭 사용
semi: true, // 문장 끝 세미콜론 사용
singleQuote: true, // 작은 따옴표 사용
trailingComma: 'all', // 꼬리 콤마 사용
bracketSpacing: true, // 중괄호 내에 공백 사용
arrowParens: 'avoid', // 화살표 함수 단일 인자 시, 괄호 생략
proseWrap: 'never', // 마크다운 포매팅 제외
endOfLine: 'auto', // 개행문자 유지 (혼합일 경우, 첫 줄 개행문자로 통일)
};
12 changes: 6 additions & 6 deletions __tests__/LottoTest.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Lotto from "../src/Lotto.js";
import Lotto from '../src/DongHangLottery/Lotto.js';

describe("로또 클래스 테스트", () => {
test("로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.", () => {
describe('로또 클래스 테스트', () => {
test('로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.', () => {
expect(() => {
new Lotto([1, 2, 3, 4, 5, 6, 7]);
}).toThrow("[ERROR]");
}).toThrow('[ERROR]');
});

// TODO: 이 테스트가 통과할 수 있게 구현 코드 작성
test("로또 번호에 중복된 숫자가 있으면 예외가 발생한다.", () => {
test('로또 번호에 중복된 숫자가 있으면 예외가 발생한다.', () => {
expect(() => {
new Lotto([1, 2, 3, 4, 5, 5]);
}).toThrow("[ERROR]");
}).toThrow('[ERROR]');
});

// 아래에 추가 테스트 작성 가능
Expand Down
94 changes: 94 additions & 0 deletions __tests__/exTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import LottoTicketGenerator from '../src/DongHangLottery/LottoTicketGenerator';
import LottoPlayer from '../src/DongHangLottery/LottoPlayer.js';
import Lotto from '../src/DongHangLottery/Lotto.js';

// describe('로또 생성 테스트', () => {
test('생성된 로또 개별 번호가 1 ~ 45 사이인 숫자인지 테스트한다.', () => {
const Lotto = new LottoTicketGenerator().makeLotto().getLottoNumber();
Lotto.forEach(num => {
expect(!isNaN(num)).toBeTruthy();
expect(num).toBeGreaterThan(0);
expect(num).toBeLessThan(46);
});
});

// test('생성된 로또 개별 번호가 1 ~ 45 사이인지 테스트한다.', () => {
// const Lotto = new LottoTicketGenerator().makeLotto();
// expect(Lotto.getLottoNumber().length).toEqual(6);
// });

// test('사용자가 구매한 로또 번호들 생성 체크', () => {
// const mokPlayer = new LottoPlayer(2000);
// expect(mokPlayer.getUserLottoList().length).toEqual(2);
// });

// test('발행한 로또 중복 번호 테스트', () => {
// const testLottoList = [
// [8, 21, 21, 41, 42, 43],
// [3, 11, 11, 16, 32, 38],
// [7, 16, 16, 35, 36, 44],
// [1, 8, 11, 11, 41, 42],
// [13, 14, 16, 16, 42, 45],
// [7, 11, 30, 30, 42, 43],
// [2, 13, 22, 22, 38, 45],
// [1, 3, 5, 5, 22, 45],
// ];

// testLottoList.forEach(lotto => {
// expect(() => {
// new Lotto(lotto);
// }).toThrow('[ERROR]');
// });
// });
// });

import App from '../src/App.js';
import { MissionUtils } from '@woowacourse/mission-utils';

const mockQuestions = inputs => {
MissionUtils.Console.readLineAsync = jest.fn();

MissionUtils.Console.readLineAsync.mockImplementation(() => {
const input = inputs.shift();

return Promise.resolve(input);
});
};

const mockRandoms = numbers => {
MissionUtils.Random.pickUniqueNumbersInRange = jest.fn();
numbers.reduce((acc, number) => {
return acc.mockReturnValueOnce(number);
}, MissionUtils.Random.pickUniqueNumbersInRange);
};

const getLogSpy = () => {
const logSpy = jest.spyOn(MissionUtils.Console, 'print');
logSpy.mockClear();
return logSpy;
};

const runException = async input => {
// given
const logSpy = getLogSpy();

const RANDOM_NUMBERS_TO_END = [1, 2, 3, 4, 5, 6];
const INPUT_NUMBERS_TO_END = ['1000', '1,2,3,4,5,6', '7'];

// Ensure that the input values are valid
mockRandoms([RANDOM_NUMBERS_TO_END]);
mockQuestions([input, ...INPUT_NUMBERS_TO_END]);

// when
const app = new App();
await app.play();

// then
expect(logSpy).toHaveBeenCalledWith(expect.stringContaining('[ERROR]'));
};

// ...

test('예외 테스트', async () => {
await runException('1000j'); // Ensure the input value is correct
});
54 changes: 54 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 기능 목록
- [x] 사용자의 구입할 금액을 입력 받는 기능
- [x] 구매한 로또 개수를 출력하는 기능
- [x] 로또를 발행 기능
- [x] 당첨번호 6자리 1 ~ 45까지
- [x] 사용자가 입력한 구매한 개수만큼 로또 번호를 발행하는 기능
- [x] 발행한 로또 번호를 출력하는 기능
- [x] 당첨 번호를 입력하는 기능
- [x] 올바른 입력인지 체크하는 기능
- [x] 숫자인지
- [x] 중복된 값이 존재하는지
- [x] 1 ~ 45를 벗어나는지
- [x] 6자리가 맞는지
- [x] 보너스 번호를 입력하는 기능
- [x] 올바른 입력인지 체크하는 기능
- [x] 숫자인지
- [x] 중복된 값이 존재하는지
- [] 1 ~ 45를 벗어나는지
- [x] 1자리가 맞는지
- [x] 입력한 당첨 번호와 보너스 번호를 관리하는 기능
- [x] 당첨 등수 판별 기능
- [x] 당첨된 내역을 저장하는 기능
- [x] 당첨 통계를 계산하는 기능
- [x] 당첨 통계을 출력하는 기능
- [x] 당첨된 수익률 계산 기능 (소수점 둘째 자리에서 반올림)
- [x] 수익률을 출력하는 기능 (당첨 금액 / 로또 총 구매 금액)

# 이전주차 총 피드백 내용정리
### 데이털를 꺼내지 말고 메시지를 던지도록 데이터를 가지는 객체가 일하도록
### 비지니스 로직과 UI 로직 분리
### getter 대신 객체에 메시지를 보내자 객체가 일하도록 하자
### 매직넘버 분리
### 역할과 책임 분산
### 단발성 코드 단축
### 테스트 코드도 코드다
### 기능 단위 커밋
### 객체를 객체스럽게 사용
### 내가 작성한 로직에 이유를 설멍할 수 있기
### 작명 신경쓰기
### 출력 메세지 따로 관리
### 다양한 에러 상황 생각하기 - 경험에 빗대어서 생각해보기

# 할일
기능별 구체적 테스트
메시지 분리
매직 넘버 분리
함수가 한가지 기능만 하게
비즈니스 로직과 UI 로직 분리
경험에 근거한 예외 처리 구현
코드 이쁘게
클린코드 노력하기
인덴트 뎁스 체크
필드 줄여보기
get set 무작위하게 사용했는지 체크
Loading