forked from knh4437/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLottoTest.java
More file actions
116 lines (93 loc) · 3.17 KB
/
LottoTest.java
File metadata and controls
116 lines (93 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package lotto;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class LottoTest {
@DisplayName("로또 번호의 개수가 6개가 넘어가면 예외가 발생한다.")
@Test
void createLottoByOverSize() {
assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 6, 7)))
.isInstanceOf(IllegalArgumentException.class);
}
@DisplayName("로또 번호에 중복된 숫자가 있으면 예외가 발생한다.")
@Test
void createLottoByDuplicatedNumber() {
assertThatThrownBy(() -> new Lotto(List.of(1, 2, 3, 4, 5, 5)))
.isInstanceOf(IllegalArgumentException.class);
}
@DisplayName("6개 일치하면, 1을 반환한다.")
@Test
void calculateRank_1st() {
//given
Lotto lotto = new Lotto(List.of(1, 2, 3, 4, 5, 6));
List<Integer> answers = List.of(1, 2, 3, 4, 5, 6);
int bonus = 7;
//when
int rank = lotto.calculateRank(answers, bonus);
//then
assertThat(rank).isEqualTo(1);
}
@DisplayName("5개 일치하고, 보너스 볼 일치하면, 2을 반환한다.")
@Test
void calculateRank_2nd() {
//given
Lotto lotto = new Lotto(List.of(1, 2, 3, 4, 5, 7));
List<Integer> answers = List.of(1, 2, 3, 4, 5, 6);
int bonus = 7;
//when
int rank = lotto.calculateRank(answers, bonus);
//then
assertThat(rank).isEqualTo(2);
}
@DisplayName("5개 일치하면, 3을 반환한다.")
@Test
void calculateRank_3rd() {
//given
Lotto lotto = new Lotto(List.of(1, 2, 3, 4, 5, 8));
List<Integer> answers = List.of(1, 2, 3, 4, 5, 6);
int bonus = 7;
//when
int rank = lotto.calculateRank(answers, bonus);
//then
assertThat(rank).isEqualTo(3);
}
@DisplayName("4개 일치하면, 4을 반환한다.")
@Test
void calculateRank_4th() {
//given
Lotto lotto = new Lotto(List.of(1, 2, 3, 4, 7, 8));
List<Integer> answers = List.of(1, 2, 3, 4, 5, 6);
int bonus = 7;
//when
int rank = lotto.calculateRank(answers, bonus);
//then
assertThat(rank).isEqualTo(4);
}
@DisplayName("3개 일치하면, 5을 반환한다.")
@Test
void calculateRank_5th() {
//given
Lotto lotto = new Lotto(List.of(1, 2, 3, 7, 8, 9));
List<Integer> answers = List.of(1, 2, 3, 4, 5, 6);
int bonus = 7;
//when
int rank = lotto.calculateRank(answers, bonus);
//then
assertThat(rank).isEqualTo(5);
}
@DisplayName("2개 이하 일치하면, 6을 반환한다.")
@Test
void calculateRank_6th() {
//given
Lotto lotto = new Lotto(List.of(1, 2, 7, 8, 9, 10));
List<Integer> answers = List.of(1, 2, 3, 4, 5, 6);
int bonus = 7;
//when
int rank = lotto.calculateRank(answers, bonus);
//then
assertThat(rank).isEqualTo(6);
}
}