-
Notifications
You must be signed in to change notification settings - Fork 6
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
혁 문자열 덧셈 계산기 #8
base: yh
Are you sure you want to change the base?
혁 문자열 덧셈 계산기 #8
Conversation
NumberString numberString = new NumberString(inputString); | ||
|
||
String delimiterRegex = delimiters.toRegexString(); | ||
return Arrays.stream(numberString.getValue().split(delimiterRegex)) |
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.
numberstring안에서 value를 꺼내서 splite하는 과정대신, numberstring안에서 split한 결과를 리턴하면 좋을것 같네요.
지금은 numberString 객체안의 값을 NumbersExtractor가 제어하는건데, numberString 객체 안에서 제어할 수 있는 로직이라면 안에 담는게 좋을 것 같아서요. (캡슐화)
Matcher matcher = customDelimiterPattern.matcher(inputString); | ||
if (matcher.find()) { | ||
String customDelimiter = matcher.group(1); | ||
DELIMITER_REGEX = DELIMITER_REGEX + "|" + customDelimiter; |
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.
value = numberString; | ||
return; | ||
} | ||
validateString(inputString); |
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.
위에서 matcher.find()로 통과한상태인데 만약 NumberString이 아니면 어떻게 되나요?
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.
find를 거쳐서 제대로 값이 들어갔다고 생각을 하는데.. 어떤 문제인지 잘 모르겠습니다.
assertThat(result).isEqualTo(6); | ||
} | ||
|
||
@DisplayName("공백 확인") |
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 static final String BLANK = ""; | ||
|
||
public static int calculateWith(String inputString) { | ||
if (inputString.equals(BLANK)) { |
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.
inputString.isEmpty() 로 가능할 것 같습니다. BLANK 상수는 없어도 될 것 같아요!
혹시 null 에 대한 검증은 어딨나여??
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.
null
에 대한 검증이 빠졌군요!
public static final String BASIC_DELIMITER_REGEX = ",|:"; | ||
public static final String CUSTOM_DELIMITER_REGEX = "//(.)\n(.*)"; | ||
|
||
private String DELIMITER_REGEX = BASIC_DELIMITER_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.
상수가 아닌데 상수 컨벤션을 하고 있네욥 !
private String DELIMITER_REGEX = BASIC_DELIMITER_REGEX; | ||
|
||
public Delimiters(String inputString) { | ||
Pattern customDelimiterPattern = Pattern.compile(CUSTOM_DELIMITER_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 이라 상수로 초기화 해두면 좋을 것 같습니다 !
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 static final String BLANK = ""; | ||
|
||
public static int calculateWith(String inputString) { | ||
if (inputString.equals(BLANK)) { |
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.
null
에 대한 검증이 빠졌군요!
//import java.util.regex.Matcher; | ||
//import java.util.regex.Pattern; | ||
// | ||
//public class StringSpliter { |
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.
불필요한 파일은 꼭 제거해주세요!
private String DELIMITER_REGEX = BASIC_DELIMITER_REGEX; | ||
|
||
public Delimiters(String inputString) { | ||
Pattern customDelimiterPattern = Pattern.compile(CUSTOM_DELIMITER_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.
Matcher matcher = customDelimiterPattern.matcher(inputString); | ||
if (matcher.find()) { | ||
String customDelimiter = matcher.group(1); |
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.
커스텀 구분자가 더 늘어날 경우 어떠한 문제점이 발생할 수 있을까요??
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.
어... 음... 늘어난다는 경우가 어떤거죠..?
그리고 늘어난다 해도 잘모르겟습니다 센세..
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.
&&과 $$ 사이에 커스텀 문자가 들어온다던가 하는 새로운 요구사항이 추가되었을 경우요!
|
||
class DelimitersTest { | ||
|
||
@DisplayName("커스텀 구분자 없을 때") |
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.
@DisplayName
을 사용해서 테스트에 대한 설명을 하려한 점은 좋지만
현재 적혀있는 설명만으로는 정확히 어떤 테스트를 하고자 하는지 파악하기가 어렵습니다.
@DisplayName
을 보고 어떠한 동작을 하는지 조금더 자세하게 적어주는게 어떨까요?
테스트 코드는 문서로써의 역할을 수행할 수 있어야합니다!
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.
아, 이게 Delimiters 라는 객체의 Test라는 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.
이 어플리케이션을 처음 보는 사람은 Delimters가 어떤 역할을 하는지 모르는 상태라고 보는게 더 맞을것 같습니다.
그러한 상황에서 테스트 클래스의 이름만 보고 문맥을 파악하기란 쉽지 않을것 같아요!
|
||
return numberString.getSplitStringNumbers(delimiters).stream() | ||
.mapToInt(Integer::valueOf) | ||
.boxed() |
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.
mapToInt 말고 map으로만 하면 boxed 할 필요없이 Integer 리스트로 collect 되지않나요??
No description provided.