From a334faf9697c199e5326e52a63cefb08ac39c089 Mon Sep 17 00:00:00 2001 From: rakow Date: Wed, 27 Mar 2024 09:38:19 +0100 Subject: [PATCH] update bast counts test --- .../matsim/application/options/CountsOptions.java | 6 +++++- .../prepare/counts/CreateCountsFromBAStDataTest.java | 12 ++++-------- .../matsim/application/prepare/counts/ignored.csv | 1 - .../org/matsim/application/prepare/counts/manual.csv | 2 -- .../matsim/application/prepare/counts/mapping.csv | 4 ++++ 5 files changed, 13 insertions(+), 12 deletions(-) delete mode 100644 contribs/application/test/input/org/matsim/application/prepare/counts/ignored.csv delete mode 100644 contribs/application/test/input/org/matsim/application/prepare/counts/manual.csv create mode 100644 contribs/application/test/input/org/matsim/application/prepare/counts/mapping.csv diff --git a/contribs/application/src/main/java/org/matsim/application/options/CountsOptions.java b/contribs/application/src/main/java/org/matsim/application/options/CountsOptions.java index c776e3eac71..3056bfd1a3e 100644 --- a/contribs/application/src/main/java/org/matsim/application/options/CountsOptions.java +++ b/contribs/application/src/main/java/org/matsim/application/options/CountsOptions.java @@ -51,7 +51,7 @@ public Map> getManualMatched() { return manualMatchedCounts; } - private void readMapping() { + private synchronized void readMapping() { // Already read if (manualMatchedCounts != null) @@ -60,6 +60,10 @@ private void readMapping() { manualMatchedCounts = new HashMap<>(); ignoredCounts = new HashSet<>(); + // No input file + if (input == null) + return; + try (var reader = IOUtils.getBufferedReader(input)) { CSVFormat format = CSVFormat.Builder.create() .setAllowMissingColumnNames(true) diff --git a/contribs/application/src/test/java/org/matsim/application/prepare/counts/CreateCountsFromBAStDataTest.java b/contribs/application/src/test/java/org/matsim/application/prepare/counts/CreateCountsFromBAStDataTest.java index c74d59b7801..1545ef4395d 100644 --- a/contribs/application/src/test/java/org/matsim/application/prepare/counts/CreateCountsFromBAStDataTest.java +++ b/contribs/application/src/test/java/org/matsim/application/prepare/counts/CreateCountsFromBAStDataTest.java @@ -22,8 +22,7 @@ public class CreateCountsFromBAStDataTest { String countsOutput = "test-counts.xml.gz"; - String ignoredCounts = "ignored.csv"; - String manualMatchedCounts = "manual.csv"; + String mapping = "mapping.csv"; String wrongManualMatchedCounts = "wrong_manual.csv"; String network = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("berlin"), "network.xml.gz").toString(); @@ -61,9 +60,6 @@ void testCreateCountsFromBAStData() { assertThat(counts.getMeasureLocations()) .hasSize(24); - assertThat(counts.getCounts()) - .hasSize(24); - for (Map.Entry, MeasurementLocation> e : counts.getMeasureLocations().entrySet()) { assertThat(e.getValue().hasMeasurableForMode(Measurable.VOLUMES, TransportMode.car)) .isTrue(); @@ -105,7 +101,7 @@ void testWithIgnoredStations() { "--shp-crs=" + shpCrs, "--year=2021", "--output=" + out2, - "--ignored-counts=" + utils.getPackageInputDirectory() + ignoredCounts, + "--counts-mapping=" + utils.getPackageInputDirectory() + mapping, }; new CreateCountsFromBAStData().execute(args2); @@ -140,7 +136,7 @@ void testManualMatchedCounts() { "--shp-crs=" + shpCrs, "--year=2021", "--output=" + out, - "--manual-matched-counts=" + utils.getPackageInputDirectory() + manualMatchedCounts, + "--counts-mapping=" + utils.getPackageInputDirectory() + mapping, }; new CreateCountsFromBAStData().execute(args); @@ -178,7 +174,7 @@ void testManualMatchingWithWrongInput() { "--shp-crs=" + shpCrs, "--year=2021", "--output=" + out, - "--manual-matched-counts=" + utils.getPackageInputDirectory() + wrongManualMatchedCounts, + "--counts-mapping=" + utils.getPackageInputDirectory() + wrongManualMatchedCounts, }; Assertions.assertThrows(RuntimeException.class, () -> new CreateCountsFromBAStData().execute(args)); diff --git a/contribs/application/test/input/org/matsim/application/prepare/counts/ignored.csv b/contribs/application/test/input/org/matsim/application/prepare/counts/ignored.csv deleted file mode 100644 index a43b7bf6621..00000000000 --- a/contribs/application/test/input/org/matsim/application/prepare/counts/ignored.csv +++ /dev/null @@ -1 +0,0 @@ -2012 diff --git a/contribs/application/test/input/org/matsim/application/prepare/counts/manual.csv b/contribs/application/test/input/org/matsim/application/prepare/counts/manual.csv deleted file mode 100644 index 58488f11a34..00000000000 --- a/contribs/application/test/input/org/matsim/application/prepare/counts/manual.csv +++ /dev/null @@ -1,2 +0,0 @@ -2012_1;4205 -2012_2;4219 diff --git a/contribs/application/test/input/org/matsim/application/prepare/counts/mapping.csv b/contribs/application/test/input/org/matsim/application/prepare/counts/mapping.csv new file mode 100644 index 00000000000..c6503661752 --- /dev/null +++ b/contribs/application/test/input/org/matsim/application/prepare/counts/mapping.csv @@ -0,0 +1,4 @@ +station,linkId,Using +2012_1,4205,x +2012_2,4219,x +2014,xxx, \ No newline at end of file