File tree Expand file tree Collapse file tree 3 files changed +39
-2
lines changed
main/java/nextstep/ladder
test/java/nextstep/ladder/domain Expand file tree Collapse file tree 3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public static void main(String[] args) {
19
19
OutputView .printLadders (lines );
20
20
OutputView .printInputResults (inputLadderResults );
21
21
22
- // LadderGame ladderGame = new LadderGame(names);
22
+ LadderGame ladderGame = new LadderGame (names , lines , inputLadderResults );
23
23
24
24
// OutputView.printNamesAndLadders(ladderGame);
25
25
// OutputView.printInputResults(inputLadderResults);
Original file line number Diff line number Diff line change 1
1
package nextstep .ladder .domain ;
2
2
3
+ import java .util .List ;
4
+
3
5
public class LadderGame {
4
6
private Names names ;
5
7
private Lines lines ;
8
+ private final List <LadderResult > results ;
6
9
7
- public LadderGame (Names names ) {
10
+ public LadderGame (Names names , Lines lines , List < LadderResult > results ) {
8
11
this .names = names ;
12
+ this .lines = lines ;
13
+ validateResults (results );
14
+ this .results = results ;
9
15
}
10
16
11
17
public Names getNames () {
@@ -15,4 +21,10 @@ public Names getNames() {
15
21
public Lines getLines () {
16
22
return lines ;
17
23
}
24
+
25
+ private void validateResults (List <LadderResult > results ) {
26
+ if (results .size () != names .size ()) {
27
+ throw new IllegalArgumentException ("참가자 수와 결과 수가 일치하지 않습니다." );
28
+ }
29
+ }
18
30
}
Original file line number Diff line number Diff line change
1
+ package nextstep .ladder .domain ;
2
+
3
+ import nextstep .ladder .domain .strategy .RandomLadderPoint ;
4
+ import org .assertj .core .api .Assertions ;
5
+ import org .junit .jupiter .api .DisplayName ;
6
+ import org .junit .jupiter .api .Test ;
7
+
8
+ import java .util .List ;
9
+
10
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
11
+
12
+ class LadderGameTest {
13
+
14
+ @ Test
15
+ @ DisplayName ("참가자 수와 결과 수가 일치하지 않으면 예외가 발생한다" )
16
+ void validateLadderResults_exception () {
17
+ Names names = new Names (List .of (new Name ("a" )));
18
+ List <LadderResult > inputLadderResults = List .of (new LadderResult ("꽝" ), new LadderResult ("1000" ));
19
+ Lines lines = new Lines ();
20
+ lines .initialize (1 , new Height (1 ), new RandomLadderPoint ());
21
+ Assertions .assertThatIllegalArgumentException ().isThrownBy (() -> {
22
+ new LadderGame (names , lines , inputLadderResults );
23
+ });
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments