-
Notifications
You must be signed in to change notification settings - Fork 203
๐ 2๋จ๊ณ - ์๊ธ ์กฐํ #399
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
kimj2su
wants to merge
6
commits into
next-step:jisu3316
Choose a base branch
from
kimj2su:step2
base: jisu3316
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
329b730
1๋จ๊ณ ์ฝ๋ฉํธ ๋ฐ์
kimj2su 09e7218
์ธ์ ์กฐ๊ฑด ์ ์ ๋ฐ ๋ฌธ์ํ ์์ฑ
kimj2su 138304e
์๊ธ ๋๋ฉ์ธ ์์ฑ ๋ฐ ๋จ์ ํ
์คํธ ์์ฑ
kimj2su 69c7628
์๊ธ ๊ณ์ฐ ๋ฐฉ๋ฒ ์์
kimj2su 61d1b68
์๊ธ ๊ณ์ฐ ์ธ์ ํ
์คํธ ์์ฑ
kimj2su 6103db5
2๋จ๊ณ ๋ฆฌ๋ทฐ ๋ฐ์
kimj2su 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
7 changes: 7 additions & 0 deletions
7
src/main/java/nextstep/subway/constant/EdgeWeightFunction.java
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,7 @@ | ||
package nextstep.subway.constant; | ||
|
||
@FunctionalInterface | ||
public interface EdgeWeightFunction<EdgeWeight, Integer> { | ||
Integer apply(EdgeWeight section); | ||
|
||
} |
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
package nextstep.subway.constant; | ||
|
||
import nextstep.subway.domain.Section; | ||
|
||
public enum FindPathType { | ||
DISTANCE("DISTANCE", "๊ฑฐ๋ฆฌ"), | ||
DURATION("DURATION", "์๊ฐ"); | ||
DISTANCE("DISTANCE", Section::getDistance), | ||
DURATION("DURATION", Section::getDuration); | ||
|
||
private final String type; | ||
private final String description; | ||
private final EdgeWeightFunction<Section, Integer> edgeWeightFunction; | ||
|
||
FindPathType(String type, String description) { | ||
FindPathType(String type, EdgeWeightFunction<Section, Integer> edgeWeightFunction) { | ||
this.type = type; | ||
this.description = description; | ||
this.edgeWeightFunction = edgeWeightFunction; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
public Integer getEdgeWeight(Section section) { | ||
return edgeWeightFunction.apply(section); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/nextstep/subway/domain/CalculateFareFacade.java
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,16 @@ | ||
package nextstep.subway.domain; | ||
|
||
public class CalculateFareFacade { | ||
|
||
private final int distance; | ||
|
||
public CalculateFareFacade(int distance) { | ||
this.distance = distance; | ||
} | ||
|
||
public int calculateFare() { | ||
int calculateOverTen = new CalculateOverTen().calculate(distance); | ||
int calculateOverFifty = new CalculateOverFifty().calculate(distance); | ||
return calculateOverTen + calculateOverFifty; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/nextstep/subway/domain/CalculateOverFifty.java
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,13 @@ | ||
package nextstep.subway.domain; | ||
|
||
import static nextstep.subway.domain.Fare.ADDITIONAL_FARE; | ||
|
||
public class CalculateOverFifty { | ||
public int calculate(int distance) { | ||
int overFiftyDistance = distance - 50; | ||
if (overFiftyDistance <= 0) { | ||
return 0; | ||
} | ||
return (int) Math.ceil((double) overFiftyDistance / 8) * ADDITIONAL_FARE; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/nextstep/subway/domain/CalculateOverTen.java
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,13 @@ | ||
package nextstep.subway.domain; | ||
|
||
import static nextstep.subway.domain.Fare.ADDITIONAL_FARE; | ||
import static nextstep.subway.domain.Fare.MAX_OVER_TEN_FARE; | ||
|
||
public class CalculateOverTen { | ||
|
||
public int calculate(int distance) { | ||
int overTenDistance = distance - 10; | ||
int fare = (int) ((Math.ceil((double) overTenDistance / 5)) * ADDITIONAL_FARE); | ||
return Math.min(fare, MAX_OVER_TEN_FARE); | ||
} | ||
} |
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 nextstep.subway.domain; | ||
|
||
public class Fare { | ||
private static final int DEFAULT_DISTANCE = 10; | ||
private static final int BASE_FARE = 1250; | ||
public static final int ADDITIONAL_FARE = 100; | ||
public static final int MAX_OVER_TEN_FARE = 800; | ||
|
||
private int fare; | ||
|
||
public Fare() {} | ||
|
||
public void init(int distance) { | ||
this.fare = generateFare(distance); | ||
} | ||
|
||
public int getFare() { | ||
return fare; | ||
} | ||
|
||
private int generateFare(int distance) { | ||
if (distance <= DEFAULT_DISTANCE) { | ||
return BASE_FARE; | ||
} | ||
int additionalFare = new CalculateFareFacade(distance).calculateFare(); | ||
return BASE_FARE + additionalFare; | ||
} | ||
} |
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
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,56 @@ | ||
package nextstep.subway.unit; | ||
|
||
|
||
import nextstep.subway.domain.Fare; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@DisplayName("์๊ธ ๋จ์ ํ ์คํธ") | ||
class FareTest { | ||
|
||
@DisplayName("๊ธฐ๋ณธ ์๊ธ์ผ๋ ํ ์คํธ") | ||
@Test | ||
void defaultFare() { | ||
// given | ||
int distance = 10; | ||
|
||
// when | ||
Fare fare = new Fare(); | ||
fare.init(distance); | ||
|
||
// then | ||
assertThat(fare.getFare()).isEqualTo(1250); | ||
} | ||
|
||
@DisplayName("10km์ด๊ณผ ~ 50km๊น์ง(5km๋ง๋ค 100์์ฉ ์ถ๊ฐ) ํ ์คํธ") | ||
@ParameterizedTest | ||
@CsvSource(value = {"15:1350","20:1450","25:1550","30:1650","35:1750","40:1850","45:1950","50:2050"}, delimiter = ':') | ||
void additionalFare(int distance, int expectedFare) { | ||
// given | ||
|
||
// when | ||
Fare fare = new Fare(); | ||
fare.init(distance); | ||
|
||
// then | ||
assertThat(fare.getFare()).isEqualTo(expectedFare); | ||
} | ||
|
||
@DisplayName("50km์ด๊ณผ ~ 100km๊น์ง(8km๋ง๋ค 100์์ฉ ์ถ๊ฐ) ํ ์คํธ") | ||
@ParameterizedTest | ||
@CsvSource(value = {"51:2150","59:2250","66:2250","67:2350","75:2450","83:2550","90:2550","91:2650", "100:2750"}, delimiter = ':') | ||
void additionalFare2(int distance, int expectedFare) { | ||
// given | ||
|
||
// when | ||
Fare fare = new Fare(); | ||
fare.init(distance); | ||
|
||
// then | ||
assertThat(fare.getFare()).isEqualTo(expectedFare); | ||
} | ||
} |
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
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.
์์ฑ์์ ์ด๊ธฐํ ๋น์ฆ๋์ค๋ก์ง์ด ๋ค์ด๊ฐ๋ ๊ฒ ๋ณด๋ค๋ ๋ง ๊ทธ๋๋ก ์์ฑ์ ํ์ํ ์ต์ํ์ ๋์(๊ฐ ํ ๋น, ์ ํจ์ฑ ๊ฒ์ฆ ์ ๋)๋ง ํด์ฃผ์๋๊ฑธ ๊ถ์ฅ๋๋ ค์.
๊ฐ๋ฐ์ ์ ์ฅ์์ ์์ฑ์ ํธ์ถ์ ์ถ๊ฐ์ ์ธ ๋น์ฆ๋์ค ๋ก์ง์ด ์์ฑ๋ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ๊ธฐ๋ณด๋จ ๋จ์ํ๊ฒ ์ธ์คํด์ค ์์ฑ์ด ๋ ๊ฒ ์ ๋๋ง ์ ์ถ๋ฅผ ํ ์ ์์ฃ . ๊ทธ๋์ ์ด๋ฐ ๋ก์ง๋ค์ด ์ถ๊ฐ๋ ๊ฒฝ์ฐ๋ฅผ ๊ณ ๋ คํด ์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๊ฑฐ๋
๋ณ๋์ init๋ฉ์๋๋ฅผ ๋ช ์์ ์ผ๋ก ํธ์ถํ๋๋ก ํ๊ณ ์์ต๋๋ค!