Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
env: {
node: true,
es2021: true,
jest: true,
},

ignorePatterns: ['package*', '.npmrc', '*.md', '.*', '__tests__'],

extends: ['eslint:recommended', 'airbnb-base', 'prettier'],

parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},

rules: {
'no-var': 'error',
'prefer-const': 'error',
'no-undef': 'warn',
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'no-console': 'off',
'no-process-exit': 'warn',

'arrow-body-style': 'off',

'max-depth': ['warn', 2],
'max-lines-per-function': ['warn', { max: 25, skipBlankLines: true, skipComments: true }],
complexity: ['warn', 9],
'class-methods-use-this': 'off',

'no-await-in-loop': 'off',
'no-else-return': 'warn',
'no-nested-ternary': 'error',
'no-ternary': 'warn',
'no-param-reassign': ['error', { props: true, ignorePropertyModificationsFor: ['acc', 'e'] }],
'no-plusplus': 'off',

'import/no-unresolved': 'off',
'import/extensions': 'off',
'import/prefer-default-export': 'off',

'lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
},
};
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package*
.npmrc
*.md
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always"
}
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
# javascript-planetlotto-precourse

## 구현 할 목록

### Model

- Lotto : LottoNumber을 멤버로 가지는 모델
- WinningLotto : LottoNumber과 Lotto 를 멤버로 가지는 모델

- Money : 돈에 관한 모델
- Rank : 등수 판별을 해주는 모델
- LottoMachine : 로또를 발행 해주는 모델

### 기능

#### Lotto

##### Lotto Validaotor

- 타입 판별
- 로또의 숫자 범위 판별 (1~30)
- 숫자 중복 검사

#### LottoMachine

- 로또 발행

#### Money

##### Money Validator

- 타입 판별
- 구매 가능 여부 판별

#### Rank

- 등수 판별해줌

#### LottoService

- 로또 구매
- 당첨 통계 계산

## 추가로 구현할 기능 목록

### refactoring

- LottoNumber: 캐싱을 통해 속도 향상

### expansion

- Money: 수익률 계산
39 changes: 39 additions & 0 deletions __tests__/domain/models/LottoTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Lotto from '../../../src/domain/models/Lotto.js';

const { MIN_RANGE, MAX_RANGE, SIZE } = Lotto.RULE;
describe('Lotto 클래스 생성 테스트', () => {
test(`최소 범위 테스트`, () => {
const testNumbers = [MIN_RANGE - 1, 2, 3, 4, 5];
expect(() => new Lotto(testNumbers)).toThrow(Lotto.ERROR_MESSAGES.RANGE);
}); // 최소 범위

test(`최대 범위 테스트`, () => {
const testNumbers = [1, 2, 3, 4, MAX_RANGE + 1];
expect(() => new Lotto(testNumbers)).toThrow(Lotto.ERROR_MESSAGES.RANGE);
});

test(`로또 숫자 갯수 테스트`, () => {
const testNumbers = [1, 2, 3, 4, 5, 6];
expect(() => new Lotto(testNumbers)).toThrow(Lotto.ERROR_MESSAGES.SIZE);
});

test(`중복 테스트`, () => {
const testNumbers = [1, 2, 3, 5, 5];
expect(() => new Lotto(testNumbers)).toThrow(Lotto.ERROR_MESSAGES.DUPLICATE);
}); // 중복 테스트
}); // describe

describe('Lotto 메서드 테스트', () => {
test(`sort 테스트`, () => {
const testNumbers = [5, 2, 3, 4, 1];
const lotto = new Lotto(testNumbers);

expect(lotto.getNumbers()).toEqual([1, 2, 3, 4, 5]);
}); // sort 테스트

test(`includes 테스트`, () => {
const testNumbers = [1, 2, 3, 4, 5];
const lotto = new Lotto(testNumbers);
expect(lotto.includes(1)).toBe(true);
}); // includes 테스트
});
22 changes: 22 additions & 0 deletions __tests__/domain/models/MoneyTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Money from '../../../src/domain/models/Money.js';

const { UNIT } = Money.RULE;
describe('Money 클래스 생성 테스트', () => {
test(`양수인지`, () => {
const testAmount = -1;
expect(() => new Money(testAmount)).toThrow(Money.ERROR_MESSAGES.NOT_POSITVE);
}); // 최소

test(`단위보다 큰지`, () => {
const testAmount = 0;
expect(() => new Money(testAmount)).toThrow(Money.ERROR_MESSAGES.MININUM);
}); // 최소
});

describe('Money 메서드 테스트', () => {
test(`getLottoCount 테스트`, () => {
const testAmount = UNIT * 4 + 1;
const money = new Money(testAmount);
expect(money.getLottoCount()).toBe(4);
}); // getLottoCount 테스트
});
19 changes: 19 additions & 0 deletions __tests__/domain/models/WinningLottoTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Lotto from '../../../src/domain/models/Lotto.js';
import WinningLotto from '../../../src/domain/models/WinningLotto.js';

const { MIN_RANGE, MAX_RANGE, SIZE } = Lotto.RULE;
describe('Lotto 클래스 생성 테스트', () => {
test(`중복 테스트`, () => {
const lotto = new Lotto([1, 2, 3, 4, 5]);
const bonusNumber = 5;
expect(() => new WinningLotto(lotto, bonusNumber)).toThrow(
WinningLotto.ERROR_MESSAGES.DUPLICATE,
);
}); // 최소 범위

test(`범위 테스트`, () => {
const lotto = new Lotto([1, 2, 3, 4, 5]);
const bonusNumber = 0;
expect(() => new WinningLotto(lotto, bonusNumber)).toThrow(Lotto.ERROR_MESSAGES.RANGE);
}); // 최소 범위
}); // describe
Loading