-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Step5] 자동차경주(리팩토링) 코드리뷰, 라이브 강의 피드백 적용 #5482
Open
kbzz17
wants to merge
8
commits into
next-step:kbzz17
Choose a base branch
from
kbzz17:step4
base: kbzz17
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+215
−160
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
aad85b9
[refactor] CarName 클래스 getter 메소드로 변경
kbzz17 7f51880
[refactor] RacingCar 출력내용 변경으로 인한 테스트 변경
kbzz17 6512ab8
[feat] Location Class 구현 및 테스트
kbzz17 fde4c08
[refactor] RacingCar Class에 Location Class 적용
kbzz17 4f33953
[refactor] Equals, Hashcode 추가
kbzz17 ae8bde4
[feat] RacingRule 추상화 및 RandomRacingRule 구현
kbzz17 cb097fe
[refactor] 사용하지 않는 클래스 삭제
kbzz17 9f2005e
[refactor] 객체간의 메세지를 통한 가장 멀리 있는 위치 값 찾는 로직 수정
kbzz17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package racingCar; | ||
|
||
import java.util.Objects; | ||
|
||
public class Location { | ||
|
||
private final static int MIN_LIMIT = 0; | ||
private int location; | ||
|
||
public Location(){ | ||
this.location = MIN_LIMIT; | ||
} | ||
|
||
public Location(int location) { | ||
validLocation(location); | ||
this.location = location; | ||
} | ||
|
||
public void increase(){ | ||
location++; | ||
} | ||
|
||
private void validLocation(int location) { | ||
if(location < MIN_LIMIT){ | ||
throw new IllegalArgumentException("위치 값은 음수일 수 없습니다."); | ||
} | ||
} | ||
|
||
public int getLocation() { | ||
return location; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Location location1 = (Location) o; | ||
return location == location1.location; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(location); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,71 @@ | ||
package racingCar; | ||
|
||
import java.util.Objects; | ||
|
||
public class RacingCar { | ||
|
||
private static final int START_LOCATION = 0; | ||
private CarName name; | ||
private int location; | ||
private Location location; | ||
|
||
public RacingCar() { | ||
this.location = START_LOCATION; | ||
this.location = new Location(); | ||
} | ||
|
||
public RacingCar(CarName name) { | ||
this.name = name; | ||
this.location = START_LOCATION; | ||
this.location = new Location(); | ||
} | ||
|
||
public RacingCar(CarName name, Location location) { | ||
this.name = name; | ||
this.location = location; | ||
} | ||
|
||
public int findCurrentLocation() { | ||
return this.location; | ||
return this.location.getLocation(); | ||
} | ||
|
||
public boolean isSameLocation(int location) { | ||
return findCurrentLocation() == location; | ||
} | ||
|
||
public int compareMaxDistance(int distance) { | ||
return Math.max(findCurrentLocation(), distance); | ||
} | ||
|
||
public CarName findCarName(){ | ||
return this.name; | ||
public String findCarName() { | ||
return this.name.getName(); | ||
} | ||
|
||
public void move(boolean isMovable) { | ||
if (isMovable) { | ||
this.location++; | ||
this.location.increase(); | ||
} | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
return sb.append(name.findName()) | ||
return sb.append(findCarName()) | ||
.append(" : ") | ||
.append("-".repeat(Math.max(0, location))) | ||
.append("-".repeat(Math.max(0, location.getLocation()))) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
RacingCar racingCar = (RacingCar) o; | ||
return Objects.equals(name, racingCar.name) && Objects.equals(location, | ||
racingCar.location); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, location); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,47 @@ | ||
package racingCar; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class RacingCars { | ||
|
||
private final List<RacingCar> cars; | ||
|
||
private RacingRule rule; | ||
|
||
public RacingCars(List<RacingCar> cars) { | ||
this.cars = cars; | ||
} | ||
|
||
public RacingCars(List<RacingCar> cars, RacingRule rule) { | ||
this.cars = cars; | ||
this.rule = rule; | ||
} | ||
|
||
public List<RacingCar> findCars() { | ||
return this.cars; | ||
} | ||
|
||
public void moveCars() { | ||
for (RacingCar car : cars) { | ||
car.move(RacingRule.isMovable(RacingRule.generateRandomDistance())); | ||
car.move(rule.isMovable()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
RacingCars that = (RacingCars) o; | ||
return Objects.equals(cars, that.cars) && Objects.equals(rule, that.rule); | ||
} | ||
|
||
public int findFarthestLocation() { | ||
return cars.stream() | ||
.mapToInt(RacingCar::findCurrentLocation) | ||
.max() | ||
.getAsInt(); | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(cars, rule); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,5 @@ | ||
package racingCar; | ||
|
||
import java.util.Random; | ||
|
||
public class RacingRule { | ||
public static int MOVABLE_STANDARD = 4; | ||
public static int RANDOM_STANDARD = 10; | ||
|
||
private static final Random random = new Random(); | ||
|
||
public static boolean isMovable(int distance) { | ||
return distance >= MOVABLE_STANDARD; | ||
} | ||
|
||
public static int generateRandomDistance(){ | ||
return random.nextInt(RANDOM_STANDARD); | ||
} | ||
public interface RacingRule { | ||
boolean isMovable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package racingCar; | ||
|
||
import java.util.Random; | ||
|
||
public class RandomRacingRule implements RacingRule{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
public static int MOVABLE_STANDARD = 4; | ||
public static int RANDOM_STANDARD = 10; | ||
|
||
private static final Random random = new Random(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 상수는 보통 대문자와 밑줄(_)만 사용합니다 |
||
|
||
@Override | ||
public boolean isMovable() { | ||
return generateRandomDistance() >= MOVABLE_STANDARD; | ||
} | ||
|
||
public static int generateRandomDistance(){ | ||
return random.nextInt(RANDOM_STANDARD); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package racingCar; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class LocationTest { | ||
|
||
@Test | ||
@DisplayName("위치 값에 음수가 들어오면 IllegalArgumentException") | ||
void Location_MinusTest() { | ||
Assertions.assertThatThrownBy(()->new Location(-1)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