-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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단계-문자열 덧셈 계산기 #5909
2단계-문자열 덧셈 계산기 #5909
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현용님 안녕하세요!
2단계 미션 잘 진행 해 주셨네요 :)
코멘트를 좀 남겨 뒀는데, 확인 후 리뷰 재요청 해주세요 ~
고생 많으셨습니다!
} | ||
|
||
if (isNumber(text)) { | ||
return Integer.parseInt(text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
숫자 하나만 있는 경우는 getSplitSum에서 숫자로 반환될거라 굳이 분기를 안해도 되지 않을까요 ?
return sum; | ||
} | ||
|
||
static private int getSingleNumber(String text) throws RuntimeException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked exception과 unchecked exception은 어떤 차이가 있을까요 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓기능 요구사항중 6번째에 "음수를 전달할 경우 RuntimeException 예외가 발생해야 한다."라고 되어 있어서, RunetimeException을 던진건데 혹시 제가 잘못 이해한 걸까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아뇨 ~ 질문의 의도는 RuntimeException을 throws 한 이유가 있는지에 대한거였습니다!
static private int sumStringToken(String[] tokens) throws RuntimeException { | ||
int sum = 0; | ||
|
||
for(String token: tokens) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stream API를 이용해보면 어떨까요 ?
return Integer.parseInt(text); | ||
} | ||
|
||
if (text.startsWith("//")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 조건은 getCustomDelimiterSum 안에서도 다시 하고있는 것 같은데, 지금 이 스코프의 분기를 34번 라인 조건에서 해보는 건 어떨까요 ?
} | ||
|
||
static private int getSplitSum(String text) throws RuntimeException { | ||
String[] tokens = text.split(",|:"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구분자를 상수로 정의해보면 어떨까요 ?
assertThat(result).isEqualTo(0); | ||
|
||
result = StringAddCalculator.splitAndSum(""); | ||
assertThat(result).isEqualTo(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위와 아래가 엄밀하게는 다른 인풋에 대한 테스트라 @ParameterizedTest
를 이용해보면 좋을 것 같아요 ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현용님 안녕하세요!
피드백 반영 잘 해 주셨네요 :)
PR은 머지하도록 하겠습니다.
고생 많으셨습니다!
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class StringAddCalculator { | ||
private static final String DELIM = ",|:"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
sum += getSingleNumber(token); | ||
} | ||
return sum; | ||
return Arrays.stream(tokens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
2단계-문자열 덧셈 계산기 코드에 대한 PR 리뷰를 요청합니다.