-
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단계 - 문자열 덧셈 계산기 #5925
2단계 - 문자열 덧셈 계산기 #5925
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단계 미션 잘 구현해주셨네요!
소소하게 피드백 남겨드렸는데, 확인부탁드리고 다음 단계 진행하시면서 반영 같이 부탁드립니다!
그럼 다음 단계 진행해주세요! 🔥
private static final String DEFAULT_DELIMITER = "[,:]"; | ||
private static final String DELIMITER_FIND_REGEX = "//(.)\n(.*)"; |
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.
상수 👍
if (StringUtils.isNumeric(input)) { | ||
return List.of(Integer.parseInt(input)); | ||
} | ||
Pattern pattern = Pattern.compile(DELIMITER_FIND_REGEX); |
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.
Pattern.compile
은 상수화 하는것도 좋을것 같아요!
구현체를 살펴보면 매번 새로운 Pattern 을 생성하기 때문이에요 🙃
/**
* Compiles the given regular expression into a pattern.
*
* @param regex
* The expression to be compiled
* @return the given regular expression compiled into a pattern
* @throws PatternSyntaxException
* If the expression's syntax is invalid
*/
public static Pattern compile(String regex) {
return new Pattern(regex, 0);
}
} else { | ||
values = input.split(DEFAULT_DELIMITER); | ||
} |
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: else 예약어를 쓰지 않는다.
를 지켜서 해보는것도 좋을것 같아요! :)
private final static NumberSeparator numberSeparator = new NumberSeparator(); | ||
|
||
|
||
public static int splitAndSum(String o) { |
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.
의미있게 변수명을 지어보는것도 좋을것 같아요 :)
@Test | ||
public void splitAndSum_negative() throws Exception { | ||
assertThatThrownBy(() -> StringAddCalculator.splitAndSum("-1,2,3")) | ||
.isInstanceOf(RuntimeException.class); | ||
} | ||
|
||
@Test | ||
public void splitAndSum_문자포함() throws Exception { | ||
assertThatThrownBy(() -> StringAddCalculator.splitAndSum("1,2,test")) | ||
.isInstanceOf(RuntimeException.class); | ||
} |
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.
예외메세지를 추가로 정의해주셨으니, 검증도 같이하는건 어떨까요?
public StringUtils() { | ||
} |
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.
static 메서드만 갖고 있는 클래스의 기본생성자를 열어두셨네요.
이유를 알 수 있을까요? 🤔
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.
고민의 흔적이 남아있던것같습니다. 제거하는 쪽으로 하겠습니다
} catch (NumberFormatException e) { | ||
throw new RuntimeException("숫자가 아닌 값이 입력되었습니다."); | ||
} | ||
if (value < 0) { | ||
throw new 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.
👍
기능 요구사항