Open
Conversation
Hyeon9mak
requested changes
Dec 4, 2024
Member
Hyeon9mak
left a comment
There was a problem hiding this comment.
안녕하세요 도희님! 2단계도 잘 진행해주셨습니다.
간결하게 잘 진행해주셔서 코멘트 드릴게 많지 않은데요~
아주 간단한 코멘트만 남겨보았으니 확인해주세요 😄
궁금하신 점 편하게 질문주세요~
Comment on lines
+5
to
+22
| 기본 연산 테스트 | ||
|
|
||
| - [x] 덧셈: "2 + 3" = 5 | ||
| - [x] 뺄셈: "5 - 3" = 2 | ||
| - [x] 곱셈: "4 * 3" = 12 | ||
| - [x] 나눗셈: "8 / 2" = 4 | ||
|
|
||
| 예외 처리 테스트 | ||
|
|
||
| - [x] null 입력 처리 | ||
| - [x] 빈 문자열 입력 처리 | ||
| - [x] 잘못된 연산자 입력 처리 ("2 @ 3") | ||
|
|
||
| 복합 연산 테스트 | ||
|
|
||
| - [x] 두 개의 연산: "2 + 3 * 4" = 20 | ||
| - [x] 세 개의 연산: "2 + 3 * 4 / 2" = 10 | ||
| - [x] 동일 우선순위 연산: "1 + 2 + 3" = 6 No newline at end of file |
Comment on lines
+41
to
+53
| private fun performOperation(a: Int, operator: String, b: Int): Int { | ||
| return when (operator) { | ||
| "+" -> a + b | ||
| "-" -> a - b | ||
| "*" -> a * b | ||
| "/" -> if (b != 0) a / b else throw IllegalArgumentException("0으로 나눌 수 없습니다.") | ||
| else -> throw IllegalArgumentException("지원하지 않는 연산자입니다.") | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| private val validOperators = setOf("+", "-", "*", "/") | ||
| } |
Member
There was a problem hiding this comment.
0으로 나누기 불가하다는 예외처리까지 👍
사칙연산 기호를 정적으로 관리하고 싶다는 니즈가 느껴지는데요,
이를 enum class 를 활용하여 따로 관리해보는 건 어떨까요?
Comment on lines
+11
to
+20
| var i = 1 | ||
| while (i < tokens.size - 1) { | ||
| val operator = tokens[i] | ||
| val number = tokens[i + 1].toInt() | ||
|
|
||
| result = performOperation(result, operator, number) | ||
| i += 2 | ||
| } | ||
|
|
||
| return result |
Member
There was a problem hiding this comment.
while 대신 for 문을 사용해도 충분해보이는걸요? 😉
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.
작업내용