Skip to content

Commit

Permalink
Merge pull request #42 from matsim-scenarios/update-tests
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
GregorRyb authored Feb 7, 2024
2 parents 4054f6a + 816f49f commit e1632a1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions src/test/java/org/matsim/run/RunLeipzigIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.matsim.analysis.ParkingLocation;
import org.matsim.api.core.v01.Id;
Expand All @@ -10,67 +11,89 @@
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.network.NetworkUtils;
import org.matsim.simwrapper.SimWrapperConfigGroup;
import org.matsim.testcases.MatsimTestUtils;
import org.matsim.utils.eventsfilecomparison.EventsFileComparator;

import java.io.File;
import java.nio.file.Path;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;

public class RunLeipzigIntegrationTest {

private static final String URL = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v1.2/input/";
private static final String exampleShp = "input/v1.3/drtServiceArea/Leipzig_stadt.shp";

private static final String URL = String.format("https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v%s/input/",
RunLeipzigScenario.VERSION);
private static final String exampleShp = String.format("input/v%s/drtServiceArea/Leipzig_stadt.shp",RunLeipzigScenario.VERSION);

@Rule
public MatsimTestUtils utils = new MatsimTestUtils();

@Test
public final void runPoint1pctIntegrationTest() {
Path output = Path.of("output/it-1pct");

Config config = ConfigUtils.loadConfig("input/v1.3/leipzig-v1.3-10pct.config.xml");
Config config = ConfigUtils.loadConfig(String.format("input/v%s/leipzig-v%s-10pct.config.xml",RunLeipzigScenario.VERSION,RunLeipzigScenario.VERSION));

config.global().setNumberOfThreads(1);
config.qsim().setNumberOfThreads(1);
config.controler().setLastIteration(1);
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controler().setOutputDirectory(output.toString());
config.plans().setInputFile(URL + "leipzig-v1.2-0.1pct.plans-initial.xml.gz");
config.controler().setOutputDirectory(utils.getOutputDirectory());
config.plans().setInputFile(URL + String.format("leipzig-v%s-0.1pct.plans-initial.xml.gz",RunLeipzigScenario.VERSION));

ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--slow-speed-area", exampleShp,
"--slow-speed-relative-change", "0.5","--drt-area", exampleShp, "--post-processing", "disabled"
"--slow-speed-relative-change", "0.5", "--drt-area", exampleShp, "--post-processing", "disabled"
);

assertThat(output)
.exists()
.isNotEmptyDirectory();
assertThat(EventsUtils.compareEventsFiles(
new File(utils.getOutputDirectory(), "leipzig-1pct.output_events.xml.gz").toString(),
new File(utils.getClassInputDirectory(), "runPoint1pctIntegrationTest_events.xml.zst").toString()
)).isEqualTo(EventsFileComparator.Result.FILES_ARE_EQUAL);


Network network = NetworkUtils.readNetwork(output + "/" + config.controler().getRunId() + ".output_network.xml.gz");
Network network = NetworkUtils.readNetwork(utils.getOutputDirectory() + "/" + config.controler().getRunId() + ".output_network.xml.gz");
assertTrue(network.getLinks().get(Id.createLinkId("24232899")).getFreespeed() < 12.501000000000001);
assertTrue(network.getLinks().get(Id.createLinkId("24675139")).getFreespeed() < 7.497);
}

@Test
public final void runPoint1pctParkingIntegrationTest() {
Path output = Path.of("output-parking-test/it-1pct");
Config config = ConfigUtils.loadConfig("input/v1.3/leipzig-v1.3-10pct.config.xml");
String output = utils.getOutputDirectory();

Config config = ConfigUtils.loadConfig(String.format("input/v%s/leipzig-v%s-10pct.config.xml",RunLeipzigScenario.VERSION,RunLeipzigScenario.VERSION));
config.global().setNumberOfThreads(1);
config.qsim().setNumberOfThreads(1);
config.controler().setLastIteration(0);
config.controler().setLastIteration(1);
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controler().setOutputDirectory(output.toString());
config.controler().setOutputDirectory(utils.getOutputDirectory());
ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;
config.plans().setInputFile(URL + "leipzig-v1.2-0.1pct.plans-initial.xml.gz");
config.plans().setInputFile(URL + String.format("leipzig-v%s-0.1pct.plans-initial.xml.gz",RunLeipzigScenario.VERSION));

MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", exampleShp, "--post-processing", "disabled",
"--parking-cost-area", "input/v" + RunLeipzigScenario.VERSION + "/parkingCostArea/Bewohnerparken_2020.shp",
"--parking", "--intermodality", "drtAsAccessEgressForPt");

assertThat(output)
assertThat(Path.of(output))
.exists()
.isNotEmptyDirectory();
new ParkingLocation().execute("--directory", output.toString());

assertThat(EventsUtils.compareEventsFiles(
new File(utils.getOutputDirectory(), "leipzig-1pct.output_events.xml.gz").toString(),
new File(utils.getClassInputDirectory(), "runPoint1pctParkingIntegrationTest_events.xml.zst").toString()
)).isEqualTo(EventsFileComparator.Result.FILES_ARE_EQUAL);


Network network = NetworkUtils.readNetwork(utils.getOutputDirectory() + "/" + config.controler().getRunId() + ".output_network.xml.gz");
assertTrue(network.getLinks().get(Id.createLinkId("24232899")).getFreespeed() < 12.501000000000001);
assertTrue(network.getLinks().get(Id.createLinkId("24675139")).getFreespeed() < 7.497);

new ParkingLocation().execute("--directory", output);
}

@Test
Expand All @@ -91,7 +114,7 @@ public final void runOptDrtExamplePopulationTest() {
ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

MATSimApplication.execute(RunLeipzigScenario.class, config, "run", "--1pct", "--drt-area", exampleShp,
"--drt-modes", "drtNorth,drtSoutheast", "--waiting-time-threshold-optDrt", "600", "--post-processing", "disabled");
"--drt-modes", "drtNorth,drtSoutheast", "--waiting-time-threshold-optDrt", "600", "--post-processing", "disabled");

Assert.assertNotNull(config.getModules().get("multiModeOptDrt"));
Assert.assertNotNull(config.getModules().get("multiModeOptDrt").getParameterSets());
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit e1632a1

Please sign in to comment.