Skip to content

Hey0140#2

Open
Hey0140 wants to merge 2 commits into
Java-JavaScript-Language-Stuty:mainfrom
Hey0140:hey0140
Open

Hey0140#2
Hey0140 wants to merge 2 commits into
Java-JavaScript-Language-Stuty:mainfrom
Hey0140:hey0140

Conversation

@Hey0140

@Hey0140 Hey0140 commented Feb 6, 2025

Copy link
Copy Markdown

calculator 기능 구현 및 test 추가

Hey0140 added 2 commits February 6, 2025 13:35
give information about code
add feature calculator
add calculator test

@moongua404 moongua404 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

되게 깔끔하고 간결한 코드를 짜신 것 같아요! 첫 주차인데도 정규형을 적극적으로 활용하셔서 더 그런 것 같아요. 1주차 미션도 수고 많으셨습니다ㅎㅎ

assertSimpleTest(() ->
assertThatThrownBy(() -> runException("//#\\n0#30"))
.isInstanceOf(IllegalArgumentException.class)
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

반복되는 테스트는 Parameterized Test 등으로 처리할 수 있어요!

String patternString = "^(?://(.{1})\\\\n(.*)|(?!//).*)$";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(string);
boolean isContain = matcher.matches();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

정규표현식을 씀에도 함수 분리가 안돼서 불필요하게 필드가 낭비되는 것 같아요

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

동의합니다.

throw new IllegalArgumentException("Not in rule. Can't caculate this expression");
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

주석에 설명적인 부분은 README.md에 정리하고 흐름적인 부분은 함수 분리로 함수명을 통해 전달하면 좋을 것 같아요

String[] splitExpression = expression.split(delimiter);
int sum = 0;
//소수를 표현하기 위한 .이 있으면 소수가 아니라 구분자로 인식될 것이기에 소수는 없다고 생각해도 된다.
for (int i =0; i < splitExpression.length; i++){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for 문 별다른 이유가 없다면 인덱스 접근보다 원소로 접근하는게 효율적일 것 같아요!

int sum = 0;
//소수를 표현하기 위한 .이 있으면 소수가 아니라 구분자로 인식될 것이기에 소수는 없다고 생각해도 된다.
for (int i =0; i < splitExpression.length; i++){
if (!splitExpression[i].matches("^[1-9][0-9]*$")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

현재 splitExpression[i].matches("^[1-9][0-9]*$")로 숫자를 검증하고 있는데,
매번 정규표현식을 컴파일하는 것보다 숫자 검증을 위한 정규표현식을 별도의 메서드로 분리하는건 어떤가요..?

String patternString = "^(?://(.{1})\\\\n(.*)|(?!//).*)$";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(string);
boolean isContain = matcher.matches();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pattern이랑 matcher라는걸 방금 알았어요 ㄷㄷ 저는 코드로 하나하나 다짰는데 너무 쉽고 간편한 방법이 있었네요

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