public void testDirectedMatrixNoNodeIdWeighted() { DirectedWeightedPseudograph<Integer, DefaultWeightedEdge> g = new DirectedWeightedPseudograph<>(DefaultWeightedEdge.class); g.addVertex(1); g.addVertex(2); g.addVertex(3); g.addVertex(4); g.addVertex(5); g.addEdge(1, 2); g.addEdge(1, 3); g.addEdge(3, 1); g.addEdge(3, 4); g.addEdge(4, 5); g.addEdge(5, 1); g.addEdge(5, 2); g.addEdge(5, 3); g.addEdge(5, 4); g.addEdge(5, 5); g.setEdgeWeight(g.getEdge(1, 3), 13); g.setEdgeWeight(g.getEdge(5, 3), 53); CSVExporter<Integer, DefaultWeightedEdge> exporter = new CSVExporter<>(nameProvider, CSVFormat.MATRIX, ';'); exporter.setParameter(CSVFormat.Parameter.MATRIX_FORMAT_EDGE_WEIGHTS, true); StringWriter w = new StringWriter(); exporter.exportGraph(g, w); assertEquals(DIRECTED_MATRIX_NO_NODEID_WEIGHTED, w.toString()); }
public void testDirectedMatrixNoNodeIdZeroMissingEdges() { DirectedGraph<Integer, DefaultEdge> g = new DirectedPseudograph<>(DefaultEdge.class); g.addVertex(1); g.addVertex(2); g.addVertex(3); g.addVertex(4); g.addVertex(5); g.addEdge(1, 2); g.addEdge(1, 3); g.addEdge(3, 1); g.addEdge(3, 4); g.addEdge(4, 5); g.addEdge(5, 1); g.addEdge(5, 2); g.addEdge(5, 3); g.addEdge(5, 4); g.addEdge(5, 5); CSVExporter<Integer, DefaultEdge> exporter = new CSVExporter<>(nameProvider, CSVFormat.MATRIX, ';'); exporter.setParameter(CSVFormat.Parameter.MATRIX_FORMAT_ZERO_WHEN_NO_EDGE, true); StringWriter w = new StringWriter(); exporter.exportGraph(g, w); assertEquals(DIRECTED_MATRIX_NO_NODEID_ZERO_NO_EDGE, w.toString()); }
public void testUndirectedAdjacencyList() { UndirectedGraph<Integer, DefaultEdge> g = new Pseudograph<>(DefaultEdge.class); g.addVertex(1); g.addVertex(2); g.addVertex(3); g.addVertex(4); g.addVertex(5); g.addEdge(1, 2); g.addEdge(1, 3); g.addEdge(3, 1); g.addEdge(3, 4); g.addEdge(4, 5); g.addEdge(5, 1); g.addEdge(5, 2); g.addEdge(5, 3); g.addEdge(5, 4); g.addEdge(5, 5); g.addEdge(5, 5); CSVExporter<Integer, DefaultEdge> exporter = new CSVExporter<>(nameProvider, CSVFormat.ADJACENCY_LIST, ';'); StringWriter w = new StringWriter(); exporter.exportGraph(g, w); assertEquals(UNDIRECTED_ADJACENCY_LIST, w.toString()); }
public void testUndirected() { UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); g.addVertex(V3); g.addEdge(V3, V1); StringWriter w = new StringWriter(); exporter.export(w, g); assertEquals(UNDIRECTED, w.toString()); }
public void testAdjacencyUndirected() { UndirectedGraph<String, DefaultEdge> g = new Pseudograph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); g.addVertex(V3); g.addEdge(V3, V1); g.addEdge(V1, V1); StringWriter w = new StringWriter(); exporter.exportAdjacencyMatrix(w, g); assertEquals(UNDIRECTED_ADJACENCY, w.toString()); }
public void testLaplacian() { UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge>(DefaultEdge.class); g.addVertex(V1); g.addVertex(V2); g.addEdge(V1, V2); g.addVertex(V3); g.addEdge(V3, V1); StringWriter w = new StringWriter(); exporter.exportLaplacianMatrix(w, g); assertEquals(LAPLACIAN, w.toString()); w = new StringWriter(); exporter.exportNormalizedLaplacianMatrix(w, g); assertEquals(NORMALIZED_LAPLACIAN, w.toString()); }
public void testEdgeListWithStringsDirectedUnweightedWithSemicolon() throws ImportException { DirectedPseudograph<String, DefaultEdge> g = new DirectedPseudograph<>(DefaultWeightedEdge.class); g.addVertex("'john doe'"); g.addVertex("fred"); g.addVertex("fred\n\"21\""); g.addVertex("who;;"); g.addEdge("'john doe'", "fred"); g.addEdge("fred", "fred\n\"21\""); g.addEdge("fred\n\"21\"", "who;;"); g.addEdge("who;;", "'john doe'"); CSVExporter<String, DefaultEdge> exporter = new CSVExporter<>(stringNameProvider, CSVFormat.EDGE_LIST, ';'); StringWriter w = new StringWriter(); exporter.exportGraph(g, w); assertEquals(DIRECTED_EDGE_LIST_ESCAPE, w.toString()); }
public void testDirectedEdgeList() { DirectedGraph<Integer, DefaultEdge> g = new SimpleDirectedGraph<>(DefaultEdge.class); g.addVertex(1); g.addVertex(2); g.addVertex(3); g.addVertex(4); g.addVertex(5); g.addEdge(1, 2); g.addEdge(1, 3); g.addEdge(3, 1); g.addEdge(3, 4); g.addEdge(4, 5); g.addEdge(5, 1); CSVExporter<Integer, DefaultEdge> exporter = new CSVExporter<>(nameProvider, CSVFormat.EDGE_LIST, ';'); StringWriter w = new StringWriter(); exporter.exportGraph(g, w); assertEquals(DIRECTED_EDGE_LIST, w.toString()); }