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

[로또 2단계] 시아 미션 제출합니다. #135

Open
wants to merge 27 commits into
base: leeyerin0210
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
79bc0e4
refactor : Lotto의 가격 부분 삭제
Leeyerin0210 Feb 25, 2025
133dce9
refactor : 출력 로직 수정 , 로또 결과 산출 로직 수정
Leeyerin0210 Feb 25, 2025
02cb6d7
feat : 유저가 입력한 숫자의 로또를 수동으로 발행하는 기능 추가
Leeyerin0210 Feb 25, 2025
29794c2
fix : 수동과 자동 모든 로또가 출력되도록 변경
Leeyerin0210 Feb 25, 2025
d9ec1a0
refactor: 입력값 검증 방식 수정하여 반복 입력 가능하도록 변경
Leeyerin0210 Feb 25, 2025
66b2a02
refactor: 잘못된 입력값을 받았을 때 다시 입력 받도록 수정
Leeyerin0210 Feb 25, 2025
1907483
docs : 리드미 수정
Leeyerin0210 Feb 25, 2025
6a9e9d9
refactor : 뷰와 도메인이 너무 강하게 결합되지 않도록 수정
Leeyerin0210 Feb 25, 2025
4ed8d62
refactor : 로또 번호를 잘못 입력하면 바로 다시 입력 받도록 수정
Leeyerin0210 Feb 25, 2025
1db3c57
refactor : 출력 로직 일부 수정
Leeyerin0210 Feb 26, 2025
4485eac
refactor : sealed 클래스를 활용해서 오류 처리 일부 수정
Leeyerin0210 Feb 26, 2025
6dd8b3d
refactor : 오류 원인을 사용자가 파악할 수 있도록 출력 수정
Leeyerin0210 Feb 26, 2025
63bb963
feat : 로또 금액 단위의 금액을 입력하지 않으면 남는 돈을 출력하도록 추가
Leeyerin0210 Feb 26, 2025
e401cbd
fix : 테스트 함수 수정
Leeyerin0210 Feb 26, 2025
d07db8c
refactor: 기존 코드 구조를 폐기하고 새로운 설계를 시작
Leeyerin0210 Feb 27, 2025
422eaac
docs: 코드 작성 중 유의할 사항 기재
Leeyerin0210 Feb 27, 2025
0050e23
feat : 로또 넘버 객체 생성
Leeyerin0210 Feb 27, 2025
e7f5664
feat : 로또 객체 생성
Leeyerin0210 Feb 27, 2025
8eb1895
feat : amount 객체 생성
Leeyerin0210 Feb 28, 2025
8444009
feat : amount 객체 지불 함수 작성
Leeyerin0210 Feb 28, 2025
0fd886a
feat : rank 객채 및 winningLotto 객체 생성
Leeyerin0210 Feb 28, 2025
fece2a8
feat : 당첨금 계산 서비스 작성 및 파일 이동
Leeyerin0210 Mar 1, 2025
0220a90
feat : 로또를 자동으로 생성하는 로또 메이커 서비스 추가
Leeyerin0210 Mar 1, 2025
09eb61b
feat : 입출력 기능 추가
Leeyerin0210 Mar 2, 2025
19253ff
refactor : 생성 인터페이스 일관성 추가
Leeyerin0210 Mar 5, 2025
33d22ea
refactor : 비지니스 로직 분리 및 순회 횟수 감소
Leeyerin0210 Mar 6, 2025
00d4c70
refactor : 명확한 오류 원인 전달
Leeyerin0210 Mar 9, 2025
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
Expand Up @@ -26,7 +26,7 @@
- [x] 로또 번호는 오름차순으로 정렬된다.
### 구입금액 및 수량
- [x] 구입 금액을 로또 가격으로 나누면 로또 수량이다.
- [x] 금액은 0 이하일 수 없다.
- [x] 금액은 음수일 수 없다.
- [ ] 구매 후 남은 금액은 마지막에 출력한다.
### 로또 발행
- [ ] 입력된 횟수에 맞게 수동으로 로또를 입력받는다
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/lotto/Amount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ class Amount private constructor(
) {
fun getCount(lottoPrize: Int): Int = money / lottoPrize
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amount를 유연하게 만들었다면, 더이상 "로또" 라는 관심사를 가질 필요가 있을까요?
이 클래스는 LottoAmount가 되어야 했을까요?


fun paymentOrNull(payMoney: Int): Amount? {
if (money < payMoney) return null
return Amount(money - payMoney)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

금액은 음수일 수 없다는 것을 null로 하는게 자연스러운 흐름일까요?
물론 마이너스가 되면 논리적으로 문제가 될 수 있으니 null을 반환할 수 도 있다고 생각하지만.
아무리 빼더라도 0보다 작아지지 않는다는 개념을 적용하면 이렇게 만들어 볼 수도 있습니다.

data class Amount(val money: Int) {
  require(money >= 0)

 fun pay(other: Amount): Amount {
   val newMoney = (money - other.money).coerceAtLeast(0)
   return copy(money = newMoney)
 }
}

결과적으로 이 함수를 사용할 때 마다 null을 컨트롤 해야한다는게 매우 번거롭다고 느껴지니까요


companion object {
fun createOrNull(input: Int): Amount? {
if (input <= 0) return null
if (input < 0) return null
return Amount(input)
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/test/kotlin/lotto/model/AmountTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@ class AmountTest {
}

@Test
fun `소지한 돈이 0 이하이면 null이 생성된다`() {
fun `소지한 돈이 음수이면 null이 생성된다`() {
val amount = Amount.createOrNull(-1)
assertThat(amount).isEqualTo(null)
}

@Test
fun `소지한 돈에 구입 금액을 지불하면 남은 돈을 가진 객채가 생성된다`() {
var amount = Amount.createOrNull(10000)
amount = amount?.paymentOrNull(7000)
assertThat(amount?.money).isEqualTo(3000)
}

@Test
fun `소지한 돈 이상의 구입 금액을 지불하면 null가 생성된다`() {
var amount = Amount.createOrNull(10000)
amount = amount?.paymentOrNull(17000)
assertThat(amount?.money).isEqualTo(null)
}
}