-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[2단계 - 자동차 경주 리팩토링] 에버(손채영) 미션 제출합니다. #791
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3320a7b
refactor: 메시지리졸버 클래스가 출력뷰 클래스 내에서 생성되도록 구조 변경
helenason 6fa6d13
refactor: 자동차의 이동 상태 출력문 리졸브 함수 제거
helenason 272a2fc
refactor: 클래스 내 인스턴수 변수 접근 방법 통일
helenason 695a0e0
test: 원시값 포장 객체에 대한 클래스 생성
helenason b464be8
refactor: 랜덤 숫자 생성 방법 변경
helenason 5cf1bfa
refactor: 문자열을 정수로 파싱하는 메서드 반복 코드 제거
helenason deb7530
refactor: 파워 범위 체크 메서드 파워매니저로 책임 이동
helenason fd8d691
test: 파워매니저 테스트 파워의 범위를 체크하는 메서드 추가
helenason 7a8b2d1
feat: 자동차 이름의 길이가 0인 경우 예외 처리 추가
helenason 383e9c6
refactor: 랜덤 숫자를 생성하고 범위를 체크하는 메서드명에서 비즈니스 로직 숨기기
helenason 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
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package domain; | ||
|
||
import java.util.Random; | ||
|
||
public class PowerManager { | ||
|
||
private static final Integer MIN = 0; | ||
private static final Integer MAX = 9; | ||
private static final Integer THRESHOLD = 4; | ||
|
||
public Integer generatePower() { | ||
Random random = new Random(); | ||
return random.nextInt(MAX - MIN + 1); | ||
} | ||
|
||
public boolean isSufficientPower(int power) { | ||
return THRESHOLD <= power; | ||
} | ||
} |
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
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
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,27 @@ | ||
package domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
public class CarNameTest { | ||
|
||
@DisplayName("자동차 이름이 5자가 넘지 않을 경우 정상적으로 도메인이 생성된다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {"1", "4444", "55555"}) | ||
void createByValidNameLength(String name) { | ||
assertThatCode(() -> CarName.from(name)) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@DisplayName("자동차 이름이 5자 초과 또는 0자 이하일 경우 에러가 발생한다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {"", "666666"}) | ||
void createByInvalidNameLength(String name) { | ||
assertThatThrownBy(() -> CarName.from(name)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
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,27 @@ | ||
package domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
public class PositionTest { | ||
|
||
@DisplayName("자동차 위치가 음수가 아닐 경우 정상적으로 도메인이 생성된다.") | ||
@ParameterizedTest | ||
@ValueSource(ints = {0, 1, 999}) | ||
void createByValidNameLength(int position) { | ||
assertThatCode(() -> Position.from(position)) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@DisplayName("자동차 위치가 음수인 경우 에러가 발생한다.") | ||
@ParameterizedTest | ||
@ValueSource(ints = {-999, -2, -1}) | ||
void createByInvalidNameLength(int position) { | ||
assertThatThrownBy(() -> Position.from(position)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.RepeatedTest; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
@DisplayName("범위 난수 생성 테스트") | ||
class PowerManagerTest { | ||
|
||
@DisplayName("생성된 난수는 지정된 범위를 벗어나지 않는다") | ||
@RepeatedTest(50) | ||
void testRangeOfRandomNumber() { | ||
PowerManager powerManager = new PowerManager(); | ||
int randomNumber = powerManager.generatePower(); | ||
assertThat(randomNumber).isBetween(0, 9); | ||
} | ||
|
||
@DisplayName("생성된 파워가 임계값 이상인 경우 파워는 충분하다.") | ||
@ParameterizedTest | ||
@ValueSource(ints = {4, 5, 9}) | ||
void testSufficiencyOfValidPower(int power) { | ||
PowerManager powerManager = new PowerManager(); | ||
assertThat(powerManager.isSufficientPower(power)).isTrue(); | ||
} | ||
|
||
@DisplayName("생성된 파워가 임계값 미만인 경우 파워는 충분하지 않다.") | ||
@ParameterizedTest | ||
@ValueSource(ints = {0, 1, 3}) | ||
void testSufficiencyOfInvalidPower(int power) { | ||
PowerManager powerManager = new PowerManager(); | ||
assertThat(powerManager.isSufficientPower(power)).isFalse(); | ||
} | ||
} |
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.
PowerManager 👍🏻
객체 책임을 분리한 덕분에 랜덤 값에 대한 테스트가 가능해졌네요!
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.
맞습니다 랜덤 값 테스트를 위해 많이 고민해보았어요.
저의 설계에 100%의 확신이 없었는데 확신이 생겼네요 감사합니다 😊