Uh oh!
There was an error while loading. Please reload this page.
π 2λ¨κ³ - μ¬λ€λ¦¬(μμ±) - #1963
Conversation
testrace
left a comment
There was a problem hiding this comment.
μλ
νμΈμ μ κ·λ
λͺ κ°μ§ μ½λ©νΈ λ¨κ²¨λμλλ° νμΈν΄ μ£Όμκ³ λ€μ 리뷰 μμ² λΆνλλ €μ
| 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.
μμ±μμ λ‘μ§μ΄ ν¬ν¨λμλ€μ
λ§ν¬λ₯Ό μ°Έκ³ ν΄ λ³΄μλ©΄ μ’μ κ² κ°μ΅λλ€
IntStream μ forλ¬ΈμΌλ‘ λ체ν μ μμ κ² κ°μλ°μ
IntStream μΌλ‘ Line κ°μ²΄λ€μ μμ±νμ μ΄μ κ° κΆκΈν©λλ€
Randomμ μΈμλ‘ λ°μΌλ©΄ λ©±λ±μ±μ΄ μ§μΌμ§μ§ μλ κ² κ°μμ
λλ€μ μ¬μ©νλλΌλ μΈν°νμ΄μ€λ₯Ό λ§λ€μ΄μ Ladderλ μΈν°νμ΄μ€μ μμ‘΄νλλ‘ λ³κ²½νλ©΄ μ΄λ¨κΉμ?
| private static final int MIN_HEIGHT = 1; | ||
| private final Integer heightOfLadder; |
There was a problem hiding this comment.
wrapper νμ
μ NPEκ° λ°μν μ μμ΅λλ€
κΌ μ¨μΌνλ μ΄μ κ° μλλΌλ©΄ μμ νμ
μ μ¬μ©νλ©΄ μ΄λ¨κΉμ?
| import java.util.List; | ||
| import java.util.Random; | ||
| public class LadderService { |
There was a problem hiding this comment.
μ¬μ©νμ§ μλ μ£Όμ, μ½λ(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.
μ¬κΈ°λ μμ±μ λ΄λΆμ λ‘μ§μ΄ μλ€μ
μΈμ 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.
getterκ° λ무 λ§μ΄ μ¬μ©λκ³ μλ κ² κ°μμ
λ©μμ§λ₯Ό 보λ΄μ ν΄κ²°ν μ μλμ§, λ©μμ§λ₯Ό λ³΄λΌ κ°μ²΄λ₯Ό λμΆν μ μλμ§ κ³ λ―Όν΄ λ³΄μλ©΄ μ’μ κ² κ°μμ
| @Override | ||
| public String toString() { | ||
| return IntStream.range(0, MAX_LENGTH - name.length()) | ||
| .mapToObj(i -> SPACE) | ||
| .collect(Collectors.joining("", name, "")); | ||
| } |
| @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.
κ²½κ³κ°μΈ 0μΌλ‘ κ²μ¦νλλ° μΆκ°λ‘ -1λ κ²μ¦νμ μ΄μ κ° μμΌμ κ°μ?
| @Test | ||
| void ladder() { | ||
| Ladder ladder = new Ladder(new LadderHeight(5), new PersonCount(4), new AlwaysReturnTrue()); | ||
| } |
There was a problem hiding this comment.
λ¨μ ν μ€νΈ μμ±μ΄ λλ½λμλ€μ
| @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.
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.
ν μ€νΈκ° νμνλ€λ©΄ ν μ€νΈλ₯Ό λ§μ μμ±ν΄ μ£Όμλ©΄ μ’μ κ² κ°μμ

μλ νμΈμ! μ¬λ€λ¦¬ λ―Έμ 2λ¨κ³ 리뷰 μμ²λ립λλ€!