-
Notifications
You must be signed in to change notification settings - Fork 709
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
๐ 2๋จ๊ณ - ์ฌ๋ค๋ฆฌ(์์ฑ) #1963
base: jeounpar
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์๋
ํ์ธ์ ์ ๊ท๋
๋ช ๊ฐ์ง ์ฝ๋ฉํธ ๋จ๊ฒจ๋์๋๋ฐ ํ์ธํด ์ฃผ์๊ณ ๋ค์ ๋ฆฌ๋ทฐ ์์ฒญ ๋ถํ๋๋ ค์
public Ladder(LadderHeight heightOfLadder, PersonCount countOfPerson, Random random) { | ||
this.lines = new ArrayList<>(); | ||
IntStream.range(0, heightOfLadder.getHeightOfLadder()) | ||
.mapToObj(line -> new Line(countOfPerson.getCountOfPerson(), random)) | ||
.forEach(this.lines::add); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ฑ์์ ๋ก์ง์ด ํฌํจ๋์๋ค์
๋งํฌ๋ฅผ ์ฐธ๊ณ ํด ๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค
IntStream ์ for๋ฌธ์ผ๋ก ๋์ฒดํ ์ ์์ ๊ฒ ๊ฐ์๋ฐ์
IntStream ์ผ๋ก Line ๊ฐ์ฒด๋ค์ ์์ฑํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค
Random์ ์ธ์๋ก ๋ฐ์ผ๋ฉด ๋ฉฑ๋ฑ์ฑ์ด ์ง์ผ์ง์ง ์๋ ๊ฒ ๊ฐ์์
๋๋ค์ ์ฌ์ฉํ๋๋ผ๋ ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค์ด์ Ladder๋ ์ธํฐํ์ด์ค์ ์์กดํ๋๋ก ๋ณ๊ฒฝํ๋ฉด ์ด๋จ๊น์?
|
||
private static final int MIN_HEIGHT = 1; | ||
|
||
private final Integer heightOfLadder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapper ํ์
์ NPE๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค
๊ผญ ์จ์ผํ๋ ์ด์ ๊ฐ ์๋๋ผ๋ฉด ์์ ํ์
์ ์ฌ์ฉํ๋ฉด ์ด๋จ๊น์?
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class LadderService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฌ์ฉํ์ง ์๋ ์ฃผ์, ์ฝ๋(import ํฌํจ)์ ์ ๊ฑฐํด ์ฃผ์ธ์
public Line(int countOfPerson, Random random) { | ||
this.points = new ArrayList<>(); | ||
this.points.add(random.nextBoolean()); | ||
IntStream.range(0, countOfPerson - 2) | ||
.forEach(index -> initPoint(index, random.nextBoolean())); | ||
validateLine(countOfPerson); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฌ๊ธฐ๋ ์์ฑ์ ๋ด๋ถ์ ๋ก์ง์ด ์๋ค์
์ธ์ countOfPerson ์ PersonCount ํ์
์ ํ์ฉํ๋ฉด ์ด๋จ๊น์?
๊ฐ๋ก๋ผ์ธ์ ๊ฒน์น ์ ์๋ค๋ ์๊ตฌ์ฌํญ์ Line์ ์ฑ
์์ผ ๊ฒ ๊ฐ์๋ฐ์
์์ฑ์์ ๋ก์ง์ด ์์ด์ ์๊ตฌ์ฌํญ์ ๊ฒ์ฆํ ์ ์์ ๊ฒ ๊ฐ์์
์๊ตฌ์ฌํญ์ ๊ฒ์ฆํ ์ ์๋ ๊ตฌ์กฐ๋ฅผ ๊ณ ๋ฏผํด ๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์
if (this.points.get(index) && nextBoolean || this.points.get(index) && !nextBoolean | ||
|| !this.points.get(index) && !nextBoolean) { | ||
this.points.add(false); | ||
return; | ||
} | ||
if (!this.points.get(index) && nextBoolean) { | ||
this.points.add(true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getter๊ฐ ๋๋ฌด ๋ง์ด ์ฌ์ฉ๋๊ณ ์๋ ๊ฒ ๊ฐ์์
๋ฉ์์ง๋ฅผ ๋ณด๋ด์ ํด๊ฒฐํ ์ ์๋์ง, ๋ฉ์์ง๋ฅผ ๋ณด๋ผ ๊ฐ์ฒด๋ฅผ ๋์ถํ ์ ์๋์ง ๊ณ ๋ฏผํด ๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์
@Override | ||
public String toString() { | ||
return IntStream.range(0, MAX_LENGTH - name.length()) | ||
.mapToObj(i -> SPACE) | ||
.collect(Collectors.joining("", name, "")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Test | ||
@DisplayName("์ฌ๋ค๋ฆฌ์ ๋์๋ 1 ์ด์์ด๋ค") | ||
void ladder_height() { | ||
Assertions.assertThatThrownBy(() -> { | ||
new LadderHeight(0); | ||
}).isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("๋์ด๋ 1 ์ด์ ์ด์ด์ผ ํฉ๋๋ค."); | ||
|
||
Assertions.assertThatThrownBy(() -> { | ||
new LadderHeight(-1); | ||
}).isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("๋์ด๋ 1 ์ด์ ์ด์ด์ผ ํฉ๋๋ค."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฒฝ๊ณ๊ฐ์ธ 0์ผ๋ก ๊ฒ์ฆํ๋๋ฐ ์ถ๊ฐ๋ก -1๋ ๊ฒ์ฆํ์ ์ด์ ๊ฐ ์์ผ์ ๊ฐ์?
@Test | ||
void ladder() { | ||
Ladder ladder = new Ladder(new LadderHeight(5), new PersonCount(4), new AlwaysReturnTrue()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋จ์ ํ ์คํธ ์์ฑ์ด ๋๋ฝ๋์๋ค์
@Test | ||
@DisplayName("์ฌ๋ค๋ฆฌ์ ๋ผ์ธ ํ๋๋ฅผ ์์ฑํ๋ค") | ||
void line() { | ||
int countOfPerson = 5; | ||
Line line = new Line(countOfPerson, new AlwaysReturnTrue()); | ||
|
||
assertThat(line.getPoints()).hasSize(countOfPerson - 1) | ||
.containsExactly(true, false, true, false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DisplayName๊ณผ ํ
์คํธ ๋ด์ฉ์ด ์ผ์น ํ์ง ์๋ค์
ํ
์คํธ์ ์๋์ ํ
์คํธ ๋ด์ฉ์ ์ผ์น ์์ผ์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์
์ถ๊ฐ๋ก ๊ฐ๋ก ๋ผ์ธ์ ๊ฒน์น ์ ์๋ค๋ ์๊ตฌ์ฌํญ์ด ์๋๋ฐ ์ด ๊ฒ์ฆ์ ์ด๋ป๊ฒ ํ ์ ์์๊น์?
class OutputViewTest { | ||
|
||
@Test | ||
void print_ladder() { | ||
Ladder ladder = new Ladder(new LadderHeight(10), new PersonCount(5), | ||
new RandomTrueOrFalse()); | ||
OutputView outputView = new OutputView(); | ||
// outputView.printLadder(ladder); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ ์คํธ๊ฐ ํ์ํ๋ค๋ฉด ํ ์คํธ๋ฅผ ๋ง์ ์์ฑํด ์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์
์๋ ํ์ธ์! ์ฌ๋ค๋ฆฌ ๋ฏธ์ 2๋จ๊ณ ๋ฆฌ๋ทฐ ์์ฒญ๋๋ฆฝ๋๋ค!