-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: add tests for scheduled points
- Loading branch information
1 parent
2a50f05
commit 07fa0ad
Showing
3 changed files
with
118 additions
and
0 deletions.
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
64 changes: 64 additions & 0 deletions
64
core/src/test/java/fr/sncf/osrd/standalone_sim/StandaloneSimTests.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,64 @@ | ||
package fr.sncf.osrd.standalone_sim; | ||
|
||
import static fr.sncf.osrd.standalone_sim.StandaloneSim.generateAllowanceFromScheduledPoints; | ||
|
||
import fr.sncf.osrd.envelope.Envelope; | ||
import fr.sncf.osrd.envelope.part.EnvelopePart; | ||
import fr.sncf.osrd.train.ScheduledPoint; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import java.util.ArrayList; | ||
|
||
public class StandaloneSimTests { | ||
@Test | ||
public void generateAllowanceFromOneScheduledPoint() { | ||
var envelopeFloor = Envelope.make(EnvelopePart.generateTimes( | ||
new double[] {0, 1, 2, 3, 4, 5, 6}, | ||
new double[] {1, 1, 1, 1, 1, 1, 1} | ||
)); | ||
var scheduledPoints = new ArrayList<ScheduledPoint>(); | ||
scheduledPoints.add(new ScheduledPoint(2, 5)); | ||
var allowanceOpt = generateAllowanceFromScheduledPoints(envelopeFloor, scheduledPoints); | ||
Assertions.assertFalse(allowanceOpt.isEmpty()); | ||
var allowance = allowanceOpt.get(); | ||
Assertions.assertEquals(allowance.ranges.size(), 1); | ||
var rangeAllowance = allowance.ranges.get(0); | ||
Assertions.assertEquals(0., rangeAllowance.beginPos, 0.0001); | ||
Assertions.assertEquals(2., rangeAllowance.endPos, 0.0001); | ||
Assertions.assertEquals(3., rangeAllowance.value.getAllowanceTime(2., 2.), 0.0001); | ||
} | ||
|
||
@Test | ||
public void generateAllowanceFromMultipleScheduledPoints() { | ||
var envelopeFloor = Envelope.make(EnvelopePart.generateTimes( | ||
new double[] {0, 1, 2, 3, 4, 5, 6}, | ||
new double[] {1, 1, 1, 1, 1, 1, 1} | ||
)); | ||
var scheduledPoints = new ArrayList<ScheduledPoint>(); | ||
scheduledPoints.add(new ScheduledPoint(2, 5)); | ||
scheduledPoints.add(new ScheduledPoint(4, 12)); | ||
var allowanceOpt = generateAllowanceFromScheduledPoints(envelopeFloor, scheduledPoints); | ||
Assertions.assertFalse(allowanceOpt.isEmpty()); | ||
var allowance = allowanceOpt.get(); | ||
Assertions.assertEquals(allowance.ranges.size(), 2); | ||
var rangeAllowance = allowance.ranges.get(0); | ||
Assertions.assertEquals(0., rangeAllowance.beginPos, 0.0001); | ||
Assertions.assertEquals(2., rangeAllowance.endPos, 0.0001); | ||
Assertions.assertEquals(3., rangeAllowance.value.getAllowanceTime(2., 2.), 0.0001); | ||
rangeAllowance = allowance.ranges.get(1); | ||
Assertions.assertEquals(2., rangeAllowance.beginPos, 0.0001); | ||
Assertions.assertEquals(4., rangeAllowance.endPos, 0.0001); | ||
Assertions.assertEquals(5., rangeAllowance.value.getAllowanceTime(2., 2.), 0.0001); | ||
} | ||
|
||
@Test | ||
public void generateAllowanceFromNoScheduledPoints() { | ||
var envelopeFloor = Envelope.make(EnvelopePart.generateTimes( | ||
new double[] {0, 1, 2, 3, 4, 5, 6}, | ||
new double[] {1, 1, 1, 1, 1, 1, 1} | ||
)); | ||
var scheduledPoints = new ArrayList<ScheduledPoint>(); | ||
var allowanceOpt = generateAllowanceFromScheduledPoints(envelopeFloor, scheduledPoints); | ||
Assertions.assertTrue(allowanceOpt.isEmpty()); | ||
} | ||
} |