-
Notifications
You must be signed in to change notification settings - Fork 5
[로또] 김지성 미션 제출합니다. #3
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
base: main
Are you sure you want to change the base?
Conversation
Walkthrough이번 변경 사항은 로또 게임 프로젝트의 기능 및 문서 구성을 전반적으로 개선하는 데 초점을 맞춥니다. README와 문서 파일에는 게임의 구현 기능과 예외 처리, 입력 및 당첨 번호 검증, 티켓 발행, 결과 및 수익률 계산 과정이 상세하게 기술되었습니다. 코드 측면에서는 Changes
Sequence Diagram(s)sequenceDiagram
participant U as 사용자
participant M as 메인 함수
participant V as 입력 검증기
participant L as 로또 시스템
participant E as 평가 프로세스
U->>M: 구매 금액 입력
M->>V: check_amount() 호출
V-->>M: 유효한 금액 반환
M->>L: 로또 티켓 생성 (generate_randomlotto)
M->>U: 티켓 정보 출력
U->>M: 당첨 번호 및 보너스 번호 입력
M->>V: prompt_winning_numbers(), prompt_bonus_number() 호출
V-->>M: 검증된 번호 반환
M->>E: evaluate_tickets() 호출
E-->>M: 결과 및 총 상금 반환
M->>U: 최종 결과 및 수익률 출력
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 (
|
Codecov ReportAttention: Patch coverage is
|
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: 2
🧹 Nitpick comments (4)
src/lotto/lotto.py (2)
103-106
: 조건 단순화 권장
_is_valid_bonus
메서드 내부에서return True
/False
전환을 더 간결하게 표현할 수 있습니다.
Ruff가 제안한 대로 조건식을 단일return
으로 처리하면 가독성이 향상됩니다.다음과 같은 코드 변경을 고려해 보세요:
-def _is_valid_bonus(bonus, numbers): - if bonus in numbers or not (1 <= bonus <= 45): - return False - return True +def _is_valid_bonus(bonus, numbers): + return not (bonus in numbers or not 1 <= bonus <= 45)🧰 Tools
🪛 Ruff (0.8.2)
103-105: Return the condition
not (bonus in numbers or not 1 <= bonus <= 45)
directlyReplace with
return not (bonus in numbers or not 1 <= bonus <= 45)
(SIM103)
🪛 GitHub Actions: Check Indentation Depth
[warning] 103-103: Unnecessary parens after 'not' keyword (superfluous-parens)
21-22
: 不要한 빈 줄 및 공백 정리 필요PEP8 검사에서 여러 빈 줄(2줄 이상)과 트레일링 공백이 감지되었습니다. 불필요한 빈 줄 수를 줄이고, 트레일링 공백을 제거하여 코드를 정돈하시기 바랍니다.
Also applies to: 35-37, 47-48, 52-53, 57-58, 64-65, 75-76, 83-84, 92-93, 100-101, 107-108, 122-123, 129-130, 138-139
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[warning] 21-21: blank line contains whitespace
[error] 22-22: too many blank lines (2)
🪛 GitHub Actions: Check Indentation Depth
[warning] 21-21: Trailing whitespace (trailing-whitespace)
src/lotto/main.py (2)
18-18
: 긴 줄 분할 권장PEP8 기준 한 줄 최대 길이(예: 79자)를 초과한 코드가 발견되었습니다(18번 줄, 24번 줄).
코드를 가독성 높게 유지하려면 적절한 위치에서 줄을 분할하도록 수정하세요.Also applies to: 24-24
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 18-18: line too long (88 > 79 characters)
4-4
: 불필요한 빈 줄 조정너무 많은 빈 줄 사용으로 인해 코드 가독성이 저하될 수 있습니다. 1줄 이상의 공백이 필요한지 다시 확인하시고, 불필요한 공백은 제거해 주세요.
Also applies to: 6-7, 8-8, 22-22
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[warning] 4-4: blank line contains whitespace
🪛 GitHub Actions: Check Indentation Depth
[warning] 4-4: Trailing whitespace (trailing-whitespace)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.github/workflows/check-no-external-libs.yml
(1 hunks)README.md
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check PEP8 Style
src/lotto/main.py
[error] 3-3: expected 2 blank lines, found 1
[warning] 4-4: blank line contains whitespace
[warning] 6-6: blank line contains whitespace
[warning] 7-7: blank line contains whitespace
[error] 8-8: too many blank lines (2)
[error] 14-14: inline comment should start with '# '
[error] 18-18: line too long (88 > 79 characters)
[warning] 22-22: blank line contains whitespace
[error] 24-24: line too long (82 > 79 characters)
[error] 30-30: expected 2 blank lines after class or function definition, found 1
src/lotto/lotto.py
[error] 4-4: expected 2 blank lines, found 1
[warning] 7-7: blank line contains whitespace
[warning] 21-21: blank line contains whitespace
[error] 22-22: too many blank lines (2)
[warning] 36-36: blank line contains whitespace
[error] 37-37: too many blank lines (2)
[warning] 42-42: blank line contains whitespace
[error] 44-44: line too long (88 > 79 characters)
[warning] 47-47: blank line contains whitespace
[error] 48-48: too many blank lines (2)
[warning] 52-52: blank line contains whitespace
[error] 53-53: too many blank lines (2)
[warning] 57-57: blank line contains whitespace
[error] 58-58: too many blank lines (2)
[warning] 64-64: blank line contains whitespace
[error] 65-65: too many blank lines (2)
[error] 69-69: line too long (108 > 79 characters)
[warning] 75-75: blank line contains whitespace
[error] 76-76: too many blank lines (2)
[warning] 83-83: blank line contains whitespace
[error] 84-84: too many blank lines (2)
[warning] 92-92: blank line contains whitespace
[error] 93-93: too many blank lines (2)
[warning] 100-100: blank line contains whitespace
[error] 101-101: too many blank lines (2)
[warning] 107-107: blank line contains whitespace
[error] 108-108: too many blank lines (2)
[warning] 122-122: blank line contains whitespace
[error] 123-123: too many blank lines (2)
[warning] 129-129: blank line contains whitespace
[error] 130-130: too many blank lines (2)
[warning] 138-138: blank line contains whitespace
[error] 139-139: too many blank lines (2)
[warning] 157-157: blank line at end of file
🪛 GitHub Actions: Check Indentation Depth
src/lotto/main.py
[warning] 4-4: Trailing whitespace (trailing-whitespace)
[warning] 6-6: Trailing whitespace (trailing-whitespace)
[warning] 7-7: Trailing whitespace (trailing-whitespace)
[warning] 22-22: Trailing whitespace (trailing-whitespace)
src/lotto/lotto.py
[warning] 7-7: Trailing whitespace (trailing-whitespace)
[warning] 21-21: Trailing whitespace (trailing-whitespace)
[warning] 36-36: Trailing whitespace (trailing-whitespace)
[warning] 42-42: Trailing whitespace (trailing-whitespace)
[warning] 47-47: Trailing whitespace (trailing-whitespace)
[warning] 52-52: Trailing whitespace (trailing-whitespace)
[warning] 57-57: Trailing whitespace (trailing-whitespace)
[warning] 64-64: Trailing whitespace (trailing-whitespace)
[warning] 69-69: Line too long (108/100) (line-too-long)
[warning] 75-75: Trailing whitespace (trailing-whitespace)
[warning] 83-83: Trailing whitespace (trailing-whitespace)
[warning] 92-92: Trailing whitespace (trailing-whitespace)
[warning] 100-100: Trailing whitespace (trailing-whitespace)
[warning] 103-103: Unnecessary parens after 'not' keyword (superfluous-parens)
[warning] 107-107: Trailing whitespace (trailing-whitespace)
[warning] 122-122: Trailing whitespace (trailing-whitespace)
[warning] 129-129: Trailing whitespace (trailing-whitespace)
[warning] 138-138: Trailing whitespace (trailing-whitespace)
[warning] 157-157: Trailing newlines (trailing-newlines)
🪛 Ruff (0.8.2)
src/lotto/lotto.py
103-105: Return the condition not (bonus in numbers or not 1 <= bonus <= 45)
directly
Replace with return not (bonus in numbers or not 1 <= bonus <= 45)
(SIM103)
🪛 GitHub Actions: Check No Else Keyword
src/lotto/lotto.py
[error] 1-1: 'else' keyword is not allowed!
🪛 GitHub Actions: Check Logic Separation
src/lotto/lotto.py
[error] 1-1: UI logic (print or input) should not be in src/lotto/lotto.py!
🪛 GitHub Actions: Check No External Libraries
src/lotto/lotto.py
[error] 1-1: External library detected: typing in src/lotto/lotto.py
🪛 GitHub Actions: Check No Ternary Operator
src/lotto/lotto.py
[error] 1-1: Ternary operators are not allowed!
🔇 Additional comments (2)
README.md (1)
1-46
: 소수점 자리수 명시 확인 요청문서에서는 “소수점 둘째 자리에서 반올림”을 명시하고 있으나, 실제 구현(
print_results
메서드)은 소수점 첫째 자리(:.1f
)만 출력하도록 설정되어 있습니다. 문서와 코드가 일치하도록 조정하거나, 문서와 코드 중 어느 쪽이 맞는지 확인 후 통일해 주세요..github/workflows/check-no-external-libs.yml (1)
23-23
:enum
모듈 추가가 적절해 보입니다.복권 게임의 상태나 결과를 열거형으로 관리하기 위해
enum
모듈을 허용 목록에 추가한 것이 타당합니다. 이는 코드의 가독성과 유지보수성을 향상시킬 것으로 예상됩니다.
src/lotto/lotto.py
Outdated
amount = input("로또 구입 금액을 입력하세요: ") | ||
Lotto._validate_amount(amount) | ||
|
||
amount = int(amount) | ||
lotto_count = amount // 1000 | ||
print(f"{lotto_count}개의 로또를 구입합니다.") | ||
return lotto_count |
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
UI 로직 분리 권장
src/lotto/lotto.py
내에서 input()
과 print()
를 직접 사용하는 로직(UI 로직)이 다수 발견됩니다. 파이프라인 정책(예: "Check Logic Separation")에 따라 UI 로직을 별도의 모듈(예: main
함수나 전용 CLI/Interface 모듈)로 분리하는 것을 권장합니다. 이를 통해 핵심 로또 로직과 사용자 입력·출력 처리 로직을 명확하게 분리하여 유지보수를 용이하게 할 수 있습니다.
Also applies to: 69-74, 96-99
src/lotto/lotto.py
Outdated
+ results["5_bonus"] * 30000000 | ||
+ results[6] * 2000000000 | ||
) | ||
profit_ratio = (total_prize / total_cost) * 100 if total_cost else 0 |
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.
삼항 연산자 사용 금지 규칙 위반
현재 파이프라인에서 삼항 연산자(if ... else ...
) 사용을 허용하지 않습니다. 다음과 같이 if
블록을 사용하여 리팩토링하세요.
- profit_ratio = (total_prize / total_cost) * 100 if total_cost else 0
+ if total_cost == 0:
+ profit_ratio = 0
+ else:
+ profit_ratio = (total_prize / total_cost) * 100
📝 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.
profit_ratio = (total_prize / total_cost) * 100 if total_cost else 0 | |
if total_cost == 0: | |
profit_ratio = 0 | |
else: | |
profit_ratio = (total_prize / total_cost) * 100 |
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/lotto/lotto.py (1)
43-51
: 검증 로직 개선 제안오류 메시지를 클래스 상수로 분리하고 각각의 검증을 개별 메서드로 분리하면 유지보수가 더 용이해질 것 같습니다.
class Lotto(): + LENGTH_ERROR = "로또 번호는 정확히 6개여야 합니다." + DUPLICATE_ERROR = "로또 번호에 중복이 있어서는 안 됩니다." + RANGE_ERROR = "로또 번호는 1부터 45 사이여야 합니다." + + def _validate_length(self, numbers): + if len(numbers) != 6: + raise ValueError(self.LENGTH_ERROR) + + def _validate_duplicates(self, numbers): + if len(set(numbers)) != 6: + raise ValueError(self.DUPLICATE_ERROR) + + def _validate_range(self, numbers): + if not all(1 <= num <= 45 for num in numbers): + raise ValueError(self.RANGE_ERROR) + def _validate(self, numbers: list[int]): - if len(numbers) != 6: - raise ValueError("로또 번호는 정확히 6개여야 합니다.") - if len(set(numbers)) != 6: - raise ValueError("로또 번호에 중복이 있어서는 안 됩니다.") - if not all(1 <= num <= 45 for num in numbers): - raise ValueError("로또 번호는 1부터 45 사이여야 합니다.") + self._validate_length(numbers) + self._validate_duplicates(numbers) + self._validate_range(numbers)src/lotto/main.py (2)
32-38
: 검증 로직 중복 제거 필요
_validate_numbers
함수의 검증 로직이Lotto
클래스의_validate
메서드와 중복됩니다. 검증 로직을Lotto
클래스로 통합하는 것이 좋겠습니다.
97-111
: 상수 정의 추가 제안수익률 계산에 사용되는 매직 넘버(1000)와 소수점 자리수(2)를 상수로 정의하면 코드의 의도가 더 명확해질 것 같습니다.
+LOTTO_PRICE = 1000 +PROFIT_DECIMAL_PLACES = 2 + def print_result(result, totalprize, amount): - profit_percentage = round((totalprize / (amount * 1000)) * 100, 2) + profit_percentage = round((totalprize / (amount * LOTTO_PRICE)) * 100, PROFIT_DECIMAL_PLACES)pytest.ini (1)
3-4
: 마커 설명 개선 제안커스텀 마커의 사용 예시와 적용 방법에 대한 주석을 추가하면 다른 개발자들이 더 쉽게 이해하고 활용할 수 있을 것 같습니다.
markers = - custom_name: 테스트 설명을 위한 커스텀 마커 + custom_name: 테스트 설명을 위한 커스텀 마커 + # 사용 예시: + # @pytest.mark.custom_name("로또 번호 유효성 검사") + # def test_validate_lotto_numbers(): + # ...
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
pytest.ini
(1 hunks)src/lotto/__init__.py
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)tests/lotto/test_main.py
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- tests/lotto/test_main.py
- src/lotto/init.py
🔇 Additional comments (1)
src/lotto/lotto.py (1)
5-33
: 잘 구현된 Rank 열거형 클래스입니다!열거형을 사용하여 로또 순위를 명확하게 정의했고, 상금과 매칭 조건이 잘 구조화되어 있습니다.
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 (2)
src/lotto/main.py (2)
53-66
: 당첨 결과 평가 로직에 대한 최적화 제안현재 구현은 잘 되어 있지만, 약간의 최적화가 가능합니다.
다음과 같이 수정해보세요:
def evaluate_tickets(tickets, winning_numbers, bonus_num): results = {rank: 0 for rank in Rank} total_prize = 0 + winning_set = set(winning_numbers) # 한 번만 set으로 변환 for ticket in tickets: ticket_numbers = ticket.get_numbers() - match_count = len(set(winning_numbers) & set(ticket_numbers)) + match_count = len(winning_set & set(ticket_numbers)) bonus = bonus_num in ticket_numbers rank = Rank.get_rank(match_count, bonus) results[rank] += 1 total_prize += rank.prize return results, total_prize
68-82
: 결과 출력 로직 개선 제안현재 구현은 정확하지만, 더 간결하게 작성할 수 있습니다.
다음과 같이 수정해보세요:
def print_results(results, total_prize, amount): profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) print("\n당첨 통계") print("---") for rank in Rank: - if rank == Rank.SECOND: - print(f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " - f"{results[rank]}개") - - if rank != Rank.NONE and rank != Rank.SECOND: - print(f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " - f"{results[rank]}개") + if rank == Rank.NONE: + continue + message = (f"{rank.match_cnt}개 일치" + f"{', 보너스 볼 일치' if rank == Rank.SECOND else ''}" + f" ({rank.prize:,}원) - {results[rank]}개") + print(message) print(f"총 수익률은 {profit_percentage}%입니다.")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lotto/main.py
(1 hunks)
🔇 Additional comments (6)
src/lotto/main.py (6)
3-10
: 구매 금액 검증 로직이 잘 구현되었습니다!입력값 검증과 에러 메시지가 명확하게 구현되어 있습니다.
22-25
: 티켓 출력 구현이 깔끔합니다!
__str__()
메서드를 활용한 출력 방식이 적절합니다.
27-34
: 당첨 번호 입력 및 검증 로직이 잘 구현되었습니다!Lotto 클래스를 활용한 검증과 에러 처리가 적절합니다.
36-43
: 보너스 번호 검증 로직이 완벽합니다!모든 필요한 검증(숫자 여부, 중복 확인, 범위 검사)이 잘 구현되어 있습니다.
45-51
: 보너스 번호 입력 로직이 일관성 있게 구현되었습니다!다른 입력 함수들과 동일한 패턴으로 구현되어 있어 코드의 일관성이 좋습니다.
84-93
: 메인 로직이 깔끔하게 구현되었습니다!전체 로또 게임의 흐름이 명확하고 구조적으로 잘 구현되어 있습니다.
src/lotto/main.py
Outdated
def prompt_purchase_amount(): | ||
while True: | ||
try: | ||
print("구입금액을 입력해 주세요.") | ||
amount = input() | ||
return check_amount(amount) | ||
except ValueError as error: | ||
print(f"[ERROR] {error}") | ||
raise |
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
에러 처리 로직 개선이 필요합니다.
에러 메시지를 출력한 후에 예외를 다시 발생시키는 것은 불필요합니다. 에러 메시지를 출력하고 계속해서 입력을 받도록 수정하는 것이 좋습니다.
다음과 같이 수정해보세요:
def prompt_purchase_amount():
while True:
try:
print("구입금액을 입력해 주세요.")
amount = input()
return check_amount(amount)
except ValueError as error:
print(f"[ERROR] {error}")
- raise
📝 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 prompt_purchase_amount(): | |
while True: | |
try: | |
print("구입금액을 입력해 주세요.") | |
amount = input() | |
return check_amount(amount) | |
except ValueError as error: | |
print(f"[ERROR] {error}") | |
raise | |
def prompt_purchase_amount(): | |
while True: | |
try: | |
print("구입금액을 입력해 주세요.") | |
amount = input() | |
return check_amount(amount) | |
except ValueError as error: | |
print(f"[ERROR] {error}") |
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
🔭 Outside diff range comments (1)
src/lotto/lotto.py (1)
35-64
: 🛠️ Refactor suggestionLotto 클래스 구현이 잘 되었으나, PEP8 스타일 가이드 위반 사항이 있습니다.
다음 위치에 빈 줄 관련 PEP8 스타일 가이드 위반이 있습니다:
- 38번 줄: 빈 줄 누락
- 57번 줄: 불필요한 빈 줄
- 61번 줄: 불필요한 빈 줄
다음과 같이 수정하세요:
class Lotto(): """로또 번호 및 당첨 결과를 처리하는 클래스""" ERROR_MESSAGE = "[ERROR] 구입 금액이 잘못되었습니다." + def __init__(self, numbers: list[int]): self._validate(numbers) self._numbers = sorted(numbers) def _validate(self, numbers: list[int]): """로또 번호 검증: 개수, 중복, 범위""" if len(numbers) != 6: raise ValueError("로또 번호는 정확히 6개여야 합니다.") if len(set(numbers)) != 6: raise ValueError("로또 번호에 중복이 있어서는 안 됩니다.") if not all(1 <= num <= 45 for num in numbers): raise ValueError("로또 번호는 1부터 45 사이여야 합니다.") @classmethod def generate_randomlotto(cls): """무작위 로또 번호 생성""" return cls(random.sample(range(1, 46), 6)) def get_numbers(self): return self._numbers def __str__(self): """str 형식으로 변환하여 반환""" return str(self._numbers)
그 외에는 클래스의 기능이 매우 잘 구현되어 있습니다:
- 번호 검증 로직이 명확합니다
- 무작위 번호 생성이 효율적으로 구현되어 있습니다
- 에러 메시지가 명확합니다
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 38-38: expected 1 blank line, found 0
[error] 57-57: too many blank lines (2)
[error] 61-61: too many blank lines (2)
🧹 Nitpick comments (1)
src/lotto/main.py (1)
36-45
: 당첨 번호 입력 함수의 에러 메시지를 개선하면 좋겠습니다.현재 구현은 잘 되어 있으나, 사용자에게 더 명확한 입력 형식 안내가 필요합니다.
다음과 같이 수정을 제안합니다:
def prompt_winning_numbers(): """당첨 번호 입력""" while True: - print("\n당첨 번호를 입력해 주세요.") + print("\n당첨 번호를 입력해 주세요.") + print("입력 형식: 1,2,3,4,5,6 (쉼표로 구분)") try: winning_numbers = list(map(int, input().split(","))) return Lotto(winning_numbers).get_numbers() except ValueError as error: print(f"[ERROR] {error}")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Check PEP8 Style
src/lotto/lotto.py
[error] 38-38: expected 1 blank line, found 0
[error] 57-57: too many blank lines (2)
[error] 61-61: too many blank lines (2)
src/lotto/main.py
[error] 97-97: line too long (86 > 79 characters)
🔇 Additional comments (6)
src/lotto/lotto.py (1)
5-33
: 잘 구현된 Rank 열거형 클래스입니다!열거형을 사용하여 로또 순위를 정의한 것이 매우 적절합니다. 각 순위별 당첨금액을 명확하게 표현했고,
get_rank
메서드를 통해 순위 결정 로직을 깔끔하게 구현했습니다.src/lotto/main.py (5)
4-27
: 입력값 검증 로직이 잘 구현되어 있습니다!금액 검증 및 사용자 입력 처리가 다음과 같이 잘 구현되어 있습니다:
- 숫자 여부 확인
- 1,000원 단위 확인
- 최소 금액 확인
- 명확한 에러 메시지
29-34
: 티켓 출력 함수가 간단명료하게 구현되었습니다!
__str__()
메서드를 활용하여 깔끔하게 구현했습니다.
47-59
: 보너스 번호 검증이 철저하게 구현되어 있습니다!모든 필요한 검증이 포함되어 있습니다:
- 숫자 입력 확인
- 당첨 번호와 중복 확인
- 유효 범위 확인
71-86
: 티켓 평가 로직이 효율적으로 구현되어 있습니다!set 연산을 활용하여 일치하는 번호를 효율적으로 계산하고 있습니다.
108-121
: 메인 함수가 명확하고 체계적으로 구현되어 있습니다!프로그램의 흐름이 논리적이고 이해하기 쉽게 구성되어 있습니다.
def print_results(results, total_prize, amount): | ||
"""당첨 결과 및 수익률 출력""" | ||
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) | ||
|
||
print("\n당첨 통계") | ||
print("---") | ||
for rank in Rank: | ||
if rank == Rank.SECOND: | ||
print( | ||
f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {results[rank]}개" | ||
) | ||
|
||
if rank != Rank.NONE and rank != Rank.SECOND: | ||
print( | ||
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - {results[rank]}개" | ||
) | ||
|
||
print(f"총 수익률은 {profit_percentage}%입니다.") | ||
|
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
결과 출력 함수에 PEP8 스타일 가이드 위반이 있습니다.
97번 줄이 PEP8의 최대 줄 길이(79자)를 초과합니다.
다음과 같이 수정하세요:
- f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {results[rank]}개"
+ f"{rank.match_cnt}개 일치, 보너스 볼 일치"
+ f" ({rank.prize:,}원) - {results[rank]}개"
📝 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 print_results(results, total_prize, amount): | |
"""당첨 결과 및 수익률 출력""" | |
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) | |
print("\n당첨 통계") | |
print("---") | |
for rank in Rank: | |
if rank == Rank.SECOND: | |
print( | |
f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {results[rank]}개" | |
) | |
if rank != Rank.NONE and rank != Rank.SECOND: | |
print( | |
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - {results[rank]}개" | |
) | |
print(f"총 수익률은 {profit_percentage}%입니다.") | |
def print_results(results, total_prize, amount): | |
"""당첨 결과 및 수익률 출력""" | |
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) | |
print("\n당첨 통계") | |
print("---") | |
for rank in Rank: | |
if rank == Rank.SECOND: | |
print( | |
f"{rank.match_cnt}개 일치, 보너스 볼 일치" | |
f" ({rank.prize:,}원) - {results[rank]}개" | |
) | |
if rank != Rank.NONE and rank != Rank.SECOND: | |
print( | |
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - {results[rank]}개" | |
) | |
print(f"총 수익률은 {profit_percentage}%입니다.") |
🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 97-97: line too long (86 > 79 characters)
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
♻️ Duplicate comments (1)
src/lotto/main.py (1)
110-123
: 🛠️ Refactor suggestionUI 로직 분리가 필요합니다.
현재 파일에서 입출력 로직과 비즈니스 로직이 혼재되어 있습니다. 유지보수와 테스트를 위해 분리하는 것이 좋습니다.
UI 관련 함수들(
prompt_*
,print_*
)을 별도의 모듈(예:ui.py
)로 분리하는 것을 추천드립니다.
🧹 Nitpick comments (3)
src/lotto/lotto.py (2)
83-88
: 검증 오류 메시지를 더 구체적으로 개선하면 좋겠습니다.현재 범위 검증 오류 메시지는 어떤 숫자가 잘못되었는지 구체적으로 알려주지 않습니다.
다음과 같이 수정해보세요:
- raise ValueError("로또 번호는 1부터 45 사이여야 합니다.") + invalid_numbers = [num for num in numbers if num < 1 or num > 45] + raise ValueError(f"유효하지 않은 번호가 있습니다: {invalid_numbers}")
61-89
: 오류 메시지를 클래스 상수로 분리하면 좋겠습니다.현재
ERROR_MESSAGE
처럼 다른 검증 관련 오류 메시지도 클래스 레벨 상수로 분리하면 일관성 있는 관리가 가능합니다.다음과 같이 수정해보세요:
ERROR_MESSAGE = "[ERROR] 구입 금액이 잘못되었습니다." + ERROR_COUNT = "로또 번호는 정확히 6개여야 합니다." + ERROR_DUPLICATE = "로또 번호에 중복이 있어서는 안 됩니다." + ERROR_RANGE = "로또 번호는 1부터 45 사이여야 합니다."src/lotto/main.py (1)
4-16
: 오류 메시지 형식을 통일하면 좋겠습니다.일부 오류 메시지에만 '[ERROR]' 접두어가 붙어있어 일관성이 없습니다.
다음과 같이 수정해보세요:
- raise ValueError("[ERROR] 숫자를 입력해 주세요.") + raise ValueError("숫자를 입력해 주세요.")또는 모든 오류 메시지에 '[ERROR]' 접두어를 추가하세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/lotto/__init__.py
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/lotto/init.py
🔇 Additional comments (3)
src/lotto/lotto.py (1)
5-52
: 잘 구현된 Rank 열거형 클래스입니다!상수 값들이 명확하게 정의되어 있고, 문서화가 잘 되어있습니다.
get_rank
클래스 메서드를 통한 순위 결정 로직도 깔끔합니다.src/lotto/main.py (2)
96-99
: 줄 길이가 PEP8 스타일 가이드를 위반합니다.97번 줄이 PEP8의 최대 줄 길이(79자)를 초과합니다.
다음과 같이 수정하세요:
- f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - {results[rank]}개" + f"{rank.match_cnt}개 일치, 보너스 볼 일치" + f" ({rank.prize:,}원) - {results[rank]}개"
71-85
: 효율적이고 깔끔한 구현입니다!집합 연산을 사용하여 일치하는 번호를 효율적으로 계산하고 있습니다. 코드가 명확하고 이해하기 쉽습니다.
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: 2
🧹 Nitpick comments (5)
src/lotto/lotto.py (2)
16-21
: NONE 케이스의 match_cnt 값 개선이 필요합니다.현재 NONE의 match_cnt가 0으로 설정되어 있는데, 이는 1-2개 일치하는 경우도 포함해야 합니다.
다음과 같이 수정하는 것을 제안합니다:
- NONE = (0, False, 0) + NONE = (None, False, 0) # None을 사용하여 미당첨 상태를 더 명확하게 표현
90-98
: generate_randomlotto 메서드에 추가 검증이 필요합니다.현재 구현은 random.sample을 직접 사용하고 있어, 잠재적으로 예외가 발생할 수 있습니다.
다음과 같이 예외 처리를 추가하는 것을 제안합니다:
@classmethod def generate_randomlotto(cls): - return cls(random.sample(range(1, 46), 6)) + try: + return cls(random.sample(range(1, 46), 6)) + except ValueError as e: + raise ValueError("로또 번호 생성 중 오류가 발생했습니다.") from esrc/lotto/main.py (1)
71-85
: 성능 최적화가 필요합니다.현재 구현은 각 티켓마다 set 변환을 수행하고 있어, 대량의 티켓 처리 시 성능 저하가 발생할 수 있습니다.
다음과 같이 최적화하는 것을 제안합니다:
def evaluate_tickets(tickets, winning_numbers, bonus_num): results = {rank: 0 for rank in Rank} total_prize = 0 + winning_set = set(winning_numbers) # 한 번만 set으로 변환 for ticket in tickets: ticket_numbers = ticket.get_numbers() - match_count = len(set(winning_numbers) & set(ticket_numbers)) + match_count = len(winning_set & set(ticket_numbers)) bonus = bonus_num in ticket_numbers.github/workflows/check-function-length.yml (1)
21-23
: Pylint 설정을 보강할 필요가 있습니다.현재 설정은 design 관련 메시지만 활성화하고 있어, 중요한 코드 품질 검사가 누락될 수 있습니다.
다음과 같이 추가 설정을 제안합니다:
echo "[MESSAGES CONTROL]" >> .pylintrc echo "disable=all" >> .pylintrc - echo "enable=design" >> .pylintrc + echo "enable=design,convention,refactor" >> .pylintrc + echo "[FORMAT]" >> .pylintrc + echo "max-line-length=88" >> .pylintrcdocs/README.md (1)
1-46
: 문서에 중요한 섹션이 누락되어 있습니다.현재 문서는 기능 목록을 잘 설명하고 있지만, 몇 가지 중요한 섹션이 누락되어 있습니다.
다음 섹션들을 추가하는 것을 제안합니다:
# 시작하기 ## 설치 방법 ## 실행 방법 # 프로젝트 구조 ## 파일 구조 ## 클래스 설명 # 테스트 ## 테스트 실행 방법 ## 테스트 케이스 설명
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
.github/workflows/check-function-length.yml
(1 hunks).github/workflows/check-no-external-libs.yml
(1 hunks)README.md
(0 hunks)docs/README.md
(1 hunks)pytest.ini
(1 hunks)src/lotto/__init__.py
(1 hunks)src/lotto/lotto.py
(1 hunks)src/lotto/main.py
(1 hunks)tests/lotto/test_main.py
(1 hunks)
💤 Files with no reviewable changes (1)
- README.md
🚧 Files skipped from review as they are similar to previous changes (3)
- tests/lotto/test_main.py
- pytest.ini
- src/lotto/init.py
🔇 Additional comments (4)
.github/workflows/check-no-external-libs.yml (4)
26-30
: 내부 모듈 확인 함수 구현 확인새롭게 추가된
is_internal_module(module_name)
함수는src
디렉토리 내에서 모듈 파일이나 폴더의 존재 여부를 확인하여 내부 모듈인지 판별하는 로직으로, 주석과 구현 모두 명확해 보입니다.
38-38
: 조건문 검증: Import 구문
alias.name
에 대해allowed_modules
와is_internal_module
함수를 이용하여 외부 라이브러리를 판별하는 조건문이 적절하게 구현되어 있습니다. 다만, 위의 allowed_modules 수정이 반영되어야 올바른 검증이 이뤄질 것입니다.
41-42
: 조건문 검증: ImportFrom 구문
node.module
를 확인할 때 외부 라이브러리 검증을 위해allowed_modules
와is_internal_module
조건을 함께 사용한 부분도 타당하게 구현되어 있습니다.
47-47
: 각 파일에 대한 체크 함수 호출 검증
os.walk
를 통해src
디렉토리 내의 모든 Python 파일에 대해check_imports
함수를 호출하는 로직은 의도한 대로 동작할 것으로 보입니다.
def print_results(results, total_prize, amount): | ||
"""당첨 결과 및 수익률 출력""" | ||
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) | ||
|
||
print("\n당첨 통계") | ||
print("---") | ||
for rank in Rank: | ||
if rank == Rank.SECOND: | ||
print( | ||
f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " | ||
f"{results[rank]}개" | ||
) | ||
|
||
if rank != Rank.NONE and rank != Rank.SECOND: | ||
print( | ||
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " | ||
f"{results[rank]}개" | ||
) | ||
|
||
print(f"총 수익률은 {profit_percentage}%입니다.") |
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
결과 출력 로직의 중복을 제거해야 합니다.
현재 구현에서 결과 출력 문자열 포맷팅 로직이 중복되어 있습니다.
다음과 같이 리팩토링하는 것을 제안합니다:
def print_results(results, total_prize, amount):
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2)
+
+ def format_result(rank):
+ bonus_text = ", 보너스 볼 일치" if rank == Rank.SECOND else ""
+ return f"{rank.match_cnt}개 일치{bonus_text} ({rank.prize:,}원) - {results[rank]}개"
print("\n당첨 통계")
print("---")
for rank in Rank:
- if rank == Rank.SECOND:
- print(
- f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - "
- f"{results[rank]}개"
- )
-
- if rank != Rank.NONE and rank != Rank.SECOND:
- print(
- f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - "
- f"{results[rank]}개"
- )
+ if rank != Rank.NONE:
+ print(format_result(rank))
📝 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 print_results(results, total_prize, amount): | |
"""당첨 결과 및 수익률 출력""" | |
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) | |
print("\n당첨 통계") | |
print("---") | |
for rank in Rank: | |
if rank == Rank.SECOND: | |
print( | |
f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " | |
f"{results[rank]}개" | |
) | |
if rank != Rank.NONE and rank != Rank.SECOND: | |
print( | |
f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " | |
f"{results[rank]}개" | |
) | |
print(f"총 수익률은 {profit_percentage}%입니다.") | |
def print_results(results, total_prize, amount): | |
"""당첨 결과 및 수익률 출력""" | |
profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) | |
def format_result(rank): | |
bonus_text = ", 보너스 볼 일치" if rank == Rank.SECOND else "" | |
return f"{rank.match_cnt}개 일치{bonus_text} ({rank.prize:,}원) - {results[rank]}개" | |
print("\n당첨 통계") | |
print("---") | |
for rank in Rank: | |
if rank != Rank.NONE: | |
print(format_result(rank)) | |
print(f"총 수익률은 {profit_percentage}%입니다.") |
allowed_modules = {'sys', 'os', 'math', 'random', 'datetime', 're' 'enum'} | ||
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.
문자열 연결으로 인한 allowed_modules 문제
현재 allowed_modules
집합 정의에서 're' 'enum'
으로 작성되어 있어 두 문자열이 쉼표 없이 연결됩니다. 이로 인해 "re"
와 "enum"
이 올바르게 분리되지 않고 "reenum"
이라는 단일 문자열이 생성됩니다.
수정 제안:
- allowed_modules = {'sys', 'os', 'math', 'random', 'datetime', 're' 'enum'}
+ allowed_modules = {'sys', 'os', 'math', 'random', 'datetime', 're', 'enum'}
📝 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.
allowed_modules = {'sys', 'os', 'math', 'random', 'datetime', 're' 'enum'} | |
allowed_modules = {'sys', 'os', 'math', 'random', 'datetime', 're', 'enum'} |
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 (2)
src/lotto/main.py (2)
4-16
: 입력 검증 로직의 테스트 커버리지 개선이 필요합니다.입력 검증 로직이 잘 구현되어 있지만, 오류 케이스에 대한 테스트가 누락되어 있습니다.
다음과 같은 테스트 케이스를 추가하는 것을 추천드립니다:
- 숫자가 아닌 입력
- 1000으로 나누어 떨어지지 않는 금액
- 1000원 미만의 금액
테스트 코드 작성을 도와드릴까요?
Also applies to: 18-23
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 11-11: src/lotto/main.py#L11
Added line #L11 was not covered by tests
[warning] 13-13: src/lotto/main.py#L13
Added line #L13 was not covered by tests
33-66
: 당첨 번호 및 보너스 번호 검증의 테스트 커버리지 개선이 필요합니다.당첨 번호와 보너스 번호의 검증 로직이 잘 구현되어 있지만, 다음 오류 케이스들에 대한 테스트가 누락되어 있습니다:
- 당첨 번호 입력 오류
- 보너스 번호가 숫자가 아닌 경우
- 보너스 번호가 당첨 번호와 중복되는 경우
- 보너스 번호가 범위를 벗어나는 경우
테스트 코드 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 40-41: src/lotto/main.py#L40-L41
Added lines #L40 - L41 were not covered by tests
[warning] 47-47: src/lotto/main.py#L47
Added line #L47 was not covered by tests
[warning] 51-51: src/lotto/main.py#L51
Added line #L51 was not covered by tests
[warning] 53-53: src/lotto/main.py#L53
Added line #L53 was not covered by tests
[warning] 64-65: src/lotto/main.py#L64-L65
Added lines #L64 - L65 were not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/lotto/main.py
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/lotto/main.py
[warning] 11-11: src/lotto/main.py#L11
Added line #L11 was not covered by tests
[warning] 13-13: src/lotto/main.py#L13
Added line #L13 was not covered by tests
[warning] 40-41: src/lotto/main.py#L40-L41
Added lines #L40 - L41 were not covered by tests
[warning] 47-47: src/lotto/main.py#L47
Added line #L47 was not covered by tests
[warning] 51-51: src/lotto/main.py#L51
Added line #L51 was not covered by tests
[warning] 53-53: src/lotto/main.py#L53
Added line #L53 was not covered by tests
[warning] 64-65: src/lotto/main.py#L64-L65
Added lines #L64 - L65 were not covered by tests
[warning] 123-123: src/lotto/main.py#L123
Added line #L123 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
src/lotto/main.py
[warning] 123-123: Final newline missing (missing-final-newline)
🪛 GitHub Actions: Check PEP8 Style
src/lotto/main.py
[error] 26-26: E303 too many blank lines (3)
[warning] 123-123: W292 no newline at end of file
🔇 Additional comments (3)
src/lotto/main.py (3)
26-31
: 구현이 깔끔합니다!객체의
__str__()
메서드를 활용한 출력 구현이 적절합니다.🧰 Tools
🪛 GitHub Actions: Check PEP8 Style
[error] 26-26: E303 too many blank lines (3)
85-104
: 결과 출력 로직의 중복을 제거해야 합니다.현재 구현에서 결과 출력 문자열 포맷팅 로직이 중복되어 있습니다.
다음과 같이 리팩토링하는 것을 제안합니다:
def print_results(results, total_prize, amount): profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) + + def format_result(rank): + bonus_text = ", 보너스 볼 일치" if rank == Rank.SECOND else "" + return f"{rank.match_cnt}개 일치{bonus_text} ({rank.prize:,}원) - {results[rank]}개" print("\n당첨 통계") print("---") for rank in Rank: - if rank == Rank.SECOND: - print( - f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " - f"{results[rank]}개" - ) - - if rank != Rank.NONE and rank != Rank.SECOND: - print( - f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " - f"{results[rank]}개" - ) + if rank != Rank.NONE: + print(format_result(rank))
107-120
: 메인 함수의 구현이 깔끔합니다!게임의 흐름이 명확하고 각 단계가 잘 구조화되어 있습니다.
src/lotto/main.py
Outdated
if __name__ == "__main__": | ||
main() | ||
main() |
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.
PEP8 스타일 가이드를 준수해야 합니다.
파일 끝에 개행이 누락되어 있습니다.
다음과 같이 수정하세요:
if __name__ == "__main__":
- main()
+ main()
+
📝 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.
if __name__ == "__main__": | |
main() | |
main() | |
if __name__ == "__main__": | |
main() | |
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 123-123: src/lotto/main.py#L123
Added line #L123 was not covered by tests
🪛 GitHub Actions: Check Indentation Depth
[warning] 123-123: Final newline missing (missing-final-newline)
🪛 GitHub Actions: Check PEP8 Style
[warning] 123-123: W292 no newline at end of 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: 1
♻️ Duplicate comments (1)
src/lotto/main.py (1)
84-103
: 🛠️ Refactor suggestion결과 출력 로직의 중복을 제거해야 합니다.
결과 출력 문자열 포맷팅 로직이 중복되어 있습니다. 헬퍼 함수를 사용하여 중복을 제거하는 것이 좋습니다.
다음과 같이 리팩토링하는 것을 제안합니다:
def print_results(results, total_prize, amount): profit_percentage = round((total_prize / (amount * 1000)) * 100, 2) + + def format_result(rank): + bonus_text = ", 보너스 볼 일치" if rank == Rank.SECOND else "" + return f"{rank.match_cnt}개 일치{bonus_text} ({rank.prize:,}원) - {results[rank]}개" print("\n당첨 통계") print("---") for rank in Rank: - if rank == Rank.SECOND: - print( - f"{rank.match_cnt}개 일치, 보너스 볼 일치 ({rank.prize:,}원) - " - f"{results[rank]}개" - ) - - if rank != Rank.NONE and rank != Rank.SECOND: - print( - f"{rank.match_cnt}개 일치 ({rank.prize:,}원) - " - f"{results[rank]}개" - ) + if rank != Rank.NONE: + print(format_result(rank))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/lotto/__init__.py
(1 hunks)src/lotto/main.py
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/lotto/init.py
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/lotto/main.py
[warning] 11-11: src/lotto/main.py#L11
Added line #L11 was not covered by tests
[warning] 13-13: src/lotto/main.py#L13
Added line #L13 was not covered by tests
[warning] 39-40: src/lotto/main.py#L39-L40
Added lines #L39 - L40 were not covered by tests
[warning] 46-46: src/lotto/main.py#L46
Added line #L46 was not covered by tests
[warning] 50-50: src/lotto/main.py#L50
Added line #L50 was not covered by tests
[warning] 52-52: src/lotto/main.py#L52
Added line #L52 was not covered by tests
[warning] 63-64: src/lotto/main.py#L63-L64
Added lines #L63 - L64 were not covered by tests
🔇 Additional comments (3)
src/lotto/main.py (3)
4-16
: 테스트 케이스 보완이 필요합니다.금액 검증 로직에 대한 테스트 케이스가 부족합니다. 다음 케이스들에 대한 테스트를 추가해주세요:
- 1,000원 미만 금액 입력
- 1,000원으로 나누어 떨어지지 않는 금액 입력
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 11-11: src/lotto/main.py#L11
Added line #L11 was not covered by tests
[warning] 13-13: src/lotto/main.py#L13
Added line #L13 was not covered by tests
43-55
: 보너스 번호 검증 테스트 케이스 보완이 필요합니다.다음 검증 케이스들에 대한 테스트가 누락되었습니다:
- 숫자가 아닌 입력
- 당첨 번호와 중복되는 번호
- 범위를 벗어난 번호 (1-45 외)
테스트 케이스 작성을 도와드릴까요?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 46-46: src/lotto/main.py#L46
Added line #L46 was not covered by tests
[warning] 50-50: src/lotto/main.py#L50
Added line #L50 was not covered by tests
[warning] 52-52: src/lotto/main.py#L52
Added line #L52 was not covered by tests
67-82
: 잘 구현되었습니다!당첨 번호 비교 로직이 효율적으로 구현되었습니다:
- set 연산을 활용한 매칭 검사
- 깔끔한 결과 집계
def prompt_winning_numbers(): | ||
"""당첨 번호 입력""" | ||
while True: | ||
print("\n당첨 번호를 입력해 주세요.") | ||
try: | ||
winning_numbers = list(map(int, input().split(","))) | ||
return Lotto(winning_numbers).get_numbers() | ||
except ValueError as error: | ||
print(f"[ERROR] {error}") | ||
|
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
예외 처리 및 테스트 케이스 보완이 필요합니다.
당첨 번호 입력 처리에서 다음 개선사항이 필요합니다:
- 예외 처리가 테스트되지 않았습니다
- 잘못된 입력 형식(예: 쉼표 없는 입력)에 대한 구체적인 에러 메시지가 필요합니다
다음과 같이 수정해보세요:
try:
winning_numbers = list(map(int, input().split(",")))
return Lotto(winning_numbers).get_numbers()
except ValueError as error:
- print(f"[ERROR] {error}")
+ if "split" in str(error):
+ print("[ERROR] 쉼표(,)로 구분된 숫자를 입력해 주세요.")
+ else:
+ print(f"[ERROR] {error}")
📝 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 prompt_winning_numbers(): | |
"""당첨 번호 입력""" | |
while True: | |
print("\n당첨 번호를 입력해 주세요.") | |
try: | |
winning_numbers = list(map(int, input().split(","))) | |
return Lotto(winning_numbers).get_numbers() | |
except ValueError as error: | |
print(f"[ERROR] {error}") | |
def prompt_winning_numbers(): | |
"""당첨 번호 입력""" | |
while True: | |
print("\n당첨 번호를 입력해 주세요.") | |
try: | |
winning_numbers = list(map(int, input().split(","))) | |
return Lotto(winning_numbers).get_numbers() | |
except ValueError as error: | |
if "split" in str(error): | |
print("[ERROR] 쉼표(,)로 구분된 숫자를 입력해 주세요.") | |
else: | |
print(f"[ERROR] {error}") |
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 39-40: src/lotto/main.py#L39-L40
Added lines #L39 - L40 were not covered by tests
Summary by CodeRabbit