solve problem 01.calculator by seoyoung#1
Open
sss20young wants to merge 2 commits into
Open
Conversation
joo-pe
suggested changes
Aug 13, 2021
| if (st.hasMoreTokens()) | ||
| operand = stringToInteger(st.nextToken()); | ||
|
|
||
| if (operator == '+') |
There was a problem hiding this comment.
public static final String ADD = "+";
이런식으로 상단에 상수처리 할 수 있습니다.
|
|
||
| public static void main(String[] args) throws IOException { | ||
| try { | ||
| br = new BufferedReader(new InputStreamReader(System.in)); |
Member
Author
There was a problem hiding this comment.
과거 알고리즘 문제를 풀 때,
Scanner의 입력의 제한으로 인해 BufferedReader를 사용했던 기억이 있어서 해당 클래스를 사용했습니다.
| if (operator == '/') | ||
| result = divide(result, operand); | ||
| } | ||
|
|
There was a problem hiding this comment.
사칙연산에 있는 문자가 없다면
throw new IllegalArgumentException("사칙연산 문자가 아닙니다");
이런식으로 처리할 수 있겠네요
| @Test | ||
| void testStringToChar() { | ||
| // TODO: 사칙연산 | ||
| assertThatIllegalArgumentException().isThrownBy(() -> { |
There was a problem hiding this comment.
아래와 같은 형식으로 할수 있어요
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(
() -> {
calculator.judge(str);
}
).withMessageMatching("문자열이 비어있습니다.");
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calculator.java & CalculatorTest.java
[ 문제점 ]
현재까지 리뷰 부탁드리겠습니다.