-
Notifications
You must be signed in to change notification settings - Fork 1
Pipeline tests #3
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
425ac87
Add unit tests for eight untested core classes
aaronbrethorst 3c0038b
Add Block, Trip, StopPath fixture-based unit tests
aaronbrethorst 97b4d15
Scaffold transitclockPipelineTests module with Core harness
aaronbrethorst 3e242f7
Add AvlProcessorBehaviorTest with real-Core harness
aaronbrethorst 61f83e4
add settings.local.json to gitignore
aaronbrethorst 87287d3
Fix critical issues from PR review
aaronbrethorst 1fd5ae5
Address important items from PR review
aaronbrethorst 23aa2c4
Polish nits from PR review
aaronbrethorst 8751210
Document pipeline tests in README, CLAUDE.md, and wire them into CI
aaronbrethorst 61f2401
Address PR review feedback on pipeline tests
aaronbrethorst 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ | |
| /.settings/ | ||
| .DS_Store | ||
|
|
||
| settings.local.json | ||
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
96 changes: 96 additions & 0 deletions
96
transitclock/src/test/java/org/transitclock/core/VehicleAtStopInfoTest.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,96 @@ | ||
| package org.transitclock.core; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * VehicleAtStopInfo is a thin Indices subclass whose entire purpose is to | ||
| * (a) pin the segmentIndex to 0 and (b) carry "at a stop" semantics for the | ||
| * vehicle-state machine. Both constructor forms and the getClass()-based | ||
| * equality with Indices are the behaviors worth locking down here. | ||
| * | ||
| * The methods that dereference the Block (toString, getStopId, atEndOfBlock) | ||
| * require a fully-wired Block+Trip+StopPath graph and are exercised via the | ||
| * integration tests. These unit tests stick to the null-block branch, mirroring | ||
| * IndicesTest. | ||
| */ | ||
| public class VehicleAtStopInfoTest { | ||
|
|
||
| @Test | ||
| public void blockConstructorForcesSegmentIndexToZero() { | ||
| VehicleAtStopInfo info = new VehicleAtStopInfo(null, 2, 5); | ||
| assertEquals(2, info.getTripIndex()); | ||
| assertEquals(5, info.getStopPathIndex()); | ||
| assertEquals(0, info.getSegmentIndex()); | ||
| assertNull(info.getBlock()); | ||
| } | ||
|
|
||
| @Test | ||
| public void indicesConstructorCopiesFieldsAndForcesSegmentIndexToZero() { | ||
| // Source Indices has a non-zero segment index. VehicleAtStopInfo | ||
| // deliberately drops that — once we know a vehicle is at a stop the | ||
| // segment offset within the stop path is no longer meaningful. | ||
| Indices source = new Indices(null, 2, 5, 7); | ||
| VehicleAtStopInfo info = new VehicleAtStopInfo(source); | ||
| assertEquals(2, info.getTripIndex()); | ||
| assertEquals(5, info.getStopPathIndex()); | ||
| assertEquals(0, info.getSegmentIndex()); | ||
| assertNull(info.getBlock()); | ||
| } | ||
|
|
||
| @Test | ||
| public void bothConstructorFormsProduceEquivalentInstances() { | ||
| VehicleAtStopInfo fromBlock = new VehicleAtStopInfo(null, 3, 4); | ||
| VehicleAtStopInfo fromIndices = | ||
| new VehicleAtStopInfo(new Indices(null, 3, 4, 0)); | ||
| // Indices defines equals() but not hashCode(), so two equal instances | ||
| // won't have matching hash codes. Only assert logical equality here. | ||
| assertEquals(fromBlock, fromIndices); | ||
| } | ||
|
|
||
| @Test | ||
| public void vehicleAtStopInfoNotEqualToPlainIndicesWithSameFields() { | ||
| // Indices.equals uses getClass()-based comparison, so subclass | ||
| // instances never compare equal to base-class instances even when | ||
| // the fields all match. This keeps different kinds of indices from | ||
| // colliding in sets/maps. | ||
| VehicleAtStopInfo sub = new VehicleAtStopInfo(null, 1, 2); | ||
| Indices base = new Indices(null, 1, 2, 0); | ||
| assertFalse(sub.equals(base)); | ||
| assertFalse(base.equals(sub)); | ||
| } | ||
|
|
||
| @Test | ||
| public void twoVehicleAtStopInfosWithSameFieldsAreEqual() { | ||
| VehicleAtStopInfo a = new VehicleAtStopInfo(null, 1, 2); | ||
| VehicleAtStopInfo b = new VehicleAtStopInfo(null, 1, 2); | ||
| assertTrue(a.equals(b)); | ||
| } | ||
|
|
||
| @Test | ||
| public void differentStopPathIndexMakesInstancesUnequal() { | ||
| VehicleAtStopInfo a = new VehicleAtStopInfo(null, 1, 2); | ||
| VehicleAtStopInfo b = new VehicleAtStopInfo(null, 1, 3); | ||
| assertFalse(a.equals(b)); | ||
| } | ||
|
|
||
| @Test | ||
| public void differentTripIndexMakesInstancesUnequal() { | ||
| VehicleAtStopInfo a = new VehicleAtStopInfo(null, 1, 2); | ||
| VehicleAtStopInfo b = new VehicleAtStopInfo(null, 5, 2); | ||
| assertFalse(a.equals(b)); | ||
| } | ||
|
|
||
| @Test | ||
| public void segmentIndexIgnoredInSource() { | ||
| // Even if the source Indices has a huge segment index, the derived | ||
| // VehicleAtStopInfo normalizes it to 0. | ||
| Indices source = new Indices(null, 0, 0, 999); | ||
| VehicleAtStopInfo info = new VehicleAtStopInfo(source); | ||
| assertEquals(0, info.getSegmentIndex()); | ||
| } | ||
| } |
140 changes: 140 additions & 0 deletions
140
transitclock/src/test/java/org/transitclock/db/structs/ArrivalDepartureSubclassesTest.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,140 @@ | ||
| package org.transitclock.db.structs; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertSame; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.util.Date; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * Arrival and Departure are tiny wrappers over ArrivalDeparture that exist | ||
| * solely to pin the isArrival flag and (for Arrival) to expose a | ||
| * withUpdatedTime copy. Their value is precisely that distinction, so these | ||
| * tests verify the isArrival/isDeparture discrimination and getter delegation. | ||
| * | ||
| * The configRev-taking constructors are used throughout so the tests don't | ||
| * depend on a running Core (the other constructor form fetches configRev via | ||
| * Core.getInstance()). Passing a null Block keeps the tests free of the | ||
| * Hibernate/Trip/StopPath graph — the base constructor short-circuits most | ||
| * derived-field computation when block is null. | ||
| */ | ||
| public class ArrivalDepartureSubclassesTest { | ||
|
|
||
| private static final int CONFIG_REV = 7; | ||
| private static final String VEHICLE_ID = "v1"; | ||
|
|
||
| private static Date time(long millis) { | ||
| return new Date(millis); | ||
| } | ||
|
|
||
| @Test | ||
| public void arrivalHasIsArrivalTrue() { | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, null); | ||
| assertTrue(a.isArrival()); | ||
| assertFalse(a.isDeparture()); | ||
| } | ||
|
|
||
| @Test | ||
| public void departureHasIsArrivalFalse() { | ||
| Departure d = new Departure(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, null); | ||
| assertFalse(d.isArrival()); | ||
| assertTrue(d.isDeparture()); | ||
| } | ||
|
|
||
| @Test | ||
| public void arrivalExposesConstructorFields() { | ||
| Date t = time(2_000_000); | ||
| Date avl = time(1_998_000); | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, t, avl, null, 3, 5, null); | ||
| assertEquals(VEHICLE_ID, a.getVehicleId()); | ||
| assertEquals(CONFIG_REV, a.getConfigRev()); | ||
| assertEquals(t, a.getDate()); | ||
| assertEquals(t.getTime(), a.getTime()); | ||
| assertSame(avl, a.getAvlTime()); | ||
| assertEquals(3, a.getTripIndex()); | ||
| assertEquals(5, a.getStopPathIndex()); | ||
| assertNull(a.getFreqStartTime()); | ||
| } | ||
|
|
||
| @Test | ||
| public void departureExposesConstructorFields() { | ||
| Date t = time(2_000_000); | ||
| Date avl = time(1_998_000); | ||
| Departure d = new Departure(CONFIG_REV, VEHICLE_ID, t, avl, null, 4, 2, null); | ||
| assertEquals(VEHICLE_ID, d.getVehicleId()); | ||
| assertEquals(CONFIG_REV, d.getConfigRev()); | ||
| assertEquals(t, d.getDate()); | ||
| assertEquals(t.getTime(), d.getTime()); | ||
| assertSame(avl, d.getAvlTime()); | ||
| assertEquals(4, d.getTripIndex()); | ||
| assertEquals(2, d.getStopPathIndex()); | ||
| } | ||
|
|
||
| @Test | ||
| public void freqStartTimeRoundTrips() { | ||
| Date freqStart = time(500_000); | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, freqStart); | ||
| assertSame(freqStart, a.getFreqStartTime()); | ||
|
|
||
| Departure d = new Departure(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, freqStart); | ||
| assertSame(freqStart, d.getFreqStartTime()); | ||
| } | ||
|
|
||
| @Test | ||
| public void nullBlockResultsInNullBlockAndDefaultFields() { | ||
| // When block is null the base constructor takes the short-circuit | ||
| // branch: no derived fields (stopId/routeId/etc.) are populated. | ||
| // This test pins that behavior so we notice if the null-block branch | ||
| // ever starts resolving those fields differently. | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, null); | ||
| assertNull(a.getBlock()); | ||
| assertEquals("", a.getStopId()); | ||
| assertEquals("", a.getTripId()); | ||
| assertEquals("", a.getServiceId()); | ||
| assertNull(a.getScheduledDate()); | ||
| assertEquals(0f, a.getStopPathLength(), 0.0f); | ||
| assertEquals(Integer.valueOf(0), a.getStopOrder()); | ||
| } | ||
|
|
||
| @Test | ||
| public void arrivalAndDepartureAreNotEqualEvenWithSameFields() { | ||
| // ArrivalDeparture.equals() includes the isArrival flag, so an | ||
| // Arrival and a Departure built from the same fields must differ. | ||
| Date t = time(1_000_000); | ||
| Date avl = time(999_000); | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, t, avl, null, 0, 1, null); | ||
| Departure d = new Departure(CONFIG_REV, VEHICLE_ID, t, avl, null, 0, 1, null); | ||
| assertFalse(a.equals(d)); | ||
| assertFalse(d.equals(a)); | ||
| } | ||
|
|
||
| @Test | ||
| public void twoArrivalsWithSameFieldsAreEqual() { | ||
| Date t = time(1_000_000); | ||
| Date avl = time(999_000); | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, t, avl, null, 0, 1, null); | ||
| Arrival b = new Arrival(CONFIG_REV, VEHICLE_ID, t, avl, null, 0, 1, null); | ||
| assertEquals(a, b); | ||
| assertEquals(a.hashCode(), b.hashCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void toStringDistinguishesArrivalAndDeparture() { | ||
| Arrival a = new Arrival(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, null); | ||
| Departure d = new Departure(CONFIG_REV, VEHICLE_ID, time(1_000_000), | ||
| time(999_000), null, 0, 1, null); | ||
| // Base class toString starts with "Arrival " or "Departure". | ||
| assertTrue(a.toString().startsWith("Arrival")); | ||
| assertTrue(d.toString().startsWith("Departure")); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.