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๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ(๋ฆฌํŒฉํ„ฐ๋ง) #2291

Open
wants to merge 14 commits into
base: mingulee-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
63f4841
refactor: 3๋‹จ๊ณ„ ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ - ์ฃผ์„ ์‚ญ์ œ ๋ฐ ์ตœ์†Œํ•œ์˜ test fixture๋งŒ ๋‚จ๊ธฐ๊ธฐ
mingulee-devel Nov 25, 2024
60fe96d
refactor: 4๋‹จ๊ณ„ - TDD๋กœ Point ๋ฆฌํŒฉํ† ๋ง
mingulee-devel Nov 28, 2024
b90c25b
refactor: 4๋‹จ๊ณ„ - Point๋ฅผ ๋” ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก first, next, last ์ถ”๊ฐ€
mingulee-devel Nov 29, 2024
1f1fb92
feat: 4๋‹จ๊ณ„ - Cross ์ƒ์„ฑ ๋ฐ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ
mingulee-devel Nov 29, 2024
69de9c9
fix: 4๋‹จ๊ณ„ - next ์กฐ๊ฑด ์ˆ˜์ •
mingulee-devel Dec 1, 2024
73e54c9
fix: 4๋‹จ๊ณ„ - line, ladder ์žฌ ๊ตฌํ˜„
mingulee-devel Dec 1, 2024
e30b8ad
refactor: 4๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ ์ถœ๋ ฅ ์žฌ๊ตฌํ˜„
mingulee-devel Dec 5, 2024
3e6e7fe
refactor: 4๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ ๊ฒฐ๊ณผ ์กฐํšŒ ์ถ”๊ฐ€
mingulee-devel Dec 9, 2024
9b75744
refactor: 4๋‹จ๊ณ„ - ์‚ฌ๋‹ค๋ฆฌ ๊ฒฐ๊ณผ ์ถœ๋ ฅ ์ค‘๊ฐ„ ์ปค๋ฐ‹
mingulee-devel Dec 10, 2024
7a616f8
feat: 4๋‹จ๊ณ„ - Usernames ์ด๋ฆ„ ์ค‘๋ณต ์ฒดํฌ
mingulee-devel Dec 10, 2024
63df125
test: 4๋‹จ๊ณ„ - ladder, point ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ถ”๊ฐ€
mingulee-devel Dec 10, 2024
b5ce392
fix: 4๋‹จ๊ณ„ - all ๊ฒฐ๊ณผ๊ฐ’ ์˜ค๋ฅ˜ ์ˆ˜์ • ์ค‘ ์ค‘๊ฐ„ ์ปค๋ฐ‹
mingulee-devel Dec 11, 2024
68817af
fix: 4๋‹จ๊ณ„ - ๊ฒฐ๊ณผ๊ฐ’ ์˜ค๋ฅ˜ ์ˆ˜์ • ์™„๋ฃŒ
mingulee-devel Dec 14, 2024
61947be
refactor: 4๋‹จ๊ณ„ - ๋ถˆํ•„์š” ์ฝ”๋“œ ์ •๋ฆฌ
mingulee-devel Dec 14, 2024
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
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,54 @@
- [x] ์‚ฌ๋‹ค๋ฆฌ ๋†’์ด๋งŒํผ ๋ฐ˜๋ณต

- ๊ฒฐ๊ณผ
- [x] ์‚ฌ๋žŒ๋ณ„ ์‚ฌ๋‹ค๋ฆฌ๊ฒŒ์ž„ ๊ฒฐ๊ณผ
- [x] ์‚ฌ๋žŒ๋ณ„ ์‚ฌ๋‹ค๋ฆฌ๊ฒŒ์ž„ ๊ฒฐ๊ณผ


---

TDD๋กœ ๊ตฌํ˜„

๋„๋ฉ”์ธ
1. point
current, right
๋‘˜๋‹ค true์ผ ์ˆ˜๋Š” ์—†์Œ
current > left๋กœ ์ด๋™
right > right๋กœ ์ด๋™
๋‘˜๋‹ค false > ๊ทธ๋Œ€๋กœ ์•„๋ž˜๋กœ ์ด๋™

