Fix order of values in assertions.

This commit is contained in:
Mikaël Capelle 2019-03-25 17:17:22 +01:00
parent dc715744d0
commit 554b38be45
4 changed files with 76 additions and 75 deletions

View file

@ -110,27 +110,28 @@ public abstract class PriorityQueueTest {
// order. // order.
objects.add(new TestParameters<>( objects.add(new TestParameters<>(
IntStream.range(0, 20).mapToObj(MutableInteger::new).toArray(MutableInteger[]::new), IntStream.range(0, 20).mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[]{ 12, 17, 18, 19, 4, 5, 3, 2, 0, 9, 10, 16, 8, 14, 13, 15, 7, 6, 1, 11 })); new int[] { 12, 17, 18, 19, 4, 5, 3, 2, 0, 9, 10, 16, 8, 14, 13, 15, 7, 6, 1,
11 }));
// Queue with 7 elements. // Queue with 7 elements.
objects.add( objects.add(
new TestParameters<>( new TestParameters<>(
Arrays.stream(new int[]{ 8, 1, 6, 3, 4, 5, 9 }) Arrays.stream(new int[] { 8, 1, 6, 3, 4, 5, 9 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new), .mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[]{ 6, 5, 0, 1, 4, 2, 3 })); new int[] { 6, 5, 0, 1, 4, 2, 3 }));
// Queue with 7 elements. // Queue with 7 elements.
objects.add( objects.add(
new TestParameters<>( new TestParameters<>(
Arrays.stream(new int[]{ 1, 7, 4, 8, 9, 6, 5 }) Arrays.stream(new int[] { 1, 7, 4, 8, 9, 6, 5 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new), .mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[]{ 2, 0, 1, 3, 4, 5, 6 })); new int[] { 2, 0, 1, 3, 4, 5, 6 }));
// Queue with 13 elements. // Queue with 13 elements.
objects.add(new TestParameters<>( objects.add(new TestParameters<>(
Arrays.stream(new int[]{ 1, 7, 2, 8, 9, 3, 4, 10, 11, 12, 13, 5, 6 }) Arrays.stream(new int[] { 1, 7, 2, 8, 9, 3, 4, 10, 11, 12, 13, 5, 6 })
.mapToObj(MutableInteger::new).toArray(MutableInteger[]::new), .mapToObj(MutableInteger::new).toArray(MutableInteger[]::new),
new int[]{ 3, 4, 0, 2, 5, 6, 1, 7, 8, 9, 10, 11, 12 })); new int[] { 3, 4, 0, 2, 5, 6, 1, 7, 8, 9, 10, 11, 12 }));
return objects; return objects;
} }
@ -200,7 +201,7 @@ public abstract class PriorityQueueTest {
@Test @Test
public void testDeleteMin() { public void testDeleteMin() {
int size = parameters.data.length; int size = parameters.data.length;
assertEquals(queue.size(), size); assertEquals(size, queue.size());
MutableInteger[] range = Arrays.copyOf(parameters.data, parameters.data.length); MutableInteger[] range = Arrays.copyOf(parameters.data, parameters.data.length);
Arrays.sort(range); Arrays.sort(range);
for (MutableInteger x: range) { for (MutableInteger x: range) {
@ -229,14 +230,14 @@ public abstract class PriorityQueueTest {
fail("Expected exception " + ElementNotFoundException.class.getName()); fail("Expected exception " + ElementNotFoundException.class.getName());
} }
catch (ElementNotFoundException e) { catch (ElementNotFoundException e) {
assertEquals(e.getElement(), min); assertEquals(min, e.getElement());
} }
try { try {
queue.remove(max); queue.remove(max);
fail("Expected exception " + ElementNotFoundException.class.getName()); fail("Expected exception " + ElementNotFoundException.class.getName());
} }
catch (ElementNotFoundException e) { catch (ElementNotFoundException e) {
assertEquals(e.getElement(), max); assertEquals(max, e.getElement());
} }
} }
@ -250,7 +251,7 @@ public abstract class PriorityQueueTest {
fail("Expected exception " + ElementNotFoundException.class.getName()); fail("Expected exception " + ElementNotFoundException.class.getName());
} }
catch (ElementNotFoundException e) { catch (ElementNotFoundException e) {
assertEquals(e.getElement(), min); assertEquals(min, e.getElement());
} }
} }
} }
@ -266,7 +267,7 @@ public abstract class PriorityQueueTest {
fail("Expected exception " + ElementNotFoundException.class.getName()); fail("Expected exception " + ElementNotFoundException.class.getName());
} }
catch (ElementNotFoundException e) { catch (ElementNotFoundException e) {
assertEquals(e.getElement(), data); assertEquals(data, e.getElement());
} }
} }
} }

View file

