generated from Learning-Is-Vital-In-Development/study-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 문자열 캐싱 * test: InputView 테스트 * test: Amount 테스트 수정 * fix: 수동 로또 수가 음수인 경우 검증 * refactor: 상수 관리 방법 변경 * refactor: Amount 위치 변경 * feat: Number 클래스 구현 및 테스트 * test: InputViewTest 테스트 작성 * refactor: 린트 수정 * refactor: 린트 수정 * refactor: 변수 명 수정 --------- Co-authored-by: 이건창 <[email protected]>
- Loading branch information
1 parent
3227453
commit 431c915
Showing
15 changed files
with
163 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/model/money/Amount.kt → src/main/kotlin/view/Amount.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package view | ||
|
||
class Number(private val stringNumber: String) { | ||
private val integers = '0'..'9' | ||
|
||
init { | ||
require(stringNumber.isNotBlank()) { "번호가 비어있을 수 없습니다." } | ||
require(stringNumber.isInt()) { INVALID_NUMBER_FORMAT_MESSAGE } | ||
} | ||
|
||
fun getInt() = stringNumber.toInt() | ||
|
||
private fun String.isInt() = this.all { it in integers } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
package view | ||
|
||
const val EMPTY_VALUE_ERROR_MESSAGE = "값이 비어있습니다." | ||
const val INVALID_NUMBER_FORMAT_MESSAGE = "입력한 값은 숫자여야 합니다." | ||
const val NOT_ENOUGH_MONEY_MESSAGE = "금액이 부족합니다" | ||
const val INVALID_LOTTO_NUMBER_COUNT_MESSAGE = "로또 번호는 6개여야 합니다." | ||
internal const val INPUT_MONEY_MESSAGE = "구입금액을 입력해 주세요." | ||
internal const val INPUT_MANUAL_INPUT_MESSAGE = "수동으로 구매할 로또 수를 입력해 주세요." | ||
internal const val INPUT_LOTTO_NUMBER_MESSAGE = "로또 번호를 입력해 주세요. (공백으로 구분)" | ||
|
||
class OutputView { | ||
fun requestCapital() { | ||
println("구입금액을 입력해 주세요.") | ||
println(INPUT_MONEY_MESSAGE) | ||
} | ||
|
||
fun printMessage(message: String) { | ||
println(message) | ||
} | ||
|
||
fun requestManualCount() { | ||
println("수동으로 구매할 로또 수를 입력해 주세요.") | ||
println(INPUT_MANUAL_INPUT_MESSAGE) | ||
} | ||
|
||
fun requestManualLottoNumber() { | ||
println("로또 번호를 입력해 주세요. (공백으로 구분)") | ||
println(INPUT_LOTTO_NUMBER_MESSAGE) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package view | ||
|
||
import io.kotest.assertions.throwables.shouldThrowExactly | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import java.math.BigDecimal | ||
|
||
class AmountTest : BehaviorSpec( | ||
{ | ||
|
||
given("금액을 입력받을 때") { | ||
`when`("숫자를 금액으로 입력하면") { | ||
val amount = "2400" | ||
then("금액에 맞는 BigDecimal 자료형이 반환된다.") { | ||
Amount(amount).getBigDecimal() shouldBe BigDecimal(amount) | ||
} | ||
} | ||
|
||
`when`("문자열을 금액으로 입력하면") { | ||
val invalidAmount = "invalid amount" | ||
then("IllegalArgumentException 예외가 발생한다") { | ||
shouldThrowExactly<IllegalArgumentException> { | ||
Amount(invalidAmount) | ||
} | ||
} | ||
} | ||
|
||
`when`("숫자가 포함된 문자열을 금액으로 입력하면") { | ||
val invalidAmount = "3k34j4" | ||
then("IllegalArgumentException 예외가 발생한다") { | ||
shouldThrowExactly<IllegalArgumentException> { | ||
Amount(invalidAmount) | ||
} | ||
} | ||
} | ||
|
||
`when`("비어있는 문자열을 금액으로 입력하면") { | ||
val invalidAmount = "" | ||
then("IllegalArgumentException 예외가 발생한다") { | ||
shouldThrowExactly<IllegalArgumentException> { | ||
Amount(invalidAmount) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package view | ||
|
||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.collections.shouldContainAll | ||
import java.io.ByteArrayInputStream | ||
|
||
private const val WHITE_SPACE = " " | ||
|
||
class InputViewTest : BehaviorSpec( | ||
{ | ||
given("사용자의 입력을 받을 때") { | ||
val inputView = InputView() | ||
val strings = "12 32 2 1 4 5" | ||
val expected = strings.split(WHITE_SPACE).map { it.toInt() } | ||
`when`("$strings 번호를 입력하면") { | ||
System.setIn(ByteArrayInputStream(strings.toByteArray())) | ||
val actual = inputView.requestLottoNumber() | ||
then("$expected 리스트가 반환된다.") { | ||
actual shouldContainAll expected | ||
} | ||
} | ||
} | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package view | ||
|
||
import io.kotest.assertions.throwables.shouldThrowExactly | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class NumberTest : BehaviorSpec( | ||
{ | ||
given("로또 번호를 입력 할 때") { | ||
`when`("숫자를 로또 번호로 입력하면") { | ||
val stringNumber = "23" | ||
val number = Number(stringNumber) | ||
then("올바른 숫자를 반환한다.") { | ||
number.getInt() shouldBe stringNumber.toInt() | ||
} | ||
} | ||
|
||
`when`("비어있는 문자열을 입력하면") { | ||
val invalidNumber = "" | ||
then("예외가 발생한다.") { | ||
shouldThrowExactly<IllegalArgumentException> { | ||
Number(invalidNumber) | ||
} | ||
} | ||
} | ||
|
||
`when`("숫자가 포함되지 않은 문자열을 입력하면") { | ||
val invalidNumber = "invalid Number" | ||
then("예외가 발생한다.") { | ||
shouldThrowExactly<IllegalArgumentException> { | ||
Number(invalidNumber) | ||
} | ||
} | ||
} | ||
|
||
`when`("숫자와 문자가 포함된 문자열을 입력하면") { | ||
val invalidNumber = "d3" | ||
then("예외가 발생한다.") { | ||
shouldThrowExactly<IllegalArgumentException> { | ||
Number(invalidNumber) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
) |