์˜ค๋ฅ˜ ๋ฐฉ์ง€
- ์ฒซ๋ฒˆ์งธ point ์ƒ์„ฑ
- ๋‹ค์Œ point ์ƒ์„ฑ
- ๋งˆ์ง€๋ง‰ point ์ƒ์„ฑ

2. Cross
ํ˜„์žฌ ์œ„์น˜ position
point

move
- right > index+1
- left > index-1
- down > index

- [x] ์ถœ๋ ฅ
- "-----", " "

2. line
crosses

- [x] ์ถœ๋ ฅ
- "|-----| |-----|"

3. ladder
lines

- [x] ์ถœ๋ ฅ
- "|-----| |-----|"
- "| |------| |"
- "|-----| |-----|"

- [x] ๊ฒฐ๊ณผ ์กฐํšŒ


Usernames
- [x] ์ด๋ฆ„ ์ค‘๋ณต ์ฒดํฌ
30 changes: 30 additions & 0 deletions src/main/java/nextstep/ladder/Cross.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package nextstep.ladder;

public class Cross {
private int position;
private Point point;

public Cross(int position, Point point) {
this.position = position;
this.point = point;
}

public int move() {
if(point.move() == Direction.RIGHT) {
return position + 1;
} else if(point.move() == Direction.LEFT) {
return position - 1;
}

return position;
}

public String getCrossForPrint(String trueSymbol, String falseSymbol) {
if(point.move() == Direction.RIGHT) {
return trueSymbol;
}

return falseSymbol;
}

}
7 changes: 7 additions & 0 deletions src/main/java/nextstep/ladder/Direction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nextstep.ladder;

