Skip to content

Commit c0b132b

Browse files
committed
test: Add unit tests
단위 테스트 기능 추가
1 parent 655b819 commit c0b132b

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/lotto/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lotto import Lotto, Score
1+
from lotto.lotto import Lotto, Score
22

33

44
LOTTO_EACH_PRICE = 1000 # 로또 구입 금액 단위 매직넘버상수

tests/lotto/test_lotto.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,63 @@ def test_create_lotto_by_duplicated_number():
2121
Lotto([1, 2, 3, 4, 5, 5])
2222

2323

24-
# 추가 테스트 작성 가능
24+
# 로또 번호 범위 초과 예외 테스트 (예: 46이 포함된 경우)
25+
@pytest.mark.custom_name("로또 번호가 1~45 범위를 벗어나면 예외가 발생한다.")
26+
def test_create_lotto_by_out_of_range():
27+
with pytest.raises(ValueError):
28+
Lotto([0, 1, 2, 3, 4, 5]) # 0 포함
29+
with pytest.raises(ValueError):
30+
Lotto([1, 2, 3, 4, 5, 46]) # 46 포함
31+
32+
33+
# 보너스 번호 중복 예외 테스트 (보너스 번호가 당첨 번호와 중복)
34+
@pytest.mark.custom_name("보너스 번호가 당첨 번호와 중복되면 예외가 발생한다.")
35+
def test_validate_bonus_number_by_duplicate():
36+
lotto = Lotto([1, 2, 3, 4, 5, 6])
37+
with pytest.raises(ValueError):
38+
lotto.validate_bonus_number(5) # 기존 당첨 번호와 중복된 보너스 번호
39+
40+
41+
# 보너스 번호 범위 초과 예외 테스트
42+
@pytest.mark.custom_name("보너스 번호가 1~45 범위를 벗어나면 예외가 발생한다.")
43+
def test_validate_bonus_number_by_out_of_range():
44+
lotto = Lotto([1, 2, 3, 4, 5, 6])
45+
with pytest.raises(ValueError):
46+
lotto.validate_bonus_number(0) # 0 포함
47+
with pytest.raises(ValueError):
48+
lotto.validate_bonus_number(46) # 46 포함
49+
50+
51+
# 로또 자동 발행 시, 6개의 숫자가 포함되어 있는지 확인
52+
@pytest.mark.custom_name("로또 자동 발행 시, 6개의 숫자가 포함되어야 한다.")
53+
def test_issuance_lotto_size():
54+
numbers = Lotto.issuance_lotto()
55+
assert len(numbers) == 6
56+
57+
58+
# 로또 자동 발행 시, 숫자가 정렬되어 있는지 확인
59+
@pytest.mark.custom_name("로또 자동 발행 시, 번호가 오름차순 정렬되어야 한다.")
60+
def test_issuance_lotto_sorted():
61+
numbers = Lotto.issuance_lotto()
62+
assert numbers == sorted(numbers)
63+
64+
65+
# 로또 번호 비교 테스트 (당첨 개수 확인)
66+
@pytest.mark.custom_name("발행된 로또 번호와 당첨 번호를 비교하여 일치 개수를 확인한다.")
67+
def test_compare_winning_number():
68+
winning_lotto = Lotto([1, 2, 3, 4, 5, 6])
69+
issued_numbers = [1, 2, 3, 10, 20, 30] # 3개 일치
70+
assert winning_lotto.compare_winning_number(issued_numbers) == 3
71+
72+
73+
# 보너스 번호 비교 테스트
74+
@pytest.mark.custom_name("발행된 로또 번호와 보너스 번호를 비교하여 일치 여부를 확인한다.")
75+
def test_compare_bonus_number():
76+
winning_lotto = Lotto([1, 2, 3, 4, 5, 6])
77+
winning_lotto.validate_bonus_number(7)
78+
79+
issued_numbers = [7, 8, 9, 10, 11, 12] # 보너스 번호(7) 포함
80+
assert winning_lotto.compare_bonus_number(issued_numbers) == 1
81+
82+
issued_numbers = [1, 2, 3, 4, 5, 6] # 보너스 번호 미포함
83+
assert winning_lotto.compare_bonus_number(issued_numbers) == 0

0 commit comments

Comments
 (0)