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) {
1919 OutputView .printLadders (lines );
2020 OutputView .printInputResults (inputLadderResults );
2121
22- // LadderGame ladderGame = new LadderGame(names);
22+ LadderGame ladderGame = new LadderGame (names , lines , inputLadderResults );
2323
2424// OutputView.printNamesAndLadders(ladderGame);
2525// OutputView.printInputResults(inputLadderResults);
Original file line number Diff line number Diff line change 11package nextstep .ladder .domain ;
22
3+ import java .util .List ;
4+
35public class LadderGame {
46 private Names names ;
57 private Lines lines ;
8+ private final List <LadderResult > results ;
69
7- public LadderGame (Names names ) {
10+ public LadderGame (Names names , Lines lines , List < LadderResult > results ) {
811 this .names = names ;
12+ this .lines = lines ;
13+ validateResults (results );
14+ this .results = results ;
915 }
1016
1117 public Names getNames () {
@@ -15,4 +21,10 @@ public Names getNames() {
1521 public Lines getLines () {
1622 return lines ;
1723 }
24+
25+ private void validateResults (List <LadderResult > results ) {
26+ if (results .size () != names .size ()) {
27+ throw new IllegalArgumentException ("참가자 수와 결과 수가 일치하지 않습니다." );
28+ }
29+ }
1830}
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