[문자열 계산기] 김난슬 미션 제출합니다.#8
[문자열 계산기] 김난슬 미션 제출합니다.#8seulnan wants to merge 4 commits intoJava-JavaScript-Language-Stuty:mainfrom
Conversation
Added a list of features to be implemented in README.md. This serves as a roadmap for the upcoming development tasks.
…ult delimiters Implemented sum calculation using split and Java Streams. - Supported default delimiters (comma, colon) - Empty input returns 0 - Unit tests added to verify expected behavior.
…ault and custom delimiters - Supported default delimiters (comma, colon) - Added support for custom delimiters (e.g., `//;\n1;2;3`) - Unit tests added to verify expected behavior
- Implemented exception handling for negative numbers and invalid input formats - Throws `IllegalArgumentException` when an invalid input is encountered - Ensured proper application termination upon encountering an exception - Verified functionality using provided integration test code
moongua404
left a comment
There was a problem hiding this comment.
첫 주차부터 MVC패턴, Junit, stream API 등등 많은 부분들을 적용시킨 부분이 눈에 띄는 것 같습니다. 개인적으로는 다양한 예외를 구체적으로 처리한 부분이 인상깊었습니다! 저도 예외처리를 좀 더 신경써야 할 것 같아요...ㅎㅎ
1주차 미션 너무 수고많으셨습니다!
| import calculator.view.InputView; | ||
| import calculator.view.OutputView; | ||
|
|
||
| public class CalculatorController { |
There was a problem hiding this comment.
컨트롤러에서 뷰와 모델을 static call을 하는 이유가 있나요?
특별한 이유가 없다면 의존성을 생각해서 DI를 하는게 더 낫지 않을까요?
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class Calculator { |
There was a problem hiding this comment.
필드가 없고 기능만 있다면 모델 보다는 service나 utils로 취급되는게 더 적절해보여요!
모델로 둔다면 모델인 만큼 상태를 저장하는 목적 등이 강조되면 좀 더 좋을 것 같아요
| import java.util.regex.Pattern; | ||
|
|
||
| public class Calculator { | ||
| public static int processSum(String numbers) { |
There was a problem hiding this comment.
이 메서드가 갖고있는 책임이 너무 큰 것 같습니다. 구분자를 확인 및 설정하는 것, 예외를 처리하는 것, 계산하는 것 등 세부 기능으로 메서드를 만들어 분리하는 쪽이 더 좋지 않을까요?
|
|
||
| if (matcher.find()) { | ||
| String customDelimiter = Pattern.quote(matcher.group(1)); | ||
| delimiters = Arrays.asList(customDelimiter, ",", ":"); |
There was a problem hiding this comment.
delimiter 필드를 재정의할 필요가 있을까요? List로 둔다면 ArrayList 내지는 LinkedList 등으로 두고 원소를 추가하는 편이 더 직관적으로 와닿을 것 같아요!
There was a problem hiding this comment.
동의합니다.
한 번에 사용 가능한걸 두 번에 나눌 필요는 없다고 생각합니당
| .sum(); | ||
| } | ||
|
|
||
| private static int parseValidation(String num) { |
There was a problem hiding this comment.
밑에서 변환 예외와 음수 예외를 다루는데 제가 받아들이기에는 역할이 2개여서 가독성이 떨어지는 것 같아요. 개인적인 생각으로는 검증 역시 메서드를 나눠도 좋을 것 같아요.
그리고 검증을 모델 내부에 두신 이유도 궁금합니다!ㅎㅎ
There was a problem hiding this comment.
검증이랑 예외처리를 따로 분리하고싶었으나...시간 부족이슈로.. 구현과 테스트 정상작동에 집중했습니다. 수정해보겠습니다!
| .sum(); | ||
| } | ||
|
|
||
| private static int parseValidation(String num) { |
There was a problem hiding this comment.
어떠한 기능만 수행해서 return해주는 메서드의 파라미터는 첫 글자만 남겨서 네이밍해도 괜찮을 것 같아요.
ex) number -> n, string -> s
There was a problem hiding this comment.
제안해주신 방식도 간결한 코드에서 효과적일 수 있다고도 생각합니다. 다만, 네이밍이 짧아지면 가독성이 떨어지고 유지보수할 때 혼란이 될 수도 있다고 생각해서요 그래도 현록님이 이 방식이 더 괜찮다고 생각하시는 이유가 있을까용? 생각하시는 더 좋은 규칙이 있다면 같이 얘기해보고싶어요! @Regyung
| void 기본_구분자_혼합사용_테스트() { | ||
| assertThat(Calculator.processSum("//;\\n1;2,3:4")).isEqualTo(10); | ||
| } | ||
| } |
There was a problem hiding this comment.
저도 나중에 생각난 것이지만 커스텀 구분자가 2개 이상일 수도 있을 상황이 존재할 것도 같습니다!
|
|
||
| if (matcher.find()) { | ||
| String customDelimiter = Pattern.quote(matcher.group(1)); | ||
| delimiters = Arrays.asList(customDelimiter, ",", ":"); |
| System.out.println("결과 : " + result); | ||
| } | ||
| public static void printError(String message) { | ||
| System.out.println("오류 발생 : " + message); |
|
|
||
| if (matcher.find()) { | ||
| String customDelimiter = Pattern.quote(matcher.group(1)); | ||
| delimiters = Arrays.asList(customDelimiter, ",", ":"); |
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
|
|
||
| if (matcher.find()) { | ||
| String customDelimiter = Pattern.quote(matcher.group(1)); | ||
| delimiters = Arrays.asList(customDelimiter, ",", ":"); |
There was a problem hiding this comment.
동의합니다.
한 번에 사용 가능한걸 두 번에 나눌 필요는 없다고 생각합니당
There was a problem hiding this comment.
문자열 중간에 커스텀 구분자를 추가할 순 없을까요?
예) //]\n1]//[\n1,2
문제서 어느정도까지의 융통성을 요구하는지 모르겠는데 어떻게 판단하고 케이스를 짜셨나요
There was a problem hiding this comment.
커스텀 구분자는 문자열 앞부분의 //와 \n 사이에 위치하는 문자를 사용한다 는 기능 요구사항을 기준으로 잡았습니다. 입력값을 커스텀 구분자로 나눈 후에도 숫자가 아닌 값이 포함될 경우, 이는 잘못된 입력이라고 판단했습니다. 따라서, 경수님이 말씀해주신 중간에 임의의 구분자를 추가하는 케이스는 예외로 처리하는 것이 더 적절하다고 보았습니다
There was a problem hiding this comment.
혹시 경수님께서 중간에 커스텀 구분자를 허용해야 한다고 생각하신다면, 어떤 요구사항을 기준으로 고려하셨는지 의견을 나눠보면 좋을 것 같아요! @Siul49
| import calculator.model.Calculator; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; |
신경써서 구현한 부분
피드백이 필요한 부분
고려한 예외