diff --git a/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleTest.java b/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleTest.java index 87644405c7d..9509bba85cc 100644 --- a/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleTest.java +++ b/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleTest.java @@ -9,6 +9,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.testcases.MatsimTestUtils; import org.matsim.utils.eventsfilecomparison.ComparisonResult; @@ -33,8 +34,8 @@ public class RunEvExampleTest{ Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ) ; PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_plans.xml.gz" ); - boolean result = PopulationUtils.comparePopulations( expected, actual ); - Assertions.assertTrue(result); + PopulationComparison.Result result = PopulationComparison.compare(expected, actual); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } { String expected = utils.getInputDirectory() + "/output_events.xml.gz" ; @@ -66,8 +67,8 @@ public class RunEvExampleTest{ Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ) ; PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_plans.xml.gz" ); - boolean result = PopulationUtils.comparePopulations( expected, actual ); - Assertions.assertTrue(result); + PopulationComparison.Result result = PopulationComparison.compare(expected, actual); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } { String expected = utils.getInputDirectory() + "/output_events.xml.gz" ; diff --git a/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModelTest.java b/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModelTest.java index 447b79966ad..c71b0898651 100644 --- a/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModelTest.java +++ b/contribs/ev/src/test/java/org/matsim/contrib/ev/example/RunEvExampleWithLTHConsumptionModelTest.java @@ -9,6 +9,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.testcases.MatsimTestUtils; import org.matsim.utils.eventsfilecomparison.ComparisonResult; @@ -33,8 +34,8 @@ void runTest(){ Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ) ; PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_plans.xml.gz" ); - boolean result = PopulationUtils.comparePopulations( expected, actual ); - Assertions.assertTrue( result ); + PopulationComparison.Result result = PopulationComparison.compare(expected, actual); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } { String expected = utils.getInputDirectory() + "/output_events.xml.gz" ; diff --git a/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingproxy/run/RunWithParkingProxyIT.java b/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingproxy/run/RunWithParkingProxyIT.java index e87a4afbaba..7619ded63e9 100644 --- a/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingproxy/run/RunWithParkingProxyIT.java +++ b/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingproxy/run/RunWithParkingProxyIT.java @@ -20,6 +20,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -27,6 +28,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; import org.matsim.testcases.MatsimTestUtils; @@ -60,9 +62,8 @@ void testMain(){ PopulationUtils.readPopulation( expected, utils.getInputDirectory() + "/output_experienced_plans.xml.gz" ); final Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ); PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_experienced_plans.xml.gz" ); - if(!PopulationUtils.comparePopulations( expected, actual )) { - throw new RuntimeException("Plans file comparison ended with result false"); - } + PopulationComparison.Result result = PopulationComparison.compare(expected, actual); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } } } diff --git a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/run/RoadPricingByConfigfileTest.java b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/run/RoadPricingByConfigfileTest.java index e59e74dd90b..93893f362fc 100644 --- a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/run/RoadPricingByConfigfileTest.java +++ b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/run/RoadPricingByConfigfileTest.java @@ -29,6 +29,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; import org.matsim.testcases.MatsimTestUtils; @@ -62,7 +63,8 @@ final void testMain() { PopulationUtils.readPopulation( expected, utils.getInputDirectory() + "/output_plans.xml.gz" ); final Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ); PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_plans.xml.gz" ); - Assertions.assertTrue(PopulationUtils.comparePopulations( expected, actual ), "Populations are different"); + PopulationComparison.Result result = PopulationComparison.compare(expected, actual); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } diff --git a/contribs/vsp/src/test/java/playground/vsp/ev/UrbanEVIT.java b/contribs/vsp/src/test/java/playground/vsp/ev/UrbanEVIT.java index b96c04fb079..b133b0e485a 100644 --- a/contribs/vsp/src/test/java/playground/vsp/ev/UrbanEVIT.java +++ b/contribs/vsp/src/test/java/playground/vsp/ev/UrbanEVIT.java @@ -8,6 +8,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.testcases.MatsimTestUtils; import org.matsim.utils.eventsfilecomparison.ComparisonResult; @@ -32,8 +33,8 @@ void run() { Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ) ; PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_plans.xml.gz" ); - boolean result = PopulationUtils.comparePopulations( expected, actual ); - Assertions.assertTrue( result ); + PopulationComparison.Result result = PopulationComparison.compare(expected, actual); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } { String expected = utils.getInputDirectory() + "/output_events.xml.gz" ; diff --git a/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java b/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java index cae206c534b..5755982b6ed 100644 --- a/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java +++ b/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java @@ -665,7 +665,10 @@ public static double calculateSimilarity(List activities1, List it1 = population1.getPersons().values().iterator(); diff --git a/matsim/src/test/java/org/matsim/core/replanning/modules/ExternalModuleTest.java b/matsim/src/test/java/org/matsim/core/replanning/modules/ExternalModuleTest.java index e9c44723123..194a7f1fe00 100644 --- a/matsim/src/test/java/org/matsim/core/replanning/modules/ExternalModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/replanning/modules/ExternalModuleTest.java @@ -35,6 +35,7 @@ import org.matsim.core.controler.*; import org.matsim.core.population.PopulationUtils; import org.matsim.core.population.io.PopulationReader; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.core.replanning.ReplanningContext; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.testcases.MatsimTestUtils; @@ -82,7 +83,9 @@ public boolean invoke() { } }, "test", outputDirectoryHierarchy, scenario); replanPopulation(scenario.getPopulation(), testee); - Assertions.assertTrue(PopulationUtils.equalPopulation(scenario.getPopulation(), originalScenario.getPopulation())); + + PopulationComparison.Result result = PopulationComparison.compare(scenario.getPopulation(), originalScenario.getPopulation()); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } @Test @@ -99,7 +102,8 @@ public boolean invoke() { } }, "test", outputDirectoryHierarchy, scenario); replanPopulation(scenario.getPopulation(), testee); - Assertions.assertFalse(PopulationUtils.equalPopulation(scenario.getPopulation(), originalScenario.getPopulation())); + PopulationComparison.Result result = PopulationComparison.compare(scenario.getPopulation(), originalScenario.getPopulation()); + Assertions.assertEquals(PopulationComparison.Result.equal, result); } private Population loadPopulation(String filename) { diff --git a/matsim/src/test/java/org/matsim/core/router/RoutingIT.java b/matsim/src/test/java/org/matsim/core/router/RoutingIT.java index 35ac550ee68..7d3ace29d49 100644 --- a/matsim/src/test/java/org/matsim/core/router/RoutingIT.java +++ b/matsim/src/test/java/org/matsim/core/router/RoutingIT.java @@ -39,6 +39,7 @@ import org.matsim.core.population.PopulationUtils; import org.matsim.core.population.algorithms.PersonAlgorithm; import org.matsim.core.population.io.PopulationReader; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.core.router.costcalculators.FreespeedTravelTimeAndDisutility; import org.matsim.core.router.costcalculators.TravelDisutilityFactory; import org.matsim.core.router.speedy.SpeedyALTFactory; @@ -161,12 +162,12 @@ private void doTest(final RouterProvider provider) { new MatsimNetworkReader(referenceScenario.getNetwork()).readFile(config.network().getInputFile()); new PopulationReader(referenceScenario).readFile(inPlansName); - final boolean isEqual = PopulationUtils.equalPopulation(referenceScenario.getPopulation(), scenario.getPopulation()); - if ( !isEqual ) { + PopulationComparison.Result result = PopulationComparison.compare(referenceScenario.getPopulation(), scenario.getPopulation()); + if (result == PopulationComparison.Result.notEqual) { new PopulationWriter(referenceScenario.getPopulation(), scenario.getNetwork()).write(this.utils.getOutputDirectory() + "/reference_population.xml.gz"); new PopulationWriter(scenario.getPopulation(), scenario.getNetwork()).write(this.utils.getOutputDirectory() + "/output_population.xml.gz"); } - Assertions.assertTrue(isEqual, "different plans files."); + Assertions.assertEquals(PopulationComparison.Result.equal, result, "different plans files"); } private static void calcRoute( diff --git a/matsim/src/test/java/org/matsim/integration/replanning/ReRoutingIT.java b/matsim/src/test/java/org/matsim/integration/replanning/ReRoutingIT.java index c432538434a..f318a535671 100644 --- a/matsim/src/test/java/org/matsim/integration/replanning/ReRoutingIT.java +++ b/matsim/src/test/java/org/matsim/integration/replanning/ReRoutingIT.java @@ -37,6 +37,7 @@ import org.matsim.core.controler.Controler; import org.matsim.core.gbl.Gbl; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.population.routes.PopulationComparison; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; @@ -113,7 +114,6 @@ private void evaluate() throws MalformedURLException { this.evaluate("plans.xml.gz"); } - private final static Logger LOG = LogManager.getLogger(ReRoutingIT.class); private void evaluate(String plansFilename) throws MalformedURLException { Config config = utils.loadConfig(utils.getClassInputDirectory() + "config.xml"); config.network().setInputFile(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("berlin"), "network.xml.gz").toString()); @@ -124,13 +124,12 @@ private void evaluate(String plansFilename) throws MalformedURLException { Scenario scenario = ScenarioUtils.loadScenario(config); Gbl.startMeasurement(); - final boolean isEqual = PopulationUtils.equalPopulation(referenceScenario.getPopulation(), scenario.getPopulation()); + PopulationComparison.Result result = PopulationComparison.compare(referenceScenario.getPopulation(), scenario.getPopulation()); Gbl.printElapsedTime(); - if ( !isEqual ) { + if (result == PopulationComparison.Result.notEqual) { new PopulationWriter(referenceScenario.getPopulation(), scenario.getNetwork()).write(utils.getOutputDirectory() + "/reference_population.xml.gz"); new PopulationWriter(scenario.getPopulation(), scenario.getNetwork()).write(utils.getOutputDirectory() + "/output_population.xml.gz"); } - Assertions.assertTrue(isEqual, "different plans files."); + Assertions.assertEquals(PopulationComparison.Result.equal, result, "different plans file"); } - }