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

Step1 문자열 덧셈 계산기 #1085

Open
wants to merge 7 commits into
base: goodbyeyo
Choose a base branch
from

Conversation

goodbyeyo
Copy link

안녕하세요

Step1 문자열 덧셈 계산기 PR 리뷰 요청 드립니다

앞으로 잘 부탁드립니다

@goodbyeyo goodbyeyo changed the title Feature/step1 string calculator Step1 문자열 덧셈 계산기 Nov 26, 2024
Copy link

@vsh123 vsh123 left a comment

Choose a reason for hiding this comment

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

안녕하세요!
계산기 작성 잘해주셨네요!! 💯

몇가지 코멘트를 남겼으니 확인부탁드립니다~!!

# kotlin-lotto

### Step1. 문자열 덧셈 계산기
Copy link

Choose a reason for hiding this comment

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

기능요구사항 작성 👍

@@ -0,0 +1,11 @@
package calculator

class Application
Copy link

Choose a reason for hiding this comment

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

삭제 가능해보이는 선언이네요! :)

package calculator

class UnparsedExpression(
var text: String? = null,
Copy link

Choose a reason for hiding this comment

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

text를 var이 아닌 val로 선언할 수 없을까요?? 지금은 text값을 외부에서 set 가능할 것 같아요 :)

}

fun splitText(): TextTokens {
val value = requireNotNull(text) { "입력값을 확인하세요" }
Copy link

Choose a reason for hiding this comment

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

  1. 빈 문자열 또는 null을 입력할 경우 0을 반환해야 한다. (예 : “” => 0, null => 0)

이라는 요구사항에 부합하는 조건이 아닌것 같아요! init에서 "0"이 됐다는 전제하에 작성된 코드로 보이는데, 이부분을 수정해보면 좋을 것 같습니다!

Comment on lines +32 to +36
result?.let {
val customDelimiter = it.groupValues[1]
return it.groupValues[2].split(customDelimiter)
}
return emptyList()
Copy link

Choose a reason for hiding this comment

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

elvis(?:) 연산을 활용하면 아래와 같이 작성이 가능해보입니다!

Suggested change
result?.let {
val customDelimiter = it.groupValues[1]
return it.groupValues[2].split(customDelimiter)
}
return emptyList()
return result?.let {
val customDelimiter = it.groupValues[1]
it.groupValues[2].split(customDelimiter)
} ?: emptyList()

Comment on lines +27 to +30
textTokens.findToken()[0] shouldBe PositiveNumber.of("1")
textTokens.findToken()[1] shouldBe PositiveNumber.of("2")
textTokens.findToken()[2] shouldBe PositiveNumber.of("3")
textTokens.findToken()[3] shouldBe PositiveNumber.of("4")
Copy link

Choose a reason for hiding this comment

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

shouldContainExactly를 활용하면 조금 더 심플하게 검증할 수 있을 것 같아요~!


@ParameterizedTest
@ValueSource(strings = ["//@\n1@2@3", "//;\n1;2;3"])
fun `커스텀 구분자로 분리할수 있다3`(text: String) {
Copy link

Choose a reason for hiding this comment

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

커스텀 구분자와 default구분자를 함께 사용할 수는 없는걸까요? //@\n1@2;3 같은거요!

Comment on lines +23 to +27
val tokens = TextTokens()
for (text in textTokens) {
tokens.addToken(text)
}
return tokens
Copy link

Choose a reason for hiding this comment

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

TextTokens의 tokens을 mutableList가 아닌 immutableList로 만들 수 있는 방법을 고민해보시면 좋을 것 같습니다!

textTokens.map을 이용해서 tokens 리스트를 만들고 해당 리스트로 바로 생성해주면 어떨까 싶어요!

fun `숫자가 아닌 문자는 예외가 발생한다`() {
shouldThrow<RuntimeException> {
PositiveNumber.of("a")
}.apply {
Copy link

Choose a reason for hiding this comment

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

https://hyeon9mak.github.io/using-kotlin-scope-function-correctly/#-apply

현재 위치에서 apply로 검증하는게 괜찮은지 고민해보면 좋을 것 같아요!

package calculator

object AdditionCalculator {
fun calculate(tokens: TextTokens): Int {
Copy link

Choose a reason for hiding this comment

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

미사용하는 함수로 보입니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants