forked from next-step/java-racingcar-playground
-
Notifications
You must be signed in to change notification settings - Fork 2
5주차 미션 구현 #8
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
Open
oliviarla
wants to merge
2
commits into
object-oriented-thinking:oliviarla
Choose a base branch
from
oliviarla:oliviarla_Feedback
base: oliviarla
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.
Open
5주차 미션 구현 #8
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
package racingcar.domain; | ||
|
||
import java.util.Objects; | ||
|
||
public class Location{ | ||
private int location; | ||
|
||
public Location() { | ||
this.location=0; | ||
} | ||
public Location(int location) { | ||
this.location = location; | ||
} | ||
|
||
public void forward(){ | ||
this.location++; | ||
} | ||
|
||
public String makeBar(){ | ||
StringBuilder result = new StringBuilder(); | ||
for(int i=0;i<location;i++){ | ||
result.append("-"); | ||
} | ||
return result.toString(); | ||
} | ||
|
||
public boolean isGreaterThan(Location o) { | ||
return this.location > o.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 contains hidden or 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,36 @@ | ||
package racingcar.domain; | ||
|
||
import java.util.Objects; | ||
|
||
public class Name { | ||
private final String name; | ||
private static final int MAX_LENGTH = 5; | ||
|
||
public Name(String name) throws IllegalArgumentException { | ||
if (name==null || name.trim().isEmpty()) { | ||
throw new IllegalArgumentException("자동차 이름은 공백일 수 없습니다."); | ||
} | ||
|
||
if (name.length() >= MAX_LENGTH) { | ||
throw new IllegalArgumentException("자동차 이름은 5글자 이내여야 합니다."); | ||
} | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Name name1 = (Name) o; | ||
return Objects.equals(name, name1.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
package racingcar.domain; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class LocationTest { | ||
Location l1 = new Location(); | ||
Location l2 = new Location(); | ||
|
||
@Test | ||
void forwardTest1(){ | ||
l1.forward(); | ||
l1.forward(); | ||
assertThat(l1).isEqualTo(new Location(2)); | ||
} | ||
|
||
@Test | ||
void forwardTest2(){ | ||
assertThat(l2).isEqualTo(new Location(0)); | ||
} | ||
|
||
@Test | ||
void compareTest(){ | ||
assertThat(new Location(2).isGreaterThan(new Location(0))).isTrue(); | ||
assertThat(new Location(1).isGreaterThan(new Location(2))).isFalse(); | ||
} | ||
} |
This file contains hidden or 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,24 @@ | ||
package racingcar.domain; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
public class NameTest { | ||
@Test | ||
@DisplayName("Name 5글자 이상일 경우 예외 발생 테스트") | ||
void checkValid1(){ | ||
assertThatThrownBy(() -> new Name("giant")).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
@Test | ||
@DisplayName("Name 비어있을 경우 예외 발생 테스트") | ||
void checkValid2(){ | ||
assertThatThrownBy(() -> new Name("")).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
@Test | ||
@DisplayName("Name 비어있을 경우 예외 발생 테스트2") | ||
void checkValid3(){ | ||
assertThatThrownBy(() -> new Name(" ")).isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
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.
Location은 원시 값을 포장한 값 객체처럼 보이는데, 인자를 final로 만들어 immutable 하게 만들면 어떨까요?☺️