Skip to content
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

๐Ÿš€ 4๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ(๋ฆฌํŒฉํ„ฐ๋ง) #2159

Open
wants to merge 2 commits into
base: jioome
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/main/java/nextstep/ladder/LadderMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ public class LadderMain {
public static void main(String[] args){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ทธ๋ฆฌ๊ณ  ๋ฏธ์…˜ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์–ด๋–ค ๋‹จ์œ„๋‚˜ ๊ธฐ์ค€์œผ๋กœ ์ปค๋ฐ‹์„ ํ•˜๋ฉด ์ข‹์„์ง€ ์• ๋งคํ•ด์„œ ๊ณ ๋ฏผ๋˜์—ˆ๋˜ ์ ์ด ๋งŽ์•˜๋Š”๋ฐ ๊ทธ ๋ถ€๋ถ„ ์งˆ๋ฌธ๋“œ๋ฆฝ๋‹ˆ๋‹ค!

๋‹ค๋“ค ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ• ๊ฑฐ๋ผ ์ •๋‹ต์€ ์—†์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ ๋งŒ ๋ถ€ํƒ๋“œ๋ ค์š”

์ €๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์„ ๋งŽ์ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

  1. ์ •ํ™•ํ•œ ํ•œ ๋‘๊ฐœ์˜ ํด๋ž˜์Šค๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ํด๋ž˜์Šค ๋ฐ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ๊นŒ์ง€ ์ปค๋ฐ‹
  2. ๋‹ค์†Œ ๋งŽ์€ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ์—ฌ๋Ÿฌ ํด๋ž˜์Šค ๋ฐ ์ด์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ๋™์ž‘ํ•˜๊ฒŒ ๋งŒ๋“  ๋’ค ์ปค๋ฐ‹

2๋ฒˆ์˜ ๊ฒฝ์šฐ ์›๊ฒฉ ์ €์žฅ์†Œ์— ์ž„์‹œ๋กœ ์˜ฌ๋ ค์•ผํ•˜๊ฑฐ๋‚˜, ์ €์žฅ์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋„ ์žˆ๋Š”๋ฐ ์ด ๊ฒฝ์šฐ ํ•ญ์ƒ ๋™์ž‘ํ•˜๋Š” ์ฝ”๋“œ ๊ธฐ๋ฐ˜์˜ ์ปค๋ฐ‹์„ ๋งŒ๋“ค๊ธฐ ์–ด๋ ค์›Œ์„œ ์ž„์‹œ๋กœ ์ปค๋ฐ‹์„ ํ–ˆ๋‹ค๊ฐ€ reset ์„ ํ†ตํ•ด ์ปค๋ฐ‹์„ ์ •๋ฆฌํ•˜๊ณ  ์˜ฌ๋ฆฌ๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์€ ๊ฒƒ ๊ฐ™์•„์š”.

InputView inputView = new InputView();
OutputView outputView = new OutputView();

final Names names = new Names(inputView.inputNames());
final LadderResult ladderResult = new LadderResult(inputView.inputResult());
final Height height = new Height(inputView.inputLadderHeight());
final Ladder ladder = new Ladder(names.getNumberOfNames(), height);
final Ladder ladder = new Ladder(names.getNumberOfNames(), inputView.inputLadderHeight());

outputView.printLadder(names, ladder);
final LadderResultDeterminer determiner = new LadderResultDeterminer(ladderResult, names);
final LadderResultManager ladderResultManager = new LadderResultManager(names);
ladderResultManager.update(ladder, determiner);
final LadderResultManager ladderResultManager = new LadderResultManager(names, ladder, determiner);
outputView.printResult(inputView.inputName(), ladderResultManager);
}
}
4 changes: 2 additions & 2 deletions src/main/java/nextstep/ladder/domain/Ladder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
public class Ladder {
private final List<Line> lines;

public Ladder(final int numberOfPeople, final Height height) {
public Ladder(final int numberOfPeople, final int height) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜น์‹œ ๋ž˜ํ•‘ ํด๋ž˜์Šค๋ฅผ ์ œ๊ฑฐํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”? 0์ธ ๊ฒฝ์šฐ์— ๋Œ€ํ•ด์„œ๋Š” ์˜ˆ์™ธ๊ฐ€ ๋‚˜์ง€ ์•Š์„ ๊ฒƒ ๊ฐ™์€๋ฐ ์˜๋„ํ•˜์‹  ๋ถ€๋ถ„์ผ๊นŒ์š”?

lines = Stream.generate(() -> new Line(new RandomGenerator(), numberOfPeople))
.limit(height.getValue())
.limit(height)
.collect(Collectors.toList());
}
public List<Line> getLines() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class LadderResultManager {

private final Map<Name, String> results;

public LadderResultManager(final Names names) {
public LadderResultManager(final Names names, final Ladder ladder, final LadderResultDeterminer determiner) {
this.results = names.toResult();
update(ladder, determiner);
}

public void update(final Ladder ladder, final LadderResultDeterminer determiner) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/nextstep/ladder/domain/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ public List<Bridge> getBridges() {
}

private Bridge getBridgeAtIndex(final int index) {
if (index >= 0 && index < bridges.size()) {
if (isIndexWithinBounds(index)) {
return bridges.get(index);
}
return Bridge.NON_BRIDGE;
}

private boolean isIndexWithinBounds(int index) {
return index >= 0 && index < bridges.size();
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/nextstep/ladder/LadderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ public class LadderTest {
@Test
@DisplayName("์ž…๋ ฅ๋œ height ๋งŒํผ ์‚ฌ๋‹ค๋ฆฌ ๊ธธ์ด๋ฅผ ๋งŒ๋“ ๋‹ค")
void ์‚ฌ๋‹ค๋ฆฌ๋ฅผ_์ƒ์„ฑํ•œ๋‹ค() {
final Height height = new Height(5);
final Ladder ladder = new Ladder(4, height);
final Ladder ladder = new Ladder(4, 5);

assertThat(ladder.getLines()).hasSize(5);
}

@Test
@DisplayName("height๊ฐ€ ์Œ์ˆ˜์ผ ๊ฒฝ์šฐ ์‚ฌ๋‹ค๋ฆฌ ์ƒ์„ฑ ์‹คํŒจ")
void ์‚ฌ๋‹ค๋ฆฌ๋ฅผ_์ƒ์„ฑ์„_์‹คํŒจํ•œ๋‹ค() {
assertThatThrownBy(() -> new Ladder(4, new Height(-1)))
assertThatThrownBy(() -> new Ladder(4, -1))
.isInstanceOf(IllegalArgumentException.class);
}

Expand Down