Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[엘리] 로또 미션 제출합니다. #126

Merged
merged 23 commits into from
Feb 26, 2020
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
83f6878
[docs] README 작성
Feb 18, 2020
263b9af
[feature] 로또 숫자 객체 비교 기능 구현
Feb 18, 2020
2395c33
[feature] 로또 숫자 생성 예외처리 기능 구현
Feb 18, 2020
97e02d3
[feature] 돈 객체 생성자 구현
Feb 18, 2020
f26dcb6
[feature] InputView 구입금액 입력 구현
Feb 18, 2020
088692b
[feature] 티켓 객체 구현
Feb 18, 2020
1071d9a
[refactor] LottoNumber 클래스 enum type으로 수정
Feb 18, 2020
3b46dbf
[feature] 당첨 번호 객체 구현
Feb 18, 2020
25b425c
[refactor] LottoNumbersDto 적용 및 관련 로직 수정
Feb 19, 2020
62f3572
[feature] 티켓과 당첨 번호 중복 확인 구현
Feb 19, 2020
34361ab
[feature] 랜덤 팩토리 구현
Feb 19, 2020
9518660
[feature] 고정값으로 당첨번호 생성 구현
Feb 19, 2020
44404dc
[feature] InputView 당첨번호와 보너스볼 입력 구현
Feb 19, 2020
164be4e
[feature] OutputView 티켓 구매 출력 구현
Feb 19, 2020
50ebf5a
[feature] 로또 당첨 결과 찾기 메서드 구현
Feb 19, 2020
89b3bd8
[refactor / feature] 구조 리팩토링 및 로또 당첨 결과 구현
Feb 20, 2020
efc5d5a
[refactor] 리펙토링
Feb 20, 2020
9b9f778
[refactor] 리펙토링, 수익률 에러 수정
Feb 20, 2020
dc876fc
[refactor] 리펙토링
Feb 20, 2020
40468b3
[refactor] DTO와 비즈니스 로직 책임 분리
YebinK Feb 23, 2020
15292ad
[refactor] 티켓 생성 로직 수정
YebinK Feb 24, 2020
5081b5c
[refactor] 검증 로직 도메인으로 이동
YebinK Feb 25, 2020
4ee67e9
[refactor] Money 객체 테스트 케이스 추가
YebinK Feb 25, 2020
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
Prev Previous commit
Next Next commit
[refactor] LottoNumbersDto 적용 및 관련 로직 수정
Ticket 객체와 WinningNumbers 객체의 생성자에 적용
KimSeongGyu1 authored and KimSeongGyu1 committed Feb 19, 2020
commit 25b425ce87c29a460db68f2ccc526adab35e455a
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

> 기능 요구사항

- [ ] 구입금액을 입력받는다.
- [x] 구입금액을 입력받는다.
- [x] (예외) 1000원 이하 단위일 경우
- [x] (예외) 숫자가 아닐 경우
- [x] (예외) 음수 또는 50000원 이상 입력될 경우
1 change: 1 addition & 0 deletions src/main/java/domain/LottoNumber.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import java.util.List;

