Ejemplo n.º 1
0
  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());
  }
Ejemplo n.º 2
0
  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());
  }
Ejemplo n.º 3
0
  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());
  }
Ejemplo n.º 4
0
  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());
  }
Ejemplo n.º 5
0
  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());
  }
Ejemplo n.º 6
0
  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());
  }
Ejemplo n.º 7
0
  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());
  }
Ejemplo n.º 8
0
  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());
  }
Ejemplo n.º 9
0
  /**
   * Test whether output routines work as expected. This is done by comparing generating output on a
   * file "useOutput.txt" and comparing it to a file "expectedOutput.txt". On a first run this test
   * might break because the file "expectedOutput.txt" does not exist. Then just run the test,
   * verify manually whether "useOutput.txt" conforms to the expected output and if it does rename
   * "useOutput.txt" in "expectedOutput.txt". From then on the tests should work as expected.
   */
  public void testOutput() {
    Network network = Network.DefaultExample();
    String generateOutputFName = "useOutput.txt", expectedOutputFName = "expectedOutput.txt";
    FileWriter generateOutput;
    StringBuffer buf = new StringBuffer(500);
    StringWriter report = new StringWriter(500);

    try {
      generateOutput = new FileWriter(generateOutputFName);
    } catch (IOException f2exc) {
      assertTrue("Could not create '" + generateOutputFName + "'", false);
      return;
    }
    ;

    try {
      buf.append(
          "---------------------------------ASCII------------------------------------------\n");
      network.printOn(buf);
      buf.append(
          "\n\n---------------------------------HTML------------------------------------------\n");
      network.printHTMLOn(buf);
      buf.append(
          "\n\n---------------------------------XML------------------------------------------\n");
      network.printXMLOn(buf);
      generateOutput.write(buf.toString());
      report.write(
          "\n\n---------------------------------SCENARIO: Print Success --------------------------\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "Andy", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (UnkownPrinter) ------------\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "UnknownPrinter", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (print on Workstation) -----\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "Hans", report);
      report.write(
          "\n\n---------------------------------SCENARIO: PrintFailure (print on Node) -----\n");
      network.requestWorkstationPrintsDocument("Filip", "Hello World", "n1", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Print Success Postscript-----------------\n");
      network.requestWorkstationPrintsDocument(
          "Filip", "!PS Hello World in postscript", "Andy", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Print Failure Postscript-----------------\n");
      network.requestWorkstationPrintsDocument(
          "Filip", "!PS Hello World in postscript", "Hans", report);
      report.write(
          "\n\n---------------------------------SCENARIO: Broadcast Success -----------------\n");
      network.requestBroadcast(report);
      generateOutput.write(report.toString());
    } catch (IOException exc) {
    } finally {
      try {
        generateOutput.close();
      } catch (IOException exc) {
      }
      ;
    }
    ;
    assertTrue(
        "Generated output is not as expected ",
        compareFiles(generateOutputFName, expectedOutputFName));
  }