The test suite for Graph.
| 11 | |
| 12 | /** The test suite for {@link Graph}. */ |
| 13 | @org.junit.jupiter.api.Tag("UnitTests") |
| 14 | public class GraphTest { |
| 15 | private static final Edge E0 = |
| 16 | Edge.of(NodeId.of("dataset:test-namespace:a"), NodeId.of("job:test-namespace:c")); |
| 17 | private static final Edge E1 = |
| 18 | Edge.of(NodeId.of("dataset:test-namespace:b"), NodeId.of("job:test-namespace:c")); |
| 19 | private static final Edge E2 = |
| 20 | Edge.of(NodeId.of("job:test-namespace:c"), NodeId.of("dataset:test-namespace:d")); |
| 21 | private static final Edge E3 = |
| 22 | Edge.of(NodeId.of("job:test-namespace:c"), NodeId.of("dataset:test-namespace:e")); |
| 23 | |
| 24 | private static final Node N0 = Node.dataset().id(NodeId.of("dataset:test-namespace:a")).build(); |
| 25 | private static final Node N1 = Node.dataset().id(NodeId.of("dataset:test-namespace:b")).build(); |
| 26 | private static final Node N2 = |
| 27 | Node.job().id(NodeId.of("job:test-namespace:c")).inEdges(E0, E1).outEdges(E2, E3).build(); |
| 28 | private static final Node N3 = Node.dataset().id(NodeId.of("dataset:test-namespace:d")).build(); |
| 29 | private static final Node N4 = Node.dataset().id(NodeId.of("dataset:test-namespace:e")).build(); |
| 30 | |
| 31 | @Test |
| 32 | public void testDirectedGraph() { |
| 33 | final Graph graph = Graph.directed().nodes(N0, N1, N2, N3, N4).build(); |
| 34 | assertThat(graph.nodes()).containsExactly(N0, N1, N3, N4, N2); |
| 35 | } |
| 36 | |
| 37 | @Test |
| 38 | public void testDirectedGraph_unordered() { |
| 39 | final Graph graph = Graph.directed().nodes(N0, N2, N1, N3, N4).build(); |
| 40 | assertThat(graph.nodes()).containsExactly(N0, N1, N3, N4, N2); |
| 41 | } |
| 42 | |
| 43 | @Test |
| 44 | public void testDirectedGraph_backwards() { |
| 45 | final Graph graph = Graph.directed().nodes(N4, N3, N2, N1, N0).build(); |
| 46 | assertThat(graph.nodes()).containsExactly(N0, N1, N3, N4, N2); |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void testDirectedGraph_edges_unordered() { |
| 51 | final Node nodeWithEdgesUnordered = |
| 52 | Node.job().id(NodeId.of("job:test-namespace:c")).inEdges(E1, E0).outEdges(E2, E3).build(); |
| 53 | final Graph graph = Graph.directed().nodes(N0, N1, nodeWithEdgesUnordered, N3, N4).build(); |
| 54 | assertThat(graph.nodes()).containsExactly(N0, N1, N3, N4, N2); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void testDirectedGraph_edges_backwards() { |
| 59 | final Node nodeWithEdgesBackwards = |
| 60 | Node.job().id(NodeId.of("job:test-namespace:c")).inEdges(E1, E0).outEdges(E3, E2).build(); |
| 61 | final Graph graph = Graph.directed().nodes(N0, N1, nodeWithEdgesBackwards, N3, N4).build(); |
| 62 | assertThat(graph.nodes()).containsExactly(N0, N1, N3, N4, N2); |
| 63 | } |
| 64 | } |