Skip to content

Conversation

@Gyeom
Copy link

@Gyeom Gyeom commented Mar 3, 2020

풀리퀘 드립니다.

감사합니다.


public class ResultView {
static void printOutResult(AddCalculator addCalculator, String[] numbers) {
System.out.println(addCalculator.calculate(numbers));
Copy link
Contributor

Choose a reason for hiding this comment

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

view라는 클래스에서 printOutResult는 인자로 받은 것을 print하겠다는 추측으로 읽었는데, 사실상 여기서 addCalculator 연산을 진행하고있네요 이 resultView를 사용하고싶다면, addCalculator의 결과를 받아서 이곳에서 print만 하는게 역할이 분명해질 것 같습니다.


public class CalculateApplication {
public static void main(String[] args) {
ResultView.printOutResult(new AddCalculator(), InputView.inputString(new Scanner(System.in)));
Copy link
Contributor

Choose a reason for hiding this comment

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

이 한줄에서 입력, 계산, 출력 모든게 이루어지고있네요. 변수명을 잘짓는 이유가 가독성을 높이기 위함인 것 처럼, 2줄을 1줄로 줄이는 것, 코드라인 사이를 띄어쓰기 하는것, 1줄을 2줄로 늘리는 것 역시 가독성을 높이기 위함입니다.

return expression.split(separator);
}

private static boolean isBlankSpace(String inputString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is empty와 inputstring == " " 의 차이가 있나요?

}

private static boolean isContains(String expression, String[] separators) {
if (expression.contains(separators[COMMA])) return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

확장성이 걱정되네요, 만약 요구사항이 기본 separator가 , : ? 로 늘어나면 위에있는 new String[]{",", ":"}) 이 코드도 변경해야하고, splitString(expression, ",|:"); 이것도 변경하고 여기에있는 index도 수정해야겠네요.

또한 만약 인자값 separators가 {","} 만들어오면 index out of range 에러가 뜰수있습니다.


public class AddCalculator {
public static int calculate(String[] numbers){
return Arrays.stream(numbers).mapToInt(number -> Integer.parseInt(number)).sum();
Copy link

@csbsjy csbsjy Mar 4, 2020

Choose a reason for hiding this comment

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

stream 연산은 stream 대로 줄바꿈 해주는게 디버깅 하기 좋다고 하더라구용!
디버깅은 한줄씩 체크하니까 !

Suggested change
return Arrays.stream(numbers).mapToInt(number -> Integer.parseInt(number)).sum();
return Arrays.stream(numbers)
.mapToInt(number -> Integer.parseInt(number))
.sum();

혹시 parseInt 가 실패하면 어떻게되나요?


public static String[] makeNumbers(String inputString) {

if (isBlankSpace(inputString)) throw new RuntimeException();
Copy link

Choose a reason for hiding this comment

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

Suggested change
if (isBlankSpace(inputString)) throw new RuntimeException();
if (isBlankSpace(inputString)){
throw new RuntimeException();
}

가 더 가독성이 좋을 것 같아요!

Copy link
Member

Choose a reason for hiding this comment

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

여기에 RuntimeException은 최상위 Exception이니 다른 걸로 바꾸기로 !!

Copy link
Member

@pci2676 pci2676 left a comment

Choose a reason for hiding this comment

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

테스트 케이스가 적습니다! 조금 더 테스트를 추가해주세요!

Comment on lines +10 to +14

@Test
void calculate() {
assertThat(AddCalculator.calculate(new String[]{"1","2","3"})).isEqualTo(6);
}
Copy link
Member

Choose a reason for hiding this comment

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

@DisplayName을 이용해서 테스트의 의도를 먼저 드러내 주세요!

Comment on lines +29 to +31
if (!isContains(expression, new String[]{",", ":"})) {
throw new IllegalArgumentException();
}
Copy link
Member

Choose a reason for hiding this comment

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

isContains 가 여기 말고 는 쓰이지 않는 것같은데 인자를 new String[]{",", ":"} 이렇게 넘길 필요가 있을까요?!

}

private static boolean isBlankSpace(String inputString) {
if (inputString == null || inputString.isEmpty() || inputString == " ") {
Copy link
Member

Choose a reason for hiding this comment

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

inputString == " "로 공백을 캐치하려 한것 같은데 " " 공백이 더길어진다면 어떨까요?
trim()에 대해 알아보면 좋을것같아요~

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.

5 participants