-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix(orca-fares): remove fare attributes with no rules #6089
Merged
leonardehrenfried
merged 4 commits into
opentripplanner:dev-2.x
from
ibi-group:orca-remove-ruleless-attributes
Sep 30, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0a95a2d
fix(orca-fares): remove fare attributes with no rules
daniel-heppner-ibigroup feedefe
add tests for FareRuleSet
daniel-heppner-ibigroup 364cf4f
add Javadoc
daniel-heppner-ibigroup 54223b1
replace new hashset with set.of()
daniel-heppner-ibigroup 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
222 changes: 222 additions & 0 deletions
222
src/ext-test/java/org/opentripplanner/ext/fares/FareRuleSetTest.java
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,222 @@ | ||
package org.opentripplanner.ext.fares; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.time.Duration; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.ext.fares.model.FareAttribute; | ||
import org.opentripplanner.ext.fares.model.FareRuleSet; | ||
import org.opentripplanner.transit.model.basic.Money; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
|
||
class FareRuleSetTest { | ||
|
||
private FareRuleSet fareRuleSet; | ||
static final Money TWO_FIFTY = Money.usDollars(2.50f); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
FeedScopedId id = new FeedScopedId("feed", "fare1"); | ||
FareAttribute fareAttribute = FareAttribute | ||
.of(id) | ||
.setPrice(TWO_FIFTY) | ||
.setPaymentMethod(1) | ||
.setTransfers(1) | ||
.setTransferDuration(7200) | ||
.build(); | ||
fareRuleSet = new FareRuleSet(fareAttribute); | ||
} | ||
|
||
@Test | ||
void testHasNoRules() { | ||
assertFalse(fareRuleSet.hasRules()); | ||
} | ||
|
||
@Test | ||
void testAddOriginDestination() { | ||
fareRuleSet.addOriginDestination("A", "B"); | ||
assertTrue(fareRuleSet.hasRules()); | ||
} | ||
|
||
@Test | ||
void testAddRouteOriginDestination() { | ||
fareRuleSet.addRouteOriginDestination("Route1", "A", "B"); | ||
assertTrue(fareRuleSet.hasRules()); | ||
assertEquals(1, fareRuleSet.getRouteOriginDestinations().size()); | ||
} | ||
|
||
@Test | ||
void testAddContains() { | ||
fareRuleSet.addContains("Zone1"); | ||
assertTrue(fareRuleSet.hasRules()); | ||
assertEquals(1, fareRuleSet.getContains().size()); | ||
} | ||
|
||
@Test | ||
void testAddRoute() { | ||
FeedScopedId routeId = new FeedScopedId("feed", "route1"); | ||
fareRuleSet.addRoute(routeId); | ||
assertTrue(fareRuleSet.hasRules()); | ||
assertEquals(1, fareRuleSet.getRoutes().size()); | ||
} | ||
|
||
@Test | ||
void testMatchesWithNoRules() { | ||
var routes = Set.of(new FeedScopedId("feed", "route1")); | ||
var trips = Set.of(new FeedScopedId("feed", "trip1")); | ||
var zones = Set.of("zone1"); | ||
assertTrue( | ||
fareRuleSet.matches("A", "B", Set.of(), Set.of(), Set.of(), 0, Duration.ZERO, Duration.ZERO) | ||
); | ||
assertTrue( | ||
fareRuleSet.matches( | ||
"A", | ||
"B", | ||
zones, | ||
routes, | ||
trips, | ||
0, | ||
Duration.ofMinutes(100), | ||
Duration.ofMinutes(100) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void testMatchesWithOriginDestination() { | ||
fareRuleSet.addOriginDestination("A", "B"); | ||
assertTrue( | ||
fareRuleSet.matches("A", "B", Set.of(), Set.of(), Set.of(), 0, Duration.ZERO, Duration.ZERO) | ||
); | ||
assertFalse( | ||
fareRuleSet.matches("B", "C", Set.of(), Set.of(), Set.of(), 0, Duration.ZERO, Duration.ZERO) | ||
); | ||
} | ||
|
||
@Test | ||
void testMatchesWithContains() { | ||
Set<String> zones = new HashSet<>(); | ||
zones.add("Zone1"); | ||
zones.add("Zone2"); | ||
fareRuleSet.addContains("Zone1"); | ||
fareRuleSet.addContains("Zone2"); | ||
assertTrue( | ||
fareRuleSet.matches("A", "B", zones, Set.of(), Set.of(), 0, Duration.ZERO, Duration.ZERO) | ||
); | ||
assertFalse( | ||
fareRuleSet.matches("A", "B", Set.of(), Set.of(), Set.of(), 0, Duration.ZERO, Duration.ZERO) | ||
); | ||
} | ||
|
||
@Test | ||
void testMatchesWithRoutes() { | ||
Set<FeedScopedId> routes = new HashSet<>(); | ||
FeedScopedId routeId = new FeedScopedId("feed", "route1"); | ||
FeedScopedId otherRouteId = new FeedScopedId("feed", "route2"); | ||
routes.add(routeId); | ||
fareRuleSet.addRoute(routeId); | ||
assertTrue( | ||
fareRuleSet.matches("A", "B", Set.of(), routes, Set.of(), 0, Duration.ZERO, Duration.ZERO) | ||
); | ||
assertFalse( | ||
fareRuleSet.matches( | ||
"A", | ||
"B", | ||
Set.of(), | ||
Set.of(otherRouteId), | ||
Set.of(), | ||
0, | ||
Duration.ZERO, | ||
Duration.ZERO | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void testMatchesWithTransfers() { | ||
assertTrue( | ||
fareRuleSet.matches("A", "B", Set.of(), Set.of(), Set.of(), 1, Duration.ZERO, Duration.ZERO) | ||
); | ||
assertFalse( | ||
fareRuleSet.matches("A", "B", Set.of(), Set.of(), Set.of(), 2, Duration.ZERO, Duration.ZERO) | ||
); | ||
} | ||
|
||
@Test | ||
void testMatchesWithTransferDuration() { | ||
assertTrue( | ||
fareRuleSet.matches( | ||
"A", | ||
"B", | ||
Set.of(), | ||
Set.of(), | ||
Set.of(), | ||
0, | ||
Duration.ofSeconds(7000), | ||
Duration.ZERO | ||
) | ||
); | ||
assertFalse( | ||
fareRuleSet.matches( | ||
"A", | ||
"B", | ||
Set.of(), | ||
Set.of(), | ||
Set.of(), | ||
0, | ||
Duration.ofSeconds(8000), | ||
Duration.ZERO | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void testMatchesWithJourneyDuration() { | ||
FareAttribute journeyFare = FareAttribute | ||
.of(new FeedScopedId("feed", "journey")) | ||
.setPrice(Money.usDollars(3.00f)) | ||
.setPaymentMethod(1) | ||
.setJourneyDuration(7200) | ||
.build(); | ||
FareRuleSet journeyRuleSet = new FareRuleSet(journeyFare); | ||
|
||
assertTrue( | ||
journeyRuleSet.matches( | ||
"A", | ||
"B", | ||
Set.of(), | ||
Set.of(), | ||
Set.of(), | ||
0, | ||
Duration.ZERO, | ||
Duration.ofSeconds(7000) | ||
) | ||
); | ||
assertFalse( | ||
journeyRuleSet.matches( | ||
"A", | ||
"B", | ||
Set.of(), | ||
Set.of(), | ||
Set.of(), | ||
0, | ||
Duration.ZERO, | ||
Duration.ofSeconds(8000) | ||
) | ||
); | ||
} | ||
|
||
@Test | ||
void testAgencyMethods() { | ||
assertFalse(fareRuleSet.hasAgencyDefined()); | ||
assertNull(fareRuleSet.getAgency()); | ||
|
||
FeedScopedId agencyId = new FeedScopedId("feed", "agency1"); | ||
fareRuleSet.setAgency(agencyId); | ||
assertTrue(fareRuleSet.hasAgencyDefined()); | ||
assertEquals(agencyId, fareRuleSet.getAgency()); | ||
} | ||
} |
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
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.
This one needs Javadoc and a test.
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.
Good point, I added tests for this and
matches
.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.
That's a very nice test but where is the Javadoc?
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.
Oops