Refactoring
* package refactoring * new matrix implementation (todo) * new adj list implemetation (todo) * fixed tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package berack96.test.sim;
|
||||
package berack96.test.lib;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -27,17 +27,20 @@ import org.junit.Test;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import berack96.sim.util.graph.Edge;
|
||||
import berack96.sim.util.graph.Graph;
|
||||
import berack96.sim.util.graph.MapGraph;
|
||||
import berack96.sim.util.graph.Vertex;
|
||||
import berack96.sim.util.graph.visit.BFS;
|
||||
import berack96.sim.util.graph.visit.DFS;
|
||||
import berack96.sim.util.graph.visit.VisitInfo;
|
||||
import berack96.lib.graph.Edge;
|
||||
import berack96.lib.graph.Graph;
|
||||
import berack96.lib.graph.Vertex;
|
||||
import berack96.lib.graph.impl.AdjGraph;
|
||||
import berack96.lib.graph.impl.MapGraph;
|
||||
import berack96.lib.graph.impl.MatrixGraph;
|
||||
import berack96.lib.graph.visit.impl.BFS;
|
||||
import berack96.lib.graph.visit.impl.DFS;
|
||||
import berack96.lib.graph.visit.impl.VisitInfo;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TestGraph {
|
||||
|
||||
/* We only try this for sake of simplicity */
|
||||
private Graph<String, Integer> graph;
|
||||
|
||||
private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
@@ -52,6 +55,8 @@ public class TestGraph {
|
||||
public void before() {
|
||||
// Change here the instance for changing all the test for that particular class
|
||||
graph = new MapGraph<>();
|
||||
// graph = new MatrixGraph<>();
|
||||
// graph = new AdjGraph<>();
|
||||
|
||||
PrintStream p = null;
|
||||
try {
|
||||
@@ -557,6 +562,14 @@ public class TestGraph {
|
||||
graph.addEdge("8", "7", 8);
|
||||
|
||||
Set<String> vertices = new HashSet<>();
|
||||
|
||||
Iterator<String> iter = graph.iterator();
|
||||
assertTrue("This should not be null!", iter != null);
|
||||
while (iter.hasNext())
|
||||
vertices.add(iter.next());
|
||||
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
|
||||
vertices.clear();
|
||||
|
||||
for (String vertex : graph)
|
||||
vertices.add(vertex);
|
||||
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
|
||||
@@ -564,13 +577,6 @@ public class TestGraph {
|
||||
vertices.clear();
|
||||
graph.forEach(vertices::add);
|
||||
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
|
||||
|
||||
vertices.clear();
|
||||
Iterator<String> iter = graph.iterator();
|
||||
while (iter.hasNext())
|
||||
vertices.add(iter.next());
|
||||
|
||||
shouldContain(vertices, "1", "2", "3", "4", "5", "6", "7", "8");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -746,6 +752,7 @@ public class TestGraph {
|
||||
graph.addEdge("7", "8", 8);
|
||||
|
||||
Graph<String, Integer> transposed = graph.transpose();
|
||||
assertTrue("This should not be null!", transposed != null);
|
||||
|
||||
DFS<String, Integer> dfs = new DFS<>();
|
||||
VisitInfo<String> visitDFS = transposed.visit("6", dfs, null);
|
||||
@@ -838,6 +845,7 @@ public class TestGraph {
|
||||
graph.addEdge("7", "8", 8);
|
||||
|
||||
List<Edge<String, Integer>> distance = graph.distance("1", "6");
|
||||
assertTrue("This should not be null!", distance != null);
|
||||
int sum = distance.stream().mapToInt(Edge::getWeight).sum();
|
||||
assertEquals(13, sum);
|
||||
shouldContainInOrder(distance,
|
||||
@@ -897,6 +905,7 @@ public class TestGraph {
|
||||
graph.addEdge("7", "8", 8);
|
||||
|
||||
Map<String, List<Edge<String, Integer>>> distance = graph.distance("1");
|
||||
assertTrue("This should not be null!", distance != null);
|
||||
assertNull(distance.get("1"));
|
||||
shouldContainInOrder(distance.get("2"),
|
||||
new Edge<>("1", "2", 1));
|
||||
@@ -1112,6 +1121,7 @@ public class TestGraph {
|
||||
graph.mark("4", "z");
|
||||
|
||||
Graph<String, Integer> sub = graph.subGraph("1", -541);
|
||||
assertTrue("This should not be null!", sub != null);
|
||||
shouldContain(sub.vertices(), "1");
|
||||
shouldContain(sub.edges());
|
||||
|
||||
@@ -1425,6 +1435,7 @@ public class TestGraph {
|
||||
|
||||
|
||||
private void shouldContain(Collection<?> actual, Object... expected) {
|
||||
assertTrue("You should pass me a collection!", actual != null);
|
||||
assertEquals("They have not the same number of elements\nActual: " + actual, expected.length, actual.size());
|
||||
|
||||
for (Object obj : expected)
|
||||
@@ -1432,6 +1443,7 @@ public class TestGraph {
|
||||
}
|
||||
|
||||
private void shouldContainInOrder(List<?> actual, Object... expected) {
|
||||
assertTrue("You should pass me a list!", actual != null);
|
||||
assertEquals("They have not the same number of elements\nActual: " + actual, expected.length, actual.size());
|
||||
|
||||
for (int i = 0; i < actual.size(); i++)
|
||||
Reference in New Issue
Block a user