Skip to content
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

Step1 - 문자열 덧셈 계산기 #815

Merged
merged 9 commits into from
Feb 7, 2025

Conversation

reversalSpring
Copy link

JUnit 5 학습 을 step 1 으로 브런치를 따서 이번 문자열 덧셈 계산기를 1-1로 만들어 푸시했습니다.

문자열 덧셈 계산기를 만들었습니다. 리뷰 부탁 드립니다.

@sihoony
Copy link

sihoony commented Jan 31, 2025

이전 커밋 이력과 함께 미션이 수행되었네요. 미션 수행을 위한 STEP을 확인해서 진행하시면 좋을 것 같아요~! 😄

Copy link

@sihoony sihoony left a comment

Choose a reason for hiding this comment

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

안녕하세요~! 준형님,
이번 미션을 잘 진행해주셨네요~! 👍
몇가지 코멘트를 남겼으니 확인주세요!!
고생하셨습니다~! 😄

String delimiter = "[,:]";
String numbers = text;

Matcher matcher = Pattern.compile("//(.)\n(.*)").matcher(text);
Copy link

Choose a reason for hiding this comment

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

Pattern을 캐싱해보면 어떨까요?
고정적이면서 생성 비용이 많이 드는 항목은 사전에 생성해둔다면 성능상 이점을 가져갈 수 있겠네요~! 😄

Comment on lines 26 to 28
if (number < 0) {
throw new RuntimeException("Negative numbers are not allowed: " + number);
}
Copy link

@sihoony sihoony Jan 31, 2025

Choose a reason for hiding this comment

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

0 미만에 대한 책임을 분리하기 위하여 VO를 활용해보면 어떨까요?


return sum;
}
}
Copy link

Choose a reason for hiding this comment

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

마지막은 개행으로 끝날 수 있도록 설정해보면 어떨까요~!?

Copy link

@sihoony sihoony left a comment

Choose a reason for hiding this comment

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

안녕하세요~! 준형님,
피드백 잘 반영해주셨네요. 👍
추가 코멘트를 남겼는데 코멘트와 관련하여 궁금하신 점은 DM을 남겨주세요~! 😄

assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> calculator.add("-1"));
}
}
Copy link

Choose a reason for hiding this comment

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

마지막 라인에 개행이 추가안된 부분들이 있네요~!

Comment on lines 27 to 30
int number = Integer.parseInt(token);
if (number < 0) {
throw new RuntimeException("Negative numbers are not allowed: " + number);
}
Copy link

Choose a reason for hiding this comment

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

Number라는 VO를 통해서 숫자를 관리해보면 어떨까요~!?
궁금하신 점은 DM으로 남겨주셔도 됩니다~! 😄

Copy link
Author

Choose a reason for hiding this comment

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

VO 로 만들어 넣겠습니다.

Copy link

@sihoony sihoony left a comment

Choose a reason for hiding this comment

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

안녕하세요~! 준형님,
피드백 잘 반영해 주셨네요~! 👍
적용해보시면 좋을 것 같아서 추가 코멘트를 남겼어요. 😄
즐거운 하루 되세요.

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;

class StringCalculatorTest {
Copy link

Choose a reason for hiding this comment

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

Number에 대한 TestCode를 분리해서 만들어보면 어떨까요~!? 😄

Copy link
Author

Choose a reason for hiding this comment

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

테스트 코드를 분리 하겠습니다~

@@ -0,0 +1,16 @@
package StringCalculator;

public class Number {
Copy link

Choose a reason for hiding this comment

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

Number 잘 만드셨네요~! 👍

Comment on lines 24 to 31
String[] tokens = numbers.split(delimiter);
int sum = 0;
for (String token : tokens) {
Number number = new Number(token);
sum += number.getValue();
}

return sum;
Copy link

Choose a reason for hiding this comment

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

일급컬렉션을 활용하여 작성해보면 어떨까요~!?
합산에 대한 책임 명확하게 분리될 것 같아요~!

Copy link
Author

Choose a reason for hiding this comment

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

일급 컬렉션을 만들어 분리 하였습니다.

oy-sihlee

This comment was marked as off-topic.

Copy link

@sihoony sihoony left a comment

Choose a reason for hiding this comment

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

안녕하세요~! 준형님,
피드백 잘 반영해 주셨네요~! 👍
다음 미션을 위해서 Merge하겠습니다.
고생하셨습니다~! 😄

assertThatExceptionOfType(RuntimeException.class)
.isThrownBy(() -> new Number("-1"));
}
}
Copy link

Choose a reason for hiding this comment

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

개행은 설정만 잡는다면 이후부터 신경쓸 포인트가 줄어들어요~! 😄

@sihoony sihoony merged commit 1ae8294 into next-step:reversalspring Feb 7, 2025
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.

3 participants