Skip to content

Commit

Permalink
replace population comparison in tests and deprecate by byte comparis…
Browse files Browse the repository at this point in the history
…on of plan files (#3247); add attributes comparison
  • Loading branch information
nkuehnel authored May 3, 2024
1 parent 653382b commit ef7e434
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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" ;
Expand Down Expand Up @@ -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" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void runChessboard() {
Population actual = PopulationUtils.createPopulation( ConfigUtils.createConfig() ) ;
PopulationUtils.readPopulation( actual, utils.getOutputDirectory() + "/output_plans.xml.gz" );

PopulationComparison.Result result = new PopulationComparison().compare(expected, actual);
PopulationComparison.Result result = PopulationComparison.compare(expected, actual);
Assertions.assertSame(PopulationComparison.Result.equal, result);
}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

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;
import org.matsim.api.core.v01.population.Population;
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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void install() {
PopulationUtils.readPopulation( popExpected, utils.getInputDirectory() + "/output_plans.xml.gz" );
Population popActual = PopulationUtils.createPopulation( config );
PopulationUtils.readPopulation( popActual, outDir + "/output_plans.xml.gz" );
new PopulationComparison().compare( popExpected, popActual ) ;
PopulationComparison.compare( popExpected, popActual ) ;
Assertions.assertEquals(138.86084460860525, psimScore, MatsimTestUtils.EPSILON, "RunPsim score changed.");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private void runScenario(String configPath) {
Population actual = PopulationUtils.createPopulation(ConfigUtils.createConfig());
PopulationUtils.readPopulation(actual, utils.getOutputDirectory() + "/output_plans.xml.gz");

PopulationComparison populationComparison = new PopulationComparison();
PopulationComparison.Result result = populationComparison.compare(expected, actual);
PopulationComparison.Result result = PopulationComparison.compare(expected, actual);
Assertions.assertEquals(PopulationComparison.Result.equal, result);
}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public static void runBenchmark(boolean vehicleDiversion, AbstractTaxiOptimizerP
Population actual = PopulationUtils.createPopulation(ConfigUtils.createConfig());
PopulationUtils.readPopulation(actual, utils.getOutputDirectory() + "/output_plans.xml.gz");

PopulationComparison populationComparison = new PopulationComparison();
PopulationComparison.Result result = populationComparison.compare(expected, actual);
PopulationComparison.Result result = PopulationComparison.compare(expected, actual);
Assertions.assertEquals(PopulationComparison.Result.equal, result);
}
{
Expand Down
5 changes: 3 additions & 2 deletions contribs/vsp/src/test/java/playground/vsp/ev/UrbanEVIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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" ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,10 @@ public static double calculateSimilarity(List<Activity> activities1, List<Activi
* this will go unnoticed (this method will just return true or false,
* probably false, except if both Writers have written the exact same text
* until the Exception happens).
*
* @deprecated -- please use {@link org.matsim.core.population.routes.PopulationComparison} instead. nkuehnel, apr'24
*/
@Deprecated
public static boolean equalPopulation(final Population s1, final Population s2) {
try {
try( InputStream inputStream1 = openPopulationInputStream( s1 ) ; InputStream inputStream2 = openPopulationInputStream( s2 ) ){
Expand Down Expand Up @@ -1186,6 +1189,10 @@ public static Population readPopulation( String filename ) {
readPopulation( population, filename );
return population ;
}
/**
* @deprecated -- please use {@link org.matsim.core.population.routes.PopulationComparison} instead. nkuehnel, apr'24
*/
@Deprecated
public static boolean comparePopulations( Population population1, Population population2 ) {
return PopulationUtils.equalPopulation( population1, population2 );
}
Expand Down
Loading

0 comments on commit ef7e434

Please sign in to comment.