@ -83,26 +83,26 @@ public class GraphTest {
assertEquals(expNbSucc[i], transpose.get(i).getNumberOfSuccessors()); assertEquals(expNbSucc[i], transpose.get(i).getNumberOfSuccessors());
} }
assertEquals(getArcsBetween(transpose.get(0), transpose.get(1)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(1)).size());
assertEquals(getArcsBetween(transpose.get(0), transpose.get(2)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(2)).size());
assertEquals(getArcsBetween(transpose.get(0), transpose.get(3)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(3)).size());
assertEquals(getArcsBetween(transpose.get(0), transpose.get(4)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(4)).size());
assertEquals(getArcsBetween(transpose.get(1), transpose.get(0)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(1), transpose.get(0)).size());
assertEquals(getArcsBetween(transpose.get(1), transpose.get(2)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(1), transpose.get(2)).size());
assertEquals(getArcsBetween(transpose.get(1), transpose.get(3)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(1), transpose.get(3)).size());
assertEquals(getArcsBetween(transpose.get(1), transpose.get(4)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(1), transpose.get(4)).size());
assertEquals(getArcsBetween(transpose.get(2), transpose.get(0)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(2), transpose.get(0)).size());
assertEquals(getArcsBetween(transpose.get(2), transpose.get(1)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(2), transpose.get(1)).size());
assertEquals(getArcsBetween(transpose.get(2), transpose.get(3)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(2), transpose.get(3)).size());
assertEquals(getArcsBetween(transpose.get(2), transpose.get(4)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(2), transpose.get(4)).size());
assertEquals(getArcsBetween(transpose.get(3), transpose.get(0)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(3), transpose.get(0)).size());
assertEquals(getArcsBetween(transpose.get(3), transpose.get(1)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(3), transpose.get(1)).size());
assertEquals(getArcsBetween(transpose.get(3), transpose.get(2)).size(), 3); assertEquals(3, getArcsBetween(transpose.get(3), transpose.get(2)).size());
assertEquals(getArcsBetween(transpose.get(3), transpose.get(4)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(3), transpose.get(4)).size());
assertEquals(getArcsBetween(transpose.get(4), transpose.get(0)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(4), transpose.get(0)).size());
assertEquals(getArcsBetween(transpose.get(4), transpose.get(1)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(4), transpose.get(1)).size());
assertEquals(getArcsBetween(transpose.get(4), transpose.get(2)).size(), 0); assertEquals(0, getArcsBetween(transpose.get(4), transpose.get(2)).size());
assertEquals(getArcsBetween(transpose.get(4), transpose.get(3)).size(), 1); assertEquals(1, getArcsBetween(transpose.get(4), transpose.get(3)).size());
} }
} }

View file

@ -65,18 +65,18 @@ public class NodeTest {
@Test @Test
public void testGetNumberOfSuccessors() { public void testGetNumberOfSuccessors() {
final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 }; final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 };
assertEquals(nodes.length, expNbSucc.length); assertEquals(expNbSucc.length, nodes.length);
for (int i = 0; i < expNbSucc.length; ++i) { for (int i = 0; i < expNbSucc.length; ++i) {
assertEquals(nodes[i].getNumberOfSuccessors(), expNbSucc[i]); assertEquals(expNbSucc[i], nodes[i].getNumberOfSuccessors());
} }
} }
@Test @Test
public void testHasSuccessors() { public void testHasSuccessors() {
final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 }; final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 };
assertEquals(nodes.length, expNbSucc.length); assertEquals(expNbSucc.length, nodes.length);
for (int i = 0; i < expNbSucc.length; ++i) { for (int i = 0; i < expNbSucc.length; ++i) {
assertEquals(nodes[i].hasSuccessors(), expNbSucc[i] != 0); assertEquals(expNbSucc[i] != 0, nodes[i].hasSuccessors());
} }
} }

View file

