fix(javaTest): align simulation time semantics
This commit is contained in:
@@ -100,7 +100,8 @@ public final class HistoricalDispatchSimulator {
|
||||
events, traversedEdges);
|
||||
verifyLedger(ledger, invariants);
|
||||
|
||||
boolean awaitingFutureArrival = active.isEmpty() && clearanceMoves.isEmpty()
|
||||
boolean awaitingFutureArrival = queue.size() > 0
|
||||
&& active.isEmpty() && clearanceMoves.isEmpty()
|
||||
&& queue.readyAt(now).isEmpty();
|
||||
if (watchdog.observe(terminal.size(),
|
||||
businessProgress || clearanceProgress.moved || awaitingFutureArrival,
|
||||
@@ -461,7 +462,7 @@ public final class HistoricalDispatchSimulator {
|
||||
ResourceKey edge = ResourceKey.edge(from, to);
|
||||
List<ResourceKey> resources = Arrays.asList(
|
||||
ResourceKey.node(from), edge, ResourceKey.node(to));
|
||||
Instant decisionTime = Instant.EPOCH.plusMillis(now + tick);
|
||||
Instant decisionTime = Instant.EPOCH.plusMillis(now);
|
||||
TrafficVehicleSnapshot frozen = new TrafficVehicleSnapshot(vehicleId,
|
||||
Long.toString(vehicle.getBootId()), tick + 1, tick + 1,
|
||||
decisionTime, from, to,
|
||||
|
||||
@@ -27,15 +27,10 @@ public final class SimulationClock {
|
||||
Collections.sort(ordered);
|
||||
LinkedHashMap<LocalDateTime, Long> converted =
|
||||
new LinkedHashMap<LocalDateTime, Long>();
|
||||
long simulationMillis = 0L;
|
||||
LocalDateTime previous = null;
|
||||
LocalDateTime first = ordered.get(0);
|
||||
for (LocalDateTime arrival : ordered) {
|
||||
if (previous != null) {
|
||||
long sourceGap = Duration.between(previous, arrival).toMillis();
|
||||
simulationMillis += sourceGap / acceleration;
|
||||
}
|
||||
long simulationMillis = Duration.between(first, arrival).toMillis() / acceleration;
|
||||
converted.put(arrival, simulationMillis);
|
||||
previous = arrival;
|
||||
}
|
||||
this.arrivals = Collections.unmodifiableMap(converted);
|
||||
}
|
||||
|
||||
@@ -31,4 +31,17 @@ class SimulationClockTest {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new SimulationClock(Arrays.asList(base), 25));
|
||||
}
|
||||
|
||||
@Test
|
||||
void scalesFromTheFirstArrivalWithoutAccumulatingRoundingLoss() {
|
||||
LocalDateTime base = LocalDateTime.of(2026, 3, 1, 10, 0);
|
||||
LocalDateTime firstGap = base.plusNanos(99_000_000L);
|
||||
LocalDateTime secondGap = base.plusNanos(198_000_000L);
|
||||
|
||||
SimulationClock clock = new SimulationClock(
|
||||
Arrays.asList(base, firstGap, secondGap), 100);
|
||||
|
||||
assertEquals(0L, clock.toSimulationMillis(firstGap));
|
||||
assertEquals(1L, clock.toSimulationMillis(secondGap));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user