Skip to content

Commit

Permalink
Merge pull request #2988 from matsim-org/junit5
Browse files Browse the repository at this point in the history
Replace JUnit 4 by JUnit 5
  • Loading branch information
paulheinr authored Dec 15, 2023
2 parents d146aec + f60453b commit 47859fe
Show file tree
Hide file tree
Showing 971 changed files with 23,899 additions and 23,509 deletions.
8 changes: 6 additions & 2 deletions benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
<version>16.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.matsim.contrib.accessibility.utils;

import org.json.simple.JSONValue;
import com.google.gson.Gson;
import org.matsim.api.core.v01.Coord;

import java.util.*;
Expand Down Expand Up @@ -34,7 +34,7 @@ public String asGeoJson() {
featureCollectionMap.put("features", featuresList);
featureCollectionMap.put("crs", parseCRS());
featureCollectionMap.put("bbox", boundingBox.getBoundingBox());
return JSONValue.toJSONString(featureCollectionMap);
return new Gson().toJson(featureCollectionMap);
}

private List<Map<String, Object>> parseFeatureList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Node;
Expand All @@ -24,9 +24,9 @@
public class LeastCostPathTreeTest {

Scenario scenario;

@Test
public void testRouteChoiceTestSpanningTree(){
void testRouteChoiceTestSpanningTree(){
this.scenario = new ScenarioBuilder(ConfigUtils.createConfig()).setNetwork(CreateTestNetwork.createTriangularNetwork()).build() ;
compareRouteChoices();
}
Expand Down Expand Up @@ -55,23 +55,23 @@ private void compareRouteChoices(){
printResults(arrivalTime, travelTime); // travel time = cost = (50s+50s) = 100s
// check route (visited nodes should be 1,2,4)
List<Id<Node>> spTimeVisitedNodes = getVisitedNodes(lcptTime, destination, "Travel Time");
Assert.assertTrue( containsNode(spTimeVisitedNodes, Id.create("2", Node.class)));
Assertions.assertTrue( containsNode(spTimeVisitedNodes, Id.create("2", Node.class)));
// check travel duration
Assert.assertTrue( travelTime == 100 );
Assertions.assertTrue( travelTime == 100 );
// check travel time
Assert.assertTrue( arrivalTime - departureTime == 100 );
Assertions.assertTrue( arrivalTime - departureTime == 100 );

lcptDistance.calculate(this.scenario.getNetwork(), origin, departureTime);
double arrivalTimeTD = lcptDistance.getTree().get( destination.getId() ).getTime();
double travelDistance = lcptDistance.getTree().get( destination.getId() ).getCost(); // here cost = traveled distance
printResults(arrivalTimeTD, travelDistance); // travel time = 1000s, cost = (50m+50m) = 100m
// check route ( visited nodes should be 1,3,4)
List<Id<Node>> spDistenceVisitedNodes = getVisitedNodes(lcptDistance, destination, "Travel Distance");
Assert.assertTrue( containsNode(spDistenceVisitedNodes, Id.create("3", Node.class)));
Assertions.assertTrue( containsNode(spDistenceVisitedNodes, Id.create("3", Node.class)));
// check travel distance
Assert.assertTrue( travelDistance == 100 );
Assertions.assertTrue( travelDistance == 100 );
// check travel time
Assert.assertTrue( arrivalTimeTD - departureTime == 1000 );
Assertions.assertTrue( arrivalTimeTD - departureTime == 1000 );
}

private void printResults(double tt, double tc){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.matsim.contrib.accessibility.grid;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.accessibility.SpatialGrid;
import org.matsim.contrib.matrixbasedptrouter.utils.BoundingBox;
Expand All @@ -11,13 +11,14 @@

public class SpatialGridTest {

@Rule
public MatsimTestUtils utils = new MatsimTestUtils();
@RegisterExtension
private MatsimTestUtils utils = new MatsimTestUtils();

private double cellSize = 10.;


@Test public void testSpatialGrid() {
@Test
void testSpatialGrid() {

// get network
Network network = CreateTestNetwork.createTestNetwork();
Expand All @@ -31,11 +32,11 @@ public class SpatialGridTest {
// get number of rows
int rows = testGrid.getNumRows();
double numOfExpectedRows = ((nbb.getYMax() - nbb.getYMin()) / cellSize) + 1;
Assert.assertTrue(rows == numOfExpectedRows);
Assertions.assertTrue(rows == numOfExpectedRows);

// get number of columns
int cols = testGrid.getNumCols(0);
double numOfExpectedCols = ((nbb.getXMax() - nbb.getXMin()) / cellSize) + 1;
Assert.assertTrue(cols == numOfExpectedCols);
Assertions.assertTrue(cols == numOfExpectedCols);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
*/
package org.matsim.contrib.accessibility.logsumComputations;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.testcases.MatsimTestUtils;

/**
Expand All @@ -33,12 +33,12 @@
*/
public class CompareLogsumFormulas2Test {

@Rule
public MatsimTestUtils utils = new MatsimTestUtils();
@RegisterExtension
private MatsimTestUtils utils = new MatsimTestUtils();



@Test public void testLogsumFormulas(){
@Test
void testLogsumFormulas(){

double walkTravelTime2Network = 2.; // 2min
double travelTimeOnNetwork = 6.; // 6min
Expand Down Expand Up @@ -66,7 +66,7 @@ public class CompareLogsumFormulas2Test {
double Sum2 =PreFactor * AggregationSum;
System.out.println(Sum2);

Assert.assertTrue( Sum1 == Sum2 );
Assertions.assertTrue( Sum1 == Sum2 );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
*/
package org.matsim.contrib.accessibility.logsumComputations;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.testcases.MatsimTestUtils;

/**
Expand All @@ -33,8 +33,8 @@
*/
public class CompareLogsumFormulasTest {

@Rule
public MatsimTestUtils utils = new MatsimTestUtils();
@RegisterExtension
private MatsimTestUtils utils = new MatsimTestUtils();

/**
* underlying network
Expand All @@ -47,7 +47,8 @@ public class CompareLogsumFormulasTest {
* cjk3
*/

@Test public void testLogsumFormulas(){
@Test
void testLogsumFormulas(){
double betaWalkTT = -2.;
double betaWalkTD = -1.;

Expand All @@ -72,7 +73,7 @@ public class CompareLogsumFormulasTest {
double Ai = computeLogsum(betaWalkTT, betaWalkTD, cik1TT, cik2TT, cik3TT, cik1TD, cik2TD, cik3TD);
double Ai2 =computeTransformedLogsum(betaWalkTT, betaWalkTD, cijTT, cjk1TT, cjk2TT, cjk3TT, cijTD, cjk1TD, cjk2TD, cjk3TD);

Assert.assertTrue( Ai == Ai2 );
Assertions.assertTrue( Ai == Ai2 );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
*/
package org.matsim.contrib.accessibility.logsumComputations;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.testcases.MatsimTestUtils;

/**
Expand All @@ -33,8 +33,8 @@
*/
public class ComputeLogsumFormulas3Test {

@Rule
public MatsimTestUtils utils = new MatsimTestUtils();
@RegisterExtension
private MatsimTestUtils utils = new MatsimTestUtils();

/**
* underlying network
Expand All @@ -48,7 +48,8 @@ public class ComputeLogsumFormulas3Test {
*/
@SuppressWarnings("static-method")

@Test public void testLogsumFormulas(){
@Test
void testLogsumFormulas(){
double betaWalkTT = -10. / 3600.0; // [util/sec]
double betaWalkTD = -10.; // [util/meter]

Expand Down Expand Up @@ -100,7 +101,7 @@ public class ComputeLogsumFormulas3Test {
// double expNewVhj= Math.exp( VhjNew );
// double expNewVhk= expNewVhj * sumExpVjk;

Assert.assertTrue(VhjOld == VhjNew); // old accessibility computation == new accessibility computation
Assertions.assertTrue(VhjOld == VhjNew); // old accessibility computation == new accessibility computation

///////
// NEW
Expand All @@ -112,7 +113,7 @@ public class ComputeLogsumFormulas3Test {
double dummyExp1 = Math.exp( dummyVijCar + dummyVhiWalk );
double dummyExp2 = Math.exp( dummyVijCar ) * Math.exp( dummyVhiWalk );

Assert.assertEquals(dummyExp1,dummyExp2,1.e-10); // exp(VijCar + VijWalk) == exp(VijCar) * exp(VijWalk)
Assertions.assertEquals(dummyExp1,dummyExp2,1.e-10); // exp(VijCar + VijWalk) == exp(VijCar) * exp(VijWalk)
}

}
Loading

0 comments on commit 47859fe

Please sign in to comment.