@ -93,15 +93,15 @@ public class PathTest {
assertFalse(longLoopPath.isEmpty()); assertFalse(longLoopPath.isEmpty());
assertFalse(invalidPath.isEmpty()); assertFalse(invalidPath.isEmpty());
} }
@Test @Test
public void testSize() { public void testSize() {
assertEquals(emptyPath.size(), 0); assertEquals(0, emptyPath.size());
assertEquals(singleNodePath.size(), 1); assertEquals(1, singleNodePath.size());
assertEquals(shortPath.size(), 4); assertEquals(4, shortPath.size());
assertEquals(longPath.size(), 5); assertEquals(5, longPath.size());
assertEquals(loopPath.size(), 5); assertEquals(5, loopPath.size());
assertEquals(longLoopPath.size(), 10); assertEquals(10, longLoopPath.size());
} }
@Test @Test
@ -118,41 +118,41 @@ public class PathTest {
@Test @Test
public void testGetLength() { public void testGetLength() {
assertEquals(emptyPath.getLength(), 0, 1e-6); assertEquals(0, emptyPath.getLength(), 1e-6);
assertEquals(singleNodePath.getLength(), 0, 1e-6); assertEquals(0, singleNodePath.getLength(), 1e-6);
assertEquals(shortPath.getLength(), 40, 1e-6); assertEquals(40, shortPath.getLength(), 1e-6);
assertEquals(longPath.getLength(), 62.8, 1e-6); assertEquals(62.8, longPath.getLength(), 1e-6);
assertEquals(loopPath.getLength(), 55, 1e-6); assertEquals(55, loopPath.getLength(), 1e-6);
assertEquals(longLoopPath.getLength(), 120, 1e-6); assertEquals(120, longLoopPath.getLength(), 1e-6);
} }
@Test @Test
public void testGetTravelTime() { public void testGetTravelTime() {
// Note: 18 km/h = 5m/s // Note: 18 km/h = 5m/s
assertEquals(emptyPath.getTravelTime(18), 0, 1e-6); assertEquals(0, emptyPath.getTravelTime(18), 1e-6);
assertEquals(singleNodePath.getTravelTime(18), 0, 1e-6); assertEquals(0, singleNodePath.getTravelTime(18), 1e-6);
assertEquals(shortPath.getTravelTime(18), 8, 1e-6); assertEquals(8, shortPath.getTravelTime(18), 1e-6);
assertEquals(longPath.getTravelTime(18), 12.56, 1e-6); assertEquals(12.56, longPath.getTravelTime(18), 1e-6);
assertEquals(loopPath.getTravelTime(18), 11, 1e-6); assertEquals(11, loopPath.getTravelTime(18), 1e-6);
assertEquals(longLoopPath.getTravelTime(18), 24, 1e-6); assertEquals(24, longLoopPath.getTravelTime(18), 1e-6);
// Note: 28.8 km/h = 8m/s // Note: 28.8 km/h = 8m/s
assertEquals(emptyPath.getTravelTime(28.8), 0, 1e-6); assertEquals(0, emptyPath.getTravelTime(28.8), 1e-6);
assertEquals(singleNodePath.getTravelTime(28.8), 0, 1e-6); assertEquals(0, singleNodePath.getTravelTime(28.8), 1e-6);
assertEquals(shortPath.getTravelTime(28.8), 5, 1e-6); assertEquals(5, shortPath.getTravelTime(28.8), 1e-6);
assertEquals(longPath.getTravelTime(28.8), 7.85, 1e-6); assertEquals(7.85, longPath.getTravelTime(28.8), 1e-6);
assertEquals(loopPath.getTravelTime(28.8), 6.875, 1e-6); assertEquals(6.875, loopPath.getTravelTime(28.8), 1e-6);
assertEquals(longLoopPath.getTravelTime(28.8), 15, 1e-6); assertEquals(15, longLoopPath.getTravelTime(28.8), 1e-6);
} }
@Test @Test
public void testGetMinimumTravelTime() { public void testGetMinimumTravelTime() {
assertEquals(emptyPath.getMinimumTravelTime(), 0, 1e-4); assertEquals(0, emptyPath.getMinimumTravelTime(), 1e-4);
assertEquals(singleNodePath.getLength(), 0, 1e-4); assertEquals(0, singleNodePath.getLength(), 1e-4);
assertEquals(shortPath.getMinimumTravelTime(), 4, 1e-4); assertEquals(4, shortPath.getMinimumTravelTime(), 1e-4);
assertEquals(longPath.getMinimumTravelTime(), 5.14, 1e-4); assertEquals(5.14, longPath.getMinimumTravelTime(), 1e-4);
assertEquals(loopPath.getMinimumTravelTime(), 5.5, 1e-4); assertEquals(5.5, loopPath.getMinimumTravelTime(), 1e-4);
assertEquals(longLoopPath.getMinimumTravelTime(), 11.25, 1e-4); assertEquals(11.25, longLoopPath.getMinimumTravelTime(), 1e-4);
} }
@Test @Test
@ -180,13 +180,13 @@ public class PathTest {
// Trap construction! // Trap construction!
path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] })); path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] }));
assertEquals(path.getOrigin(), nodes[1]); assertEquals(nodes[1], path.getOrigin());
assertEquals(path.getArcs().size(), 0); assertEquals(0, path.getArcs().size());
// Trap construction - The return! // Trap construction - The return!
path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[0])); path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[0]));
assertEquals(path.getOrigin(), null); assertEquals(null, path.getOrigin());
assertEquals(path.getArcs().size(), 0); assertEquals(0, path.getArcs().size());
assertTrue(path.isEmpty()); assertTrue(path.isEmpty());
} }
@ -215,13 +215,13 @@ public class PathTest {
// Trap construction! // Trap construction!
path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] })); path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] }));
assertEquals(path.getOrigin(), nodes[1]); assertEquals(nodes[1], path.getOrigin());
assertEquals(path.getArcs().size(), 0); assertEquals(0, path.getArcs().size());
// Trap construction - The return! // Trap construction - The return!
path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[0])); path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[0]));
assertEquals(path.getOrigin(), null); assertEquals(null, path.getOrigin());
assertEquals(path.getArcs().size(), 0); assertEquals(0, path.getArcs().size());
assertTrue(path.isEmpty()); assertTrue(path.isEmpty());
} }