public enum Direction {
LEFT,
RIGHT,
DOWN;
}
67 changes: 28 additions & 39 deletions src/main/java/nextstep/ladder/Ladder.java
Original file line number Diff line number Diff line change
@@ -1,64 +1,53 @@
package nextstep.ladder;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Ladder {
private Usernames usernames;
private Lines lines;
private List<String> results;
private static final String LADDER_DELIMITER = "\n";

public Ladder(Usernames usernames, Lines lines, List<String> results) {
this.usernames = usernames;
this.lines = lines;
this.results = results;
}
private List<Line> lines;

public String getResultsForPrint() {
return results.stream()
.map(d -> String.format("%-6s", d))
.collect(Collectors.joining());
public Ladder(int countOfPerson, int height) {
this.lines = createLines(countOfPerson, height);
}

public String getLadderForPrint(String trueSymbol, String falseSymbol) {
return String.join("\n",
usernames.toString(),
lines.toString(trueSymbol, falseSymbol),
getResultsForPrint()
);
public Ladder(List<Line> lines) {
this.lines = new ArrayList<>(lines);
}

public String getResult(String resultUsername) {
if ("all".equals(resultUsername)) {
return getAllResult();
private List<Line> createLines(int countOfPerson, int height) {
List<Line> nLines = new ArrayList<>();

for (int i = 0; i < height; i++) {
nLines.add(new Line(countOfPerson));
}

return getResultByUsername(resultUsername);
return nLines;
}

private Map<String, String> getResultMap() {
Map<String, String> result = IntStream.range(0, usernames.size())
.boxed()
.collect(Collectors.toMap(
i -> usernames.getValues().get(i).getUsername(),
i -> results.get(lines.getPersonFinalResultIndex(i))
));

return result;
public int move(int position) {
int index = position;
for (Line line : lines) {
index = line.move(index);
}
return index;
}

private String getAllResult() {
Map<String, String> resultMap = getResultMap();

return resultMap.entrySet()
.stream()
.map(d -> d.getKey() + " : " + d.getValue()).collect(Collectors.joining("\n"));
public String getLadderForPrint(String trueSymbol, String falseSymbol) {
return lines.stream()
.map(line -> line.getLineForPrint(trueSymbol, falseSymbol))
.collect(Collectors.joining(LADDER_DELIMITER));
}

private String getResultByUsername(String resultUsername) {
return getResultMap().get(resultUsername);
//todo lines.get(0).getCrossSize()
public Map<Integer, Integer> getAllResult() {
return IntStream.range(0, lines.get(0).getCrossSize())
.boxed()
.collect(Collectors.toMap(i -> i, i -> move(i)));
}

}
6 changes: 4 additions & 2 deletions src/main/java/nextstep/ladder/LadderMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public static void main(String[] args) {
if (usernames.size() != results.size()) {
throw new IllegalArgumentException("์ฐธ์—ฌํ•  ์‚ฌ๋žŒ ์ˆ˜์™€ ์ž…๋ ฅํ•œ ์‹คํ–‰ ๊ฒฐ๊ณผ์˜ ์ˆ˜๊ฐ€ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.");
}
Ladder ladder = new Ladder(usernames, new Lines(InputView.inputHeight(), usernames.size()), results);
Ladder ladder = new Ladder(usernames.size(), InputView.inputHeight());
ResultView.printUsernames(usernames);
ResultView.printLadder(ladder);
ResultView.printResults(results);

String resultUserName = InputView.inputResultUserName();
ResultView.printResult(ladder.getResult(resultUserName));
ResultView.printResult(resultUserName, usernames, ladder, results);
}
}
54 changes: 43 additions & 11 deletions src/main/java/nextstep/ladder/Line.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,59 @@
package nextstep.ladder;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class Line {
private Points points;
private static final Random RANDOM = new Random();
private static final String LINE_DELIMITER = "|";

private List<Cross> crosses;

public Line(int countOfPerson) {
points = new Points(countOfPerson);
createCrosses(countOfPerson);
}

public Line(List<Cross> crosses) {
this.crosses = crosses;
}

public Line(Points points) {
this.points = points;
private void createCrosses(int countOfPerson) {
crosses = new ArrayList<>();

Point point = Point.first(RANDOM.nextBoolean());
for (int i = 0; i < countOfPerson; i++) {
point = updatePoint(i, countOfPerson, point);
crosses.add(new Cross(i, point));
}
}

public String toString(String trueSymbol, String falseSymbol) {
return points.toString(trueSymbol, falseSymbol);
private Point updatePoint(int index, int countOfPerson, Point currentPoint) {
if (index == countOfPerson - 1) {
return currentPoint.last();
}
if (index > 0) {
return currentPoint.next(RANDOM.nextBoolean());
}
return currentPoint;
}

public Integer getResultIndex(int index) {
return points.getResultIndex(index);
//todo
public int move(int position) {
return this.crosses.get(position).move();
}

@Override
public String toString() {
return points.toString();
//todo
public int getCrossSize() {
return crosses.size();
}

public String getLineForPrint(String trueSymbol, String falseSymbol) {
return LINE_DELIMITER
+ crosses.stream()
.map(cross -> cross.getCrossForPrint(trueSymbol, falseSymbol))
.collect(Collectors.joining(LINE_DELIMITER));
}

}
47 changes: 0 additions & 47 deletions src/main/java/nextstep/ladder/Lines.java

This file was deleted.

39 changes: 24 additions & 15 deletions src/main/java/nextstep/ladder/Point.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package nextstep.ladder;

public class Point {
private boolean left;
private boolean current;
private boolean right;

public Point(boolean left, boolean right) {
this.left = left;
public Point(boolean current, boolean right) {
if (current && right) {
throw new IllegalArgumentException("์œ ํšจํ•˜์ง€ ์•Š์€ ๊ฐ’์ž…๋‹ˆ๋‹ค.");
}
this.current = current;
this.right = right;
}

public boolean getRight() {
return right;
public static Point first(boolean right) {
return new Point(false, right);
}

public String getLineSymbol(String trueSymbol, String falseSymbol) {
return right ? trueSymbol : falseSymbol;
public Point next(boolean right) {
if (this.right) {
return new Point(this.right, false);
}
return new Point(this.right, right);
}

public int getResultIndex(int index) {
return left ? index - 1 : (right ? index + 1 : index);
public Point last() {
return new Point(this.right, false);
}

@Override
public String toString() {
return "Point{" +
"left=" + left +
", right=" + right +
'}';
public Direction move() {
if (current) {
return Direction.LEFT;
}
if (right) {
return Direction.RIGHT;
}

return Direction.DOWN;
}
}
Loading