コード例 #1
0
  @Test
  public void testRandom() throws GraphFactoryException {
    Random random = new Random();
    int order = random.nextInt(40) + 1;
    int maxEdge = order * (order - 1);
    int nbEdge = (maxEdge > 0) ? random.nextInt(maxEdge) : 0;
    graph = new AdjencyListDGraph(GraphFactory.createRandomMatrix(order, nbEdge, true));

    assertThat(graph.addNode(), is(order));
    int randomVertex = random.nextInt(order);
    for (Integer succ : graph.getSuccessors(randomVertex)) {
      assertThat(graph.getPredecessors(succ), hasItem(randomVertex));
    }
    assertThat(graph.inverse().inverse().getGraph(), is(graph.getGraph()));
  }
コード例 #2
0
 @Test
 public void testGetPredecessors() throws Exception {
   List<Integer> resultList = graph.getPredecessors(3);
   Integer[] pred = {0, 1, 2};
   List<Integer> expectedList = Arrays.asList(pred);
   assertEquals(expectedList, resultList);
 }
コード例 #3
0
 @Test
 public void testGetSuccessors() throws Exception {
   List<Integer> resultList = graph.getSuccessors(3);
   Integer[] succ = {1, 2, 4};
   List<Integer> expectedList = Arrays.asList(succ);
   assertEquals(expectedList, resultList);
 }
コード例 #4
0
 @Test
 public void testInverse() {
   int[][] resultMatrix = graph.inverse().getGraph();
   int[][] expectedMatrix = {
     {0, 1, 1, 0, 1}, {0, 0, 1, 1, 0}, {1, 1, 0, 1, 1}, {1, 1, 1, 0, 0}, {1, 0, 1, 1, 0}
   };
   assertThat(resultMatrix, is(expectedMatrix));
 }
コード例 #5
0
 @Test
 public void testAddEdge() throws Exception {
   graph.addArc(4, 3);
   assertTrue(graph.isArc(4, 3));
 }
コード例 #6
0
 @Test
 public void testRemoveEdge() throws Exception {
   graph.removeArc(0, 2);
   assertFalse(graph.isArc(0, 2));
 }
コード例 #7
0
 @Test
 public void testIsEdge() throws Exception {
   assertTrue(graph.isArc(0, 2));
   assertFalse(graph.isArc(4, 4));
 }
コード例 #8
0
 @Test
 public void testAddVertex() throws Exception {
   int val = graph.addNode();
   assertEquals(val, 5);
 }