From f046bb61195426a864824ffda646d1d9a1634038 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Wed, 23 Dec 2020 00:11:37 +0100 Subject: [PATCH] A test for DAG width wrong for triple interdependent graph #287 --- .../mvndaemon/mvnd/builder/DagWidthTest.java | 86 +++++++++++++++++-- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/daemon/src/test/java/org/mvndaemon/mvnd/builder/DagWidthTest.java b/daemon/src/test/java/org/mvndaemon/mvnd/builder/DagWidthTest.java index 39a6480c..9af3d3b5 100644 --- a/daemon/src/test/java/org/mvndaemon/mvnd/builder/DagWidthTest.java +++ b/daemon/src/test/java/org/mvndaemon/mvnd/builder/DagWidthTest.java @@ -33,14 +33,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public class DagWidthTest { + /** + *
+     *   A   B
+     *  /|\ / \
+     * C D E   F
+     *  \|
+     *   G
+     * 
+ */ @Test void testSimpleGraph() { // - // A B - // / | \ / \ - // C D E F - // \/ - // G Map> upstreams = new HashMap<>(); upstreams.put("A", Collections.emptyList()); upstreams.put("B", Collections.emptyList()); @@ -54,11 +58,77 @@ public class DagWidthTest { assertEquals(4, new DagWidth<>(graph).getMaxWidth(12)); } + /** + *
+     *   A
+     *  /|
+     * B |
+     *  \|
+     *   C
+     * 
+ */ + @Test + void tripleLinearGraph() { + Map> upstreams = new HashMap<>(); + upstreams.put("A", Collections.emptyList()); + upstreams.put("B", Collections.singletonList("A")); + upstreams.put("C", Arrays.asList("A", "B")); + DependencyGraph graph = newGraph(upstreams); + assertEquals(1, new DagWidth<>(graph).getMaxWidth()); + } + + /** + *
+     *     A
+     *    /|\
+     *   B C D
+     *  /|\ \|
+     * E F G H
+     * 
+ */ + @Test + void multilevelSum() { + Map> upstreams = new HashMap<>(); + upstreams.put("A", Collections.emptyList()); + upstreams.put("B", Collections.singletonList("A")); + upstreams.put("C", Collections.singletonList("A")); + upstreams.put("D", Collections.singletonList("A")); + upstreams.put("E", Collections.singletonList("B")); + upstreams.put("F", Collections.singletonList("B")); + upstreams.put("G", Collections.singletonList("B")); + upstreams.put("H", Arrays.asList("C", "D")); + DependencyGraph graph = newGraph(upstreams); + assertEquals(5, new DagWidth<>(graph).getMaxWidth()); + } + + /** + *
+     *     A
+     *    /|\
+     *   B C D
+     *       |
+     *       E
+     * 
+ */ + @Test + void wide() { + Map> upstreams = new HashMap<>(); + upstreams.put("A", Collections.emptyList()); + upstreams.put("B", Collections.singletonList("A")); + upstreams.put("C", Collections.singletonList("A")); + upstreams.put("D", Collections.singletonList("A")); + upstreams.put("E", Collections.singletonList("D")); + DependencyGraph graph = newGraph(upstreams); + assertEquals(3, new DagWidth<>(graph).getMaxWidth()); + } + + /** + *
+     * A
+     * 
+ */ @Test void testSingle() { - // - // A - // Map> upstreams = new HashMap<>(); upstreams.put("A", Collections.emptyList()); DependencyGraph graph = newGraph(upstreams);