Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel committed May 2, 2024
1 parent af6cde9 commit 8050c17
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

package org.matsim.core.replanning.modules;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.Scenario;
Expand All @@ -32,8 +32,7 @@
import org.matsim.api.core.v01.population.PopulationWriter;
import org.matsim.api.core.v01.replanning.PlanStrategyModule;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.*;
import org.matsim.core.population.PopulationUtils;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.population.io.PopulationReader;
import org.matsim.core.population.routes.PopulationComparison;
import org.matsim.core.replanning.ReplanningContext;
Expand Down Expand Up @@ -103,7 +102,7 @@ public boolean invoke() {
}, "test", outputDirectoryHierarchy, scenario);
replanPopulation(scenario.getPopulation(), testee);
PopulationComparison.Result result = PopulationComparison.compare(scenario.getPopulation(), originalScenario.getPopulation());
Assertions.assertEquals(PopulationComparison.Result.equal, result);
Assertions.assertNotEquals(PopulationComparison.Result.equal, result);
}

private Population loadPopulation(String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.*;

/**
/**
* @author thibautd
*/
public class AttributesTest {
Expand Down Expand Up @@ -166,4 +164,86 @@ void testComparison() {
Assertions.assertFalse(AttributesComparison.equals(a1, a2));

}

@Test
void testComplexComparisonMap() {

AttributesImpl a1 = new AttributesImpl();
AttributesImpl a2 = new AttributesImpl();

Map<Object, Object> map = new HashMap<>();
a1.putAttribute("map", map);
a2.putAttribute("map", map);

Assertions.assertTrue(AttributesComparison.equals(a1, a2));

Map<Object, Object> map2 = new HashMap<>();
a2.putAttribute("map", map2);

Assertions.assertTrue(AttributesComparison.equals(a1, a2));

Object o = new Object();
map.put(o, o);
Assertions.assertFalse(AttributesComparison.equals(a1, a2));

map2.put(o, o);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));


Map<Object, Object> recursiveMap = new HashMap<>();
map.put("recursiveMap", recursiveMap);
map2.put("recursiveMap", recursiveMap);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));

recursiveMap.put(o, o);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));

Map<Object, Object> recursiveMap2 = new HashMap<>();
map2.put("recursiveMap", recursiveMap2);
Assertions.assertFalse(AttributesComparison.equals(a1, a2));

recursiveMap2.put(o, o);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));
}

@Test
void testComplexComparisonList() {

AttributesImpl a1 = new AttributesImpl();
AttributesImpl a2 = new AttributesImpl();

List<Object> list= new ArrayList<>();
a1.putAttribute("list", list);
a2.putAttribute("list", list);

Assertions.assertTrue(AttributesComparison.equals(a1, a2));

List<Object> list2 = new ArrayList<>();
a2.putAttribute("list", list2);

Assertions.assertTrue(AttributesComparison.equals(a1, a2));

Object o = new Object();
list.add(o);
Assertions.assertFalse(AttributesComparison.equals(a1, a2));

list2.add(o);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));

List<Object> recursiveList = new ArrayList<>();
list.add(recursiveList);
list2.add(recursiveList);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));

recursiveList.add(o);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));

List<Object> recursiveList2 = new ArrayList<>();
list2.add(recursiveList2);
Assertions.assertFalse(AttributesComparison.equals(a1, a2));
list2.remove(recursiveList);

recursiveList2.add(o);
Assertions.assertTrue(AttributesComparison.equals(a1, a2));
}
}

0 comments on commit 8050c17

Please sign in to comment.