public enum LottoNumber {
YebinK marked this conversation as resolved.
Show resolved Hide resolved
ERROR(-1),
ONE(1),
YebinK marked this conversation as resolved.
Show resolved Hide resolved
TWO(2),
THREE(3),
Original file line number Diff line number Diff line change
@@ -2,9 +2,16 @@

import java.util.Set;

abstract class AbstractNumbersContainer {
abstract class LottoNumbersContainer {
private static final int TICKET_SIZE = 6;

protected final Set<LottoNumber> lottoSixNumbers;

public LottoNumbersContainer(LottoNumbersDto lottoNumbersDto) {
validateSize(lottoNumbersDto.getSixNumbers());
this.lottoSixNumbers = lottoNumbersDto.getSixNumbers();
}

protected void validateSize(Set<LottoNumber> lottoNumbers) {
if (lottoNumbers.size() != TICKET_SIZE) {
throw new IllegalArgumentException("6개의 숫자를 입력해주세요.");
25 changes: 25 additions & 0 deletions src/main/java/domain/LottoNumbersDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package domain;

import java.util.Set;

public class LottoNumbersDto {
private final Set<LottoNumber> sixNumbers;
private final LottoNumber bonusNumber;

public LottoNumbersDto(Set<LottoNumber> sixNumbers) {
this(sixNumbers, LottoNumber.ERROR);
}

public LottoNumbersDto(Set<LottoNumber> sixNumbers, LottoNumber bonusNumber) {
this.sixNumbers = sixNumbers;
this.bonusNumber = bonusNumber;
}

public Set<LottoNumber> getSixNumbers() {
return sixNumbers;
}

public LottoNumber getBonusNumber() {
return bonusNumber;
}
}
11 changes: 3 additions & 8 deletions src/main/java/domain/Ticket.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package domain;

import java.util.List;
import java.util.Set;

public class Ticket extends AbstractNumbersContainer {

private final Set<LottoNumber> lottoNumbers;

public Ticket(Set<LottoNumber> lottoNumbers) {
validateSize(lottoNumbers);
this.lottoNumbers = lottoNumbers;
public class Ticket extends LottoNumbersContainer {
public Ticket(LottoNumbersDto lottoNumbersDto) {
super(lottoNumbersDto);
}
}
30 changes: 22 additions & 8 deletions src/main/java/domain/WinningNumbers.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
package domain;

import java.util.Set;
public class WinningNumbers extends LottoNumbersContainer {

public class WinningNumbers extends AbstractNumbersContainer {

private final Set<LottoNumber> lastWeekNumbers;
private final LottoNumber bonusNumber;

public WinningNumbers(Set<LottoNumber> lastWeekNumbers, LottoNumber bonusNumber) {
validateSize(lastWeekNumbers);
this.lastWeekNumbers = lastWeekNumbers;
this.bonusNumber = bonusNumber;
public WinningNumbers(LottoNumbersDto lottoNumbersDto) {
super(lottoNumbersDto);
validateBonusNumber(lottoNumbersDto.getBonusNumber());
this.bonusNumber = lottoNumbersDto.getBonusNumber();
}

private void validateBonusNumber(LottoNumber bonusNumber) {
validateErrorBonusNumber(bonusNumber);
validateDuplicatedBonusNumber(bonusNumber);
}

private void validateErrorBonusNumber(LottoNumber bonusNumber) {
if (bonusNumber != LottoNumber.ERROR) {
throw new IllegalArgumentException("잘못된 보너스 번호를 입력했습니다.");
}
}

private void validateDuplicatedBonusNumber(LottoNumber bonusNumber) {
if (this.lottoSixNumbers.contains(bonusNumber)) {
throw new IllegalArgumentException("당첨번호와 보너스 번호가 중복됩니다.");
}
}
}
11 changes: 8 additions & 3 deletions src/main/java/view/InputView.java
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import java.util.Scanner;

public class InputView {
YebinK marked this conversation as resolved.
Show resolved Hide resolved
private static final String NUMBER_REGEX = "^[0-9]+$";

private static Scanner scanner = new Scanner(System.in);

public static Money enterMoney() {
@@ -14,9 +16,12 @@ public static Money enterMoney() {
}

private static int parseMoney(String input) {
try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
validateNumber(input);
return Integer.parseInt(input);
}

private static void validateNumber(String input) {
if (!input.matches(NUMBER_REGEX)) {
throw new NumberFormatException("숫자를 입력해주세요.");
}
}
28 changes: 10 additions & 18 deletions src/test/java/domain/TicketTest.java
Original file line number Diff line number Diff line change
@@ -5,9 +5,6 @@

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -17,12 +14,8 @@ public class TicketTest {
@Test
@DisplayName("티켓 생성")
void ticketConstructor() {
Set<LottoNumber> lottoNumberList = new HashSet<>(Arrays.asList(LottoNumber.getLottoNumber(1),
LottoNumber.getLottoNumber(2),
LottoNumber.getLottoNumber(3),
LottoNumber.getLottoNumber(4),
LottoNumber.getLottoNumber(5)));
assertThatThrownBy(() -> new Ticket(lottoNumberList))
LottoNumbersDto lottoNumbersDto = createLottoNumberDto(1,2,3,4,5,5);
assertThatThrownBy(() -> new Ticket(lottoNumbersDto))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("6개의 숫자를 입력해주세요.");
}
@@ -37,13 +30,12 @@ void ticketConstructor() {
// assertThat(ticket1.getWith(ticket2)).isEqualTo(3);
// }
//
// private Set<LottoNumber> createLottoNumber(int number1, int number2, int number3, int number4, int number5, int number6) {
// Set<LottoNumber> lottoNumberList = new HashSet<>(Arrays.asList(LottoNumber.getLottoNumber(number1),
// LottoNumber.getLottoNumber(number2),
// LottoNumber.getLottoNumber(number3),
// LottoNumber.getLottoNumber(number4),
// LottoNumber.getLottoNumber(number5),
// LottoNumber.getLottoNumber(number6)));
// return lottoNumberList;
// }
private LottoNumbersDto createLottoNumberDto(int number1, int number2, int number3, int number4, int number5, int number6) {
return new LottoNumbersDto(new HashSet<>(Arrays.asList(LottoNumber.getLottoNumber(number1),
LottoNumber.getLottoNumber(number2),
LottoNumber.getLottoNumber(number3),
LottoNumber.getLottoNumber(number4),
LottoNumber.getLottoNumber(number5),
LottoNumber.getLottoNumber(number6))));
}
}
13 changes: 7 additions & 6 deletions src/test/java/domain/WinningNumbersTest.java
Original file line number Diff line number Diff line change
@@ -14,20 +14,21 @@ public class WinningNumbersTest {
@Test
@DisplayName("당첨 번호 객체 생성")
void winningNumberConstructor() {
Set<LottoNumber> lastWeekNumbers = createLastWeekNumbers(1, 2, 3, 4, 5, 5);
LottoNumber bonusNumber = LottoNumber.getLottoNumber(7);
assertThatThrownBy(() -> new WinningNumbers(lastWeekNumbers, bonusNumber))
LottoNumbersDto lottoNumbersDto = createLottoNumberDto(1, 2, 3, 4, 5, 5, 7);
assertThatThrownBy(() -> new WinningNumbers(lottoNumbersDto))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("6개의 숫자를 입력해주세요.");
}

private Set<LottoNumber> createLastWeekNumbers(int number1, int number2, int number3, int number4, int number5, int number6) {
Set<LottoNumber> lottoNumberList = new HashSet<>(Arrays.asList(LottoNumber.getLottoNumber(number1),
private LottoNumbersDto createLottoNumberDto(int number1, int number2, int number3, int number4, int number5, int number6, int number7) {
Set<LottoNumber> sixNumbers = new HashSet<>(Arrays.asList(LottoNumber.getLottoNumber(number1),
LottoNumber.getLottoNumber(number2),
LottoNumber.getLottoNumber(number3),
LottoNumber.getLottoNumber(number4),
LottoNumber.getLottoNumber(number5),
LottoNumber.getLottoNumber(number6)));
return lottoNumberList;
LottoNumber bonusNumber = LottoNumber.getLottoNumber(number7);

return new LottoNumbersDto(sixNumbers, bonusNumber);
}
}