-
Notifications
You must be signed in to change notification settings - Fork 10
[숫자 야구 게임] 원영진 미션 제출합니다. #6
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
Conversation
|
""" Walkthrough변경사항은 게임의 기능 요구사항 및 입력/출력, 오류 처리 방법에 대한 구조적 개요를 추가합니다. 새로운 기능 함수들이 도입되었으며, 기존 함수들이 수정되어 랜덤 숫자 생성 범위, 중복 검사, 그리고 게임 루프 실행 방식이 개선되었습니다. 플레이어 입력 검증과 재시작/종료 옵션이 명확하게 구현되어 전체 게임 플로우가 안정적으로 작동하도록 업데이트되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant 플레이어 as Player
participant 메인 as Main
participant 게임루프 as GameLoop
플레이어->>메인: 게임 시작 요청
메인->>게임루프: 컴퓨터 숫자 생성 (make_computer_num)
Note over 게임루프: 게임 루프 실행 (loop_check)
플레이어->>게임루프: 숫자 입력 (player_input)
게임루프->>게임루프: 입력 검증 (validate_input)
게임루프->>게임루프: 숫자 비교 (check_input)
alt 정답일 경우
게임루프->>플레이어: 성공 메시지 출력
else
게임루프->>플레이어: 스트라이크 및 볼 결과 출력
end
게임루프->>메인: 게임 결과 반환
메인->>플레이어: 재시작/종료 요청 (restart_baseball)
alt 재시작 선택
플레이어->>메인: 재시작
else
플레이어->>메인: 종료
end
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (4)
src/baseball/main.py (2)
3-7: 성능 최적화 제안현재 구현은 정확하지만, 더 큰 배열에서의 성능을 위해 set을 사용하는 방법을 고려해보세요.
def same_num_check(check_array): # list에서 중복되는 수를 인식하는 기능 함수 - for i in check_array: - if check_array.count(i) != 1: - return 0 - return 1 + return 1 if len(set(check_array)) == len(check_array) else 0
9-11: 더 구체적인 오류 메시지 추가 제안ValueError를 발생시킬 때 구체적인 오류 원인을 메시지로 포함하면 사용자가 무엇이 잘못되었는지 더 쉽게 이해할 수 있습니다.
def validate_input(compare_array, want_len): if (len(compare_array) != want_len) or (0 in compare_array) or (same_num_check(compare_array) == 0): - raise ValueError + if len(compare_array) != want_len: + raise ValueError(f"입력된 숫자의 개수가 {want_len}개가 아닙니다") + if 0 in compare_array: + raise ValueError("0은 입력할 수 없습니다") + if same_num_check(compare_array) == 0: + raise ValueError("중복된 숫자가 있습니다").github/workflows/codecov.yml (1)
2-3: YAML 형식 개선trailing spaces를 제거하고 들여쓰기를 일관되게 유지하세요.
-on: - push +on: + push🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 2-2: trailing spaces
(trailing-spaces)
docs/README.md (1)
1-23: 문서 형식 개선 제안마크다운 형식을 개선하여 가독성을 높일 수 있습니다:
- 날짜 형식을 일관되게 유지
- 제목 단계를 명확하게 구분
- 코드 블록에 적절한 구문 강조 추가
-## 기능 추가 +# 변경 사항 + +## 기능 추가 1. make_computer_num() -> 1에서 9까지 서로 다른 임의의 수 3개 생성 기능 함수 추가 (2025/02/04) +> 1에서 9까지 서로 다른 임의의 수 3개 생성 기능 함수 추가 (2025-02-04) ... ->> random.sample(range(1, ~~9~~10), 3) +```python +random.sample(range(1, 10), 3) # 이전: range(1, 9) +```
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/codecov.yml(1 hunks)docs/README.md(1 hunks)src/baseball/main.py(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/codecov.yml
14-14: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🪛 YAMLlint (1.35.1)
.github/workflows/codecov.yml
[error] 2-2: trailing spaces
(trailing-spaces)
| def loop_check(com): # 1에서 3까지의 과정을 반복해 3개의 숫자를 모두 맞히면 게임이 종료되는 기능 함수 | ||
| get = player_input() | ||
| result_check_input = check_input(get, com) | ||
| print(result_check_input) | ||
| if result_check_input == "3스트라이크": # check_input()의 결과가 "3스트라이크"일 경우 게임을 종료하고, 아닐 경우 다시 loop_check() 수해 | ||
| print("3개의 숫자를 모두 맞히셨습니다! 게임 종료") | ||
| return 0 | ||
| else: | ||
| loop_check(com) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
재귀 호출 대신 while 루프 사용 권장
재귀 호출은 스택 오버플로우를 일으킬 수 있으므로, while 루프를 사용하는 것이 더 안전합니다.
def loop_check(com):
- get = player_input()
- result_check_input = check_input(get, com)
- print(result_check_input)
- if result_check_input == "3스트라이크":
- print("3개의 숫자를 모두 맞히셨습니다! 게임 종료")
- return 0
- else:
- loop_check(com)
+ while True:
+ get = player_input()
+ result_check_input = check_input(get, com)
+ print(result_check_input)
+ if result_check_input == "3스트라이크":
+ print("3개의 숫자를 모두 맞히셨습니다! 게임 종료")
+ return 0📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def loop_check(com): # 1에서 3까지의 과정을 반복해 3개의 숫자를 모두 맞히면 게임이 종료되는 기능 함수 | |
| get = player_input() | |
| result_check_input = check_input(get, com) | |
| print(result_check_input) | |
| if result_check_input == "3스트라이크": # check_input()의 결과가 "3스트라이크"일 경우 게임을 종료하고, 아닐 경우 다시 loop_check() 수해 | |
| print("3개의 숫자를 모두 맞히셨습니다! 게임 종료") | |
| return 0 | |
| else: | |
| loop_check(com) | |
| def loop_check(com): # 1에서 3까지의 과정을 반복해 3개의 숫자를 모두 맞히면 게임이 종료되는 기능 함수 | |
| while True: | |
| get = player_input() | |
| result_check_input = check_input(get, com) | |
| print(result_check_input) | |
| if result_check_input == "3스트라이크": | |
| print("3개의 숫자를 모두 맞히셨습니다! 게임 종료") | |
| return 0 |
src/baseball/main.py
Outdated
| def restart_baseball(): # 게임 종료 후 '1' 입력시 다시 시작, '2' 입력시 완전히 종료하는 기능 함수 | ||
| print("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.") | ||
| user_key = int(input()) | ||
| if user_key in [1, 2]: | ||
| return user_key | ||
| else: # 잘못된 값을 입력할 경우 'ValueError'를 발생 | ||
| raise ValueError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
입력 오류 처리 개선 필요
사용자가 숫자가 아닌 값을 입력할 경우 발생할 수 있는 ValueError를 처리해야 합니다.
def restart_baseball():
print("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.")
- user_key = int(input())
- if user_key in [1, 2]:
- return user_key
- else:
- raise ValueError
+ try:
+ user_key = int(input())
+ if user_key in [1, 2]:
+ return user_key
+ else:
+ raise ValueError("1 또는 2만 입력 가능합니다")
+ except ValueError:
+ raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def restart_baseball(): # 게임 종료 후 '1' 입력시 다시 시작, '2' 입력시 완전히 종료하는 기능 함수 | |
| print("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.") | |
| user_key = int(input()) | |
| if user_key in [1, 2]: | |
| return user_key | |
| else: # 잘못된 값을 입력할 경우 'ValueError'를 발생 | |
| raise ValueError | |
| def restart_baseball(): # 게임 종료 후 '1' 입력시 다시 시작, '2' 입력시 완전히 종료하는 기능 함수 | |
| print("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.") | |
| try: | |
| user_key = int(input()) | |
| if user_key in [1, 2]: | |
| return user_key | |
| else: | |
| raise ValueError("1 또는 2만 입력 가능합니다") | |
| except ValueError: | |
| raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") |
| - name: Set up Python | ||
| uses: actions/setup-python@v4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Python 버전 명시 필요
Python 버전을 명시하여 일관된 테스트 환경을 보장하세요.
- name: Set up Python
uses: actions/setup-python@v4
+ with:
+ python-version: '3.11'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' |
🧰 Tools
🪛 actionlint (1.7.4)
14-14: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/baseball/main.py (3)
3-7: 성능 개선을 위한 리팩토링 제안set을 사용하여 중복 검사를 더 효율적으로 수행할 수 있습니다.
-def same_num_check(check_array): # list에서 중복되는 수를 인식하는 기능 함수 - for i in check_array: - if check_array.count(i) != 1: - return 0 - return 1 +def same_num_check(check_array): # list에서 중복되는 수를 인식하는 기능 함수 + return 1 if len(set(check_array)) == len(check_array) else 0
26-44: 코드 간소화 제안결과 문자열 생성 로직을 더 간단하게 만들 수 있습니다.
def check_input(get, com): # 플레이어가 입력한 숫자에 대한 결과를 출력하는 함수 ball, strike = 0, 0 for i in range(0,3): if get[i] == com[i]: strike += 1 elif get[i] in com: ball += 1 else: continue - if strike == 3: - return "3스트라이크" - elif ball + strike == 0: - return "낫싱" - elif ball == 0: - return "{0}스트라이크".format(strike) - elif strike == 0: - return "{0}볼".format(ball) - else: - return "{0}볼 {1}스트라이크".format(ball, strike) + if ball + strike == 0: + return "낫싱" + result = [] + if ball > 0: + result.append(f"{ball}볼") + if strike > 0: + result.append(f"{strike}스트라이크") + return " ".join(result)
55-64: 예외 처리 패턴 개선 제안예외의 원인을 더 명확하게 추적할 수 있도록 "raise from" 패턴을 사용하는 것이 좋습니다.
def restart_baseball(): # 게임 종료 후 '1' 입력시 다시 시작, '2' 입력시 완전히 종료하는 기능 함수 print("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요.") try: user_key = int(input()) if user_key in [1, 2]: return user_key else: # 잘못된 값을 입력할 경우 'ValueError'를 발생 raise ValueError("1 또는 2만 입력 가능합니다") - except ValueError: - raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") + except ValueError as e: + raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") from e🧰 Tools
🪛 Ruff (0.8.2)
64-64: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
docs/README.md (1)
1-60: 마크다운 서식 개선 필요문서의 가독성을 높이기 위해 들여쓰기를 수정하는 것이 좋습니다.
- 순서 없는 목록의 들여쓰기를 2칸으로 통일
- 하위 목록은 상위 목록보다 2칸 더 들여쓰기
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
3-3: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/README.md(1 hunks)src/baseball/main.py(1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/README.md
3-3: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
🪛 Ruff (0.8.2)
src/baseball/main.py
64-64: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🔇 Additional comments (4)
src/baseball/main.py (4)
9-15: 구현이 잘 되었습니다!입력 유효성 검사가 명확하고 상세한 오류 메시지를 제공합니다.
17-19: 효율적인 구현입니다!random.sample을 사용하여 중복 없는 난수 생성을 보장합니다.
46-53: 이전 리뷰 의견이 잘 반영되었습니다!재귀 호출 대신 while 루프를 사용하여 스택 오버플로우 위험을 제거했습니다.
21-24: 🛠️ Refactor suggestion입력 오류 처리 개선 필요
숫자가 아닌 입력에 대한 예외 처리가 필요합니다.
def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수 - get_array = list(map(int, input("숫자를 입력해주세요 : "))) - validate_input(get_array, 3) - return get_array + try: + get_array = list(map(int, input("숫자를 입력해주세요 : "))) + validate_input(get_array, 3) + return get_array + except ValueError: + raise ValueError("숫자만 입력해주세요")Likely invalid or redundant comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
src/baseball/main.py (4)
3-7: 성능 최적화를 위한 set() 사용 제안현재 구현은 정확하지만, 리스트의 크기가 커질 경우 성능이 저하될 수 있습니다. set()을 사용하면 더 효율적으로 중복을 확인할 수 있습니다.
다음과 같이 수정하는 것을 제안합니다:
def same_num_check(check_array): # list에서 중복되는 수를 인식하는 기능 함수 - for i in check_array: - if check_array.count(i) != 1: - return 0 - return 1 + return 1 if len(set(check_array)) == len(check_array) else 0
17-19: 불필요한 주석 제거 제안"basecode" 주석은 코드의 이해에 도움이 되지 않으므로 제거하는 것이 좋습니다.
def make_computer_num(): # random 모듈을 사용하여 임의의 수 생성하는 함수 (요구사항) - computer = random.sample(range(1, 10), 3) # basecode + computer = random.sample(range(1, 10), 3) return computer
26-44: 불필요한 else-continue 블록 제거 제안33-34줄의 else-continue 블록은 불필요합니다. 제거해도 동일하게 동작합니다.
elif get[i] in com: ball += 1 - else: - continue
55-64: 예외 처리 개선 제안예외 처리가 잘 구현되어 있지만, 원본 예외를 유지하기 위해 예외 체이닝을 사용하는 것이 좋습니다.
try: user_key = int(input()) if user_key in [1, 2]: return user_key else: # 잘못된 값을 입력할 경우 'ValueError'를 발생 raise ValueError("1 또는 2만 입력 가능합니다") except ValueError: - raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") + raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") from None🧰 Tools
🪛 Ruff (0.8.2)
64-64: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
docs/README.md (1)
1-60: 마크다운 들여쓰기 형식 개선 필요문서의 내용은 잘 정리되어 있지만, 마크다운 리스트의 들여쓰기가 일관적이지 않습니다.
- 최상위 리스트는 2칸 들여쓰기
- 하위 리스트는 4칸 들여쓰기로 통일하는 것을 추천합니다.
예시:
## 기능 요구 사항 - - [X] 입력 기능 - - [X] 반복 입력, 1~9 서로다른 3자리의 수 (ex:123) + - [X] 입력 기능 + - [X] 반복 입력, 1~9 서로다른 3자리의 수 (ex:123)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
3-3: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
docs/README.md(1 hunks)src/baseball/main.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/baseball/main.py
64-64: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🪛 markdownlint-cli2 (0.17.2)
docs/README.md
3-3: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
🔇 Additional comments (2)
src/baseball/main.py (2)
9-15: 잘 구현된 입력 검증 로직입니다!명확한 에러 메시지와 함께 모든 필요한 검증을 수행하고 있습니다.
46-53: 이전 리뷰 의견이 잘 반영되었습니다!재귀 호출 대신 while 루프를 사용하여 스택 오버플로우 위험을 제거했습니다.
| def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수 | ||
| get_array = list(map(int, input("숫자를 입력해주세요 : "))) | ||
| validate_input(get_array, 3) | ||
| return get_array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
숫자가 아닌 입력에 대한 예외 처리 필요
현재 구현에서는 숫자가 아닌 값을 입력할 경우 명확하지 않은 에러가 발생할 수 있습니다.
다음과 같이 예외 처리를 추가하는 것을 제안합니다:
def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수
- get_array = list(map(int, input("숫자를 입력해주세요 : ")))
- validate_input(get_array, 3)
- return get_array
+ try:
+ get_array = list(map(int, input("숫자를 입력해주세요 : ")))
+ validate_input(get_array, 3)
+ return get_array
+ except ValueError:
+ raise ValueError("숫자만 입력해주세요")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수 | |
| get_array = list(map(int, input("숫자를 입력해주세요 : "))) | |
| validate_input(get_array, 3) | |
| return get_array | |
| def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수 | |
| try: | |
| get_array = list(map(int, input("숫자를 입력해주세요 : "))) | |
| validate_input(get_array, 3) | |
| return get_array | |
| except ValueError: | |
| raise ValueError("숫자만 입력해주세요") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/baseball/main.py (2)
3-7: 성능 최적화를 위한 set 사용 제안현재 구현은 작은 리스트에서는 잘 작동하지만, 더 큰 리스트를 처리할 때를 대비하여 set을 사용하면 성능을 개선할 수 있습니다.
def same_num_check(check_array): # list에서 중복되는 수를 인식하는 기능 함수 - for i in check_array: - if check_array.count(i) != 1: - return 0 - return 1 + return 1 if len(set(check_array)) == len(check_array) else 0
26-44: 코드 간소화 제안현재 구현은 정확하지만, 더 간결하게 작성할 수 있습니다.
def check_input(get, com): # 플레이어가 입력한 숫자에 대한 결과를 출력하는 함수 ball, strike = 0, 0 for i in range(0,3): if get[i] == com[i]: strike += 1 elif get[i] in com: ball += 1 - else: - continue - if strike == 3: - return "3스트라이크" - elif ball + strike == 0: - return "낫싱" - elif ball == 0: - return "{0}스트라이크".format(strike) - elif strike == 0: - return "{0}볼".format(ball) - else: - return "{0}볼 {1}스트라이크".format(ball, strike) + + if strike == 3: + return "3스트라이크" + return "낫싱" if ball + strike == 0 else \ + f"{strike}스트라이크" if ball == 0 else \ + f"{ball}볼" if strike == 0 else \ + f"{ball}볼 {strike}스트라이크".github/workflows/codecov.yml (1)
2-3: 불필요한 공백 제거 필요YAML 파일의 가독성을 위해 불필요한 공백을 제거해 주세요.
-on: - pull_request +on: + pull_request🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 2-2: trailing spaces
(trailing-spaces)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/codecov.yml(1 hunks)docs/README.md(1 hunks)src/baseball/main.py(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/codecov.yml
14-14: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🪛 YAMLlint (1.35.1)
.github/workflows/codecov.yml
[error] 2-2: trailing spaces
(trailing-spaces)
🪛 Ruff (0.8.2)
src/baseball/main.py
64-64: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🪛 markdownlint-cli2 (0.17.2)
docs/README.md
3-3: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
🔇 Additional comments (7)
src/baseball/main.py (5)
17-19: 구현이 깔끔하고 효율적입니다!
random.sample을 사용하여 중복 없는 난수를 생성하는 방식이 적절합니다.
21-24: 숫자가 아닌 입력에 대한 예외 처리가 필요합니다이전 리뷰 코멘트와 동일한 이슈가 여전히 존재합니다. 숫자가 아닌 입력에 대해 더 명확한 에러 메시지를 제공해야 합니다.
def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수 - get_array = list(map(int, input("숫자를 입력해주세요 : "))) - validate_input(get_array, 3) - return get_array + try: + get_array = list(map(int, input("숫자를 입력해주세요 : "))) + validate_input(get_array, 3) + return get_array + except ValueError as e: + if str(e): + raise ValueError(str(e)) + raise ValueError("숫자만 입력해주세요")
46-53: 재귀 호출을 while 루프로 변경한 것이 좋습니다!스택 오버플로우를 방지하기 위해 while 루프를 사용한 구현이 적절합니다.
55-64: 예외 처리가 잘 구현되었습니다!사용자 입력에 대한 예외 처리와 에러 메시지가 명확하게 구현되었습니다.
🧰 Tools
🪛 Ruff (0.8.2)
64-64: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
72-80: 게임 로직이 깔끔하게 구현되었습니다!게임 시작, 실행, 재시작 로직이 명확하게 구현되었습니다.
.github/workflows/codecov.yml (1)
13-14: Python 버전을 명시해 주세요일관된 테스트 환경을 보장하기 위해 Python 버전을 명시해야 합니다.
- name: Set up Python uses: actions/setup-python@v4 + with: + python-version: '3.11'🧰 Tools
🪛 actionlint (1.7.4)
14-14: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
docs/README.md (1)
1-60: 문서가 잘 작성되었습니다!기능 요구사항, 구현 내용, 오류 수정 사항이 명확하게 문서화되어 있습니다.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
3-3: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
| def validate_input(compare_array, want_len): # 잘못된 값을 입력한 경우 ValueError가 발생하여 프로그램을 종료하는 기능 함수 | ||
| if (len(compare_array) != want_len): # 플레이어가 입력한 값이 예상되는 값의 길이가 아니거나, 0이 포함되거나, 중복되는 수가 입력되어도 예외 처리 | ||
| raise ValueError("3개의 숫자를 입력해주세요.") | ||
| elif (0 in compare_array): | ||
| raise ValueError("1 ~ 9의 숫자만 입력해주세요.") | ||
| elif (same_num_check(compare_array) == 0): | ||
| raise ValueError("중복되는 수가 있습니다.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
입력값 범위 검증 추가 필요
1부터 9까지의 숫자만 허용하도록 명시적인 검증이 필요합니다.
def validate_input(compare_array, want_len): # 잘못된 값을 입력한 경우 ValueError가 발생하여 프로그램을 종료하는 기능 함수
if (len(compare_array) != want_len): # 플레이어가 입력한 값이 예상되는 값의 길이가 아니거나, 0이 포함되거나, 중복되는 수가 입력되어도 예외 처리
raise ValueError("3개의 숫자를 입력해주세요.")
elif (0 in compare_array):
raise ValueError("1 ~ 9의 숫자만 입력해주세요.")
+ elif any(num > 9 for num in compare_array):
+ raise ValueError("1 ~ 9의 숫자만 입력해주세요.")
elif (same_num_check(compare_array) == 0):
raise ValueError("중복되는 수가 있습니다.")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| def validate_input(compare_array, want_len): # 잘못된 값을 입력한 경우 ValueError가 발생하여 프로그램을 종료하는 기능 함수 | |
| if (len(compare_array) != want_len): # 플레이어가 입력한 값이 예상되는 값의 길이가 아니거나, 0이 포함되거나, 중복되는 수가 입력되어도 예외 처리 | |
| raise ValueError("3개의 숫자를 입력해주세요.") | |
| elif (0 in compare_array): | |
| raise ValueError("1 ~ 9의 숫자만 입력해주세요.") | |
| elif (same_num_check(compare_array) == 0): | |
| raise ValueError("중복되는 수가 있습니다.") | |
| def validate_input(compare_array, want_len): # 잘못된 값을 입력한 경우 ValueError가 발생하여 프로그램을 종료하는 기능 함수 | |
| if (len(compare_array) != want_len): # 플레이어가 입력한 값이 예상되는 값의 길이가 아니거나, 0이 포함되거나, 중복되는 수가 입력되어도 예외 처리 | |
| raise ValueError("3개의 숫자를 입력해주세요.") | |
| elif (0 in compare_array): | |
| raise ValueError("1 ~ 9의 숫자만 입력해주세요.") | |
| elif any(num > 9 for num in compare_array): | |
| raise ValueError("1 ~ 9의 숫자만 입력해주세요.") | |
| elif (same_num_check(compare_array) == 0): | |
| raise ValueError("중복되는 수가 있습니다.") |
…s when all 3 numbers are guessed correctly
…and completely quit when you input '2'
…d the program terminates
…ranges from 1 to 8 have been corrected so that 1 to 9 operates normally
…ranges from 1 to 8 have been corrected so that 1 to 9 operates normally
… returns immediately has been modified to check for duplicates in the entire array.
기존 loop_check()에서 재귀 호출을 이용해 게임을 진행해왔던 방식을 while 루프로 변경 (스택 오버플로우 방지) 기존 validate_input()에서 ValueError 발생 시 에러 메시지 추가 (입력 타입, 입력 길이, 중복 유무 3가지로 나눠 에러 메시지 출력)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (5)
src/baseball/main.py (3)
3-7: 성능 최적화를 위한 set 사용 제안현재 구현은 정확하지만, 리스트의 크기가 커질 경우 성능이 저하될 수 있습니다. set을 사용하면 더 효율적으로 구현할 수 있습니다.
def same_num_check(check_array): # list에서 중복되는 수를 인식하는 기능 함수 - for i in check_array: - if check_array.count(i) != 1: - return 0 - return 1 + return 1 if len(set(check_array)) == len(check_array) else 0
26-44: 불필요한 else-continue 블록 제거코드를 더 간결하게 만들기 위해 불필요한 else-continue 블록을 제거할 수 있습니다.
def check_input(get, com): # 플레이어가 입력한 숫자에 대한 결과를 출력하는 함수 ball, strike = 0, 0 for i in range(0,3): if get[i] == com[i]: strike += 1 elif get[i] in com: ball += 1 - else: - continue
55-64: 예외 체이닝 구현 필요예외 처리 시 원인이 되는 예외를 연결하여 디버깅을 용이하게 해야 합니다.
try: user_key = int(input()) if user_key in [1, 2]: return user_key else: # 잘못된 값을 입력할 경우 'ValueError'를 발생 raise ValueError("1 또는 2만 입력 가능합니다") - except ValueError: - raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") + except ValueError as err: + raise ValueError("올바른 숫자를 입력해주세요 (1 또는 2)") from err🧰 Tools
🪛 Ruff (0.8.2)
64-64: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
.github/workflows/codecov.yml (1)
2-3: 불필요한 공백 제거YAML 파일의 가독성을 위해 불필요한 공백을 제거하세요.
-on: +on: pull_request🧰 Tools
🪛 YAMLlint (1.35.1)
[error] 2-2: trailing spaces
(trailing-spaces)
docs/README.md (1)
1-60: 마크다운 리스트 들여쓰기 수정 필요마크다운 문서의 가독성을 높이기 위해 리스트 들여쓰기를 수정하세요.
- 상위 리스트는 2칸 들여쓰기
- 하위 리스트는 4칸 들여쓰기로 통일
예시:
## 기능 요구 사항 - 입력 기능 - 반복 입력, 1~9 서로다른 3자리의 수 (ex:123) - 게임이 끝난 경우 재시작/종료를 선택하는 1과 2 중 하나의 수🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
3-3: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8(MD007, ul-indent)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/codecov.yml(1 hunks)docs/README.md(1 hunks)src/baseball/main.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
src/baseball/main.py
64-64: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
🪛 markdownlint-cli2 (0.17.2)
docs/README.md
3-3: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
4-4: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
7-7: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
8-8: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
9-9: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
10-10: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
11-11: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
12-12: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
13-13: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
16-16: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
17-17: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
20-20: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
21-21: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
24-24: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
25-25: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
26-26: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
27-27: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
28-28: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
29-29: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
30-30: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
31-31: Unordered list indentation
Expected: 4; Actual: 8
(MD007, ul-indent)
🪛 actionlint (1.7.4)
.github/workflows/codecov.yml
14-14: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🪛 YAMLlint (1.35.1)
.github/workflows/codecov.yml
[error] 2-2: trailing spaces
(trailing-spaces)
🔇 Additional comments (5)
src/baseball/main.py (4)
9-15: 입력값 범위 검증 추가 필요1부터 9까지의 숫자만 허용하도록 명시적인 검증이 필요합니다.
def validate_input(compare_array, want_len): # 잘못된 값을 입력한 경우 ValueError가 발생하여 프로그램을 종료하는 기능 함수 if (len(compare_array) != want_len): # 플레이어가 입력한 값이 예상되는 값의 길이가 아니거나, 0이 포함되거나, 중복되는 수가 입력되어도 예외 처리 raise ValueError("3개의 숫자를 입력해주세요.") elif (0 in compare_array): raise ValueError("1 ~ 9의 숫자만 입력해주세요.") + elif any(num > 9 for num in compare_array): + raise ValueError("1 ~ 9의 숫자만 입력해주세요.") elif (same_num_check(compare_array) == 0): raise ValueError("중복되는 수가 있습니다.")
21-24: 숫자가 아닌 입력에 대한 예외 처리 필요현재 구현에서는 숫자가 아닌 값을 입력할 경우 명확하지 않은 에러가 발생할 수 있습니다.
def player_input(): # 플레이어에게 3개의 숫자 입력 받는 기능 함수 - get_array = list(map(int, input("숫자를 입력해주세요 : "))) - validate_input(get_array, 3) - return get_array + try: + get_array = list(map(int, input("숫자를 입력해주세요 : "))) + validate_input(get_array, 3) + return get_array + except ValueError as err: + raise ValueError("숫자만 입력해주세요") from err
46-53: 구현이 적절합니다!재귀 호출 대신 while 루프를 사용하여 스택 오버플로우 문제를 방지했습니다.
72-80: 구현이 적절합니다!게임의 메인 로직이 명확하고 잘 구조화되어 있습니다.
.github/workflows/codecov.yml (1)
13-14: Python 버전 명시 필요Python 버전을 명시하여 일관된 테스트 환경을 보장하세요.
- name: Set up Python uses: actions/setup-python@v4 + with: + python-version: '3.11'🧰 Tools
🪛 actionlint (1.7.4)
14-14: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
예외에서 테스트되지 않은 테스트 케이스 추가 입력값 경우의 수에서 부족한 테스트 케이스 추가
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/test_main.py (1)
23-26: 중첩된 with 문을 하나로 합치면 어떨까요?코드의 가독성을 높이기 위해 중첩된 with 문을 하나의 with 문으로 결합하는 것을 제안드립니다.
다음과 같이 수정해보세요:
- with pytest.raises(ValueError): - # 잘못된 입력 처리 - with patch('builtins.input', side_effect=["1234", "012", "233", "3", "ㄱ"]): - main() + # 잘못된 입력 처리 + with pytest.raises(ValueError), \ + patch('builtins.input', side_effect=["1234", "012", "233", "3", "ㄱ"]): + main()🧰 Tools
🪛 Ruff (0.8.2)
23-25: Use a single
withstatement with multiple contexts instead of nestedwithstatements(SIM117)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/test_main.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
tests/test_main.py
23-25: Use a single with statement with multiple contexts instead of nested with statements
(SIM117)
🔇 Additional comments (2)
tests/test_main.py (2)
11-11: 테스트 케이스가 잘 보완되었습니다!게임의 다양한 상태와 흐름을 검증하도록 테스트가 확장되었습니다.
Also applies to: 18-18
25-25: 예외 처리 테스트가 더욱 견고해졌습니다!다양한 유형의 잘못된 입력(4자리 숫자, 0으로 시작하는 숫자, 중복된 숫자, 한 자리 숫자, 한글)에 대한 검증이 추가되었습니다.
🧰 Tools
🪛 Ruff (0.8.2)
23-25: Use a single
withstatement with multiple contexts instead of nestedwithstatements(SIM117)
…lue Error occurs and the program terminates
Summary by CodeRabbit