|
40 | 40 |
|
41 | 41 | import java.util.HashSet; |
42 | 42 | import java.util.List; |
43 | | -import java.util.Set; |
44 | 43 | import java.util.concurrent.atomic.AtomicLong; |
45 | 44 | import java.util.stream.LongStream; |
46 | 45 |
|
47 | 46 | import static org.assertj.core.api.Assertions.assertThat; |
48 | 47 | import static org.junit.jupiter.api.Assertions.assertEquals; |
49 | | -import static org.junit.jupiter.api.Assertions.assertFalse; |
50 | | -import static org.junit.jupiter.api.Assertions.assertNotEquals; |
51 | 48 | import static org.junit.jupiter.api.Assertions.assertTrue; |
52 | 49 | import static org.neo4j.gds.TestSupport.fromGdl; |
53 | 50 | import static org.neo4j.gds.core.concurrency.ParallelUtil.DEFAULT_BATCH_SIZE; |
@@ -81,9 +78,17 @@ void testK1Coloring() { |
81 | 78 |
|
82 | 79 | HugeLongArray colors = k1Coloring.colors(); |
83 | 80 |
|
84 | | - assertNotEquals(colors.get(0), colors.get(1)); |
85 | | - assertNotEquals(colors.get(0), colors.get(2)); |
86 | | - assertEquals(colors.get(1), colors.get(2)); |
| 81 | + var colorOfNode0 = colors.get(0); |
| 82 | + var colorOfNode1 = colors.get(1); |
| 83 | + var colorOfNode2 = colors.get(2); |
| 84 | + |
| 85 | + assertThat(colorOfNode0) |
| 86 | + .as("Color of Node0 should be unique") |
| 87 | + .isNotEqualTo(colorOfNode1) |
| 88 | + .isNotEqualTo(colorOfNode2); |
| 89 | + assertThat(colorOfNode1) |
| 90 | + .as("Color of Node1 should be unique") |
| 91 | + .isNotEqualTo(colorOfNode2); |
87 | 92 | } |
88 | 93 |
|
89 | 94 | @Test |
@@ -113,21 +118,26 @@ void testParallelK1Coloring() { |
113 | 118 | k1Coloring.compute(); |
114 | 119 | HugeLongArray colors = k1Coloring.colors(); |
115 | 120 |
|
116 | | - Set<Long> colorsUsed = new HashSet<>(100); |
117 | | - MutableLong conflicts = new MutableLong(0); |
| 121 | + var usedColors = new HashSet<>(100); |
| 122 | + var conflicts = new MutableLong(0); |
118 | 123 | graph.forEachNode((nodeId) -> { |
119 | 124 | graph.forEachRelationship(nodeId, (source, target) -> { |
120 | 125 | if (source != target && colors.get(source) == colors.get(target)) { |
121 | 126 | conflicts.increment(); |
122 | 127 | } |
123 | | - colorsUsed.add(colors.get(source)); |
| 128 | + usedColors.add(colors.get(source)); |
124 | 129 | return true; |
125 | 130 | }); |
126 | 131 | return true; |
127 | 132 | }); |
128 | 133 |
|
129 | | - assertTrue(conflicts.getValue() < 20); |
130 | | - assertTrue(colorsUsed.size() < 20); |
| 134 | + assertThat(conflicts.longValue()) |
| 135 | + .as("Conflicts should be less than 20") |
| 136 | + .isLessThan(20L); |
| 137 | + |
| 138 | + assertThat(usedColors.size()) |
| 139 | + .as("Used colors should be less than 20") |
| 140 | + .isLessThan(20); |
131 | 141 | } |
132 | 142 |
|
133 | 143 |
|
@@ -174,7 +184,9 @@ void everyNodeShouldHaveBeenColored() { |
174 | 184 |
|
175 | 185 | k1Coloring.compute(); |
176 | 186 |
|
177 | | - assertFalse(k1Coloring.usedColors().get(ColoringStep.INITIAL_FORBIDDEN_COLORS)); |
| 187 | + assertThat(k1Coloring.usedColors().get(ColoringStep.INITIAL_FORBIDDEN_COLORS)) |
| 188 | + .as("The result should not contain the initial forbidden colors") |
| 189 | + .isFalse(); |
178 | 190 | } |
179 | 191 |
|
180 | 192 | @Test |
|
0 commit comments