@Test public void pathMatrix_creates_transitive_closure() { matrix.setEdge(0, 1); matrix.setEdge(1, 2); matrix.setEdge(2, 3); matrix.produceTransitiveClosure(); assertThat(matrix.hasEdge(0, 2), is(true)); assertThat(matrix.hasEdge(0, 3), is(true)); assertThat(matrix.hasEdge(1, 3), is(true)); }
@Test public void howto_use_transitive_reduction_test() { createSimpleGraph(); matrix.setEdge(0, 0); // connect a vertex with itself assertThat( matrix.toString(), is("[1,1,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[0,0,0,0,1],[0,1,0,0,0]")); matrix.removeReflexiveEdges(); assertThat( matrix.toString(), is("[0,1,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[0,0,0,0,1],[0,1,0,0,0]")); matrix.produceTransitiveClosure(); assertThat( matrix.toString(), is("[0,1,1,1,1],[0,0,0,0,0],[0,1,0,1,1],[0,1,0,0,1],[0,1,0,0,0]")); matrix.transitiveReduction(); assertThat( matrix.toString(), is("[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[0,0,0,0,1],[0,1,0,0,0]")); matrix.clear(); assertThat( matrix.toString(), is("[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]")); }