1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.building;
20
21 import java.io.IOException;
22 import java.nio.file.Files;
23 import java.nio.file.Paths;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.List;
27
28 import org.junit.jupiter.api.Test;
29
30 import static org.junit.jupiter.api.Assertions.assertThrows;
31
32 public class GraphTest {
33
34 @Test
35 void testCycle() throws Graph.CycleDetectedException {
36 Graph graph = new Graph();
37 graph.addEdge("a1", "a2");
38 assertThrows(Graph.CycleDetectedException.class, () -> graph.addEdge("a2", "a1"));
39 }
40
41 @Test
42 public void testPerf() throws IOException {
43 List<String[]> data = new ArrayList<>();
44 String k = null;
45 for (String line : Files.readAllLines(Paths.get("src/test/resources/dag.txt"))) {
46 if (line.startsWith("\t")) {
47 data.add(new String[] {k, line.trim()});
48 } else {
49 k = line;
50 }
51 }
52 Collections.shuffle(data);
53
54 long t0 = System.nanoTime();
55 Graph g = new Graph();
56 data.parallelStream().forEach(s -> {
57 try {
58 g.addEdge(s[0], s[1]);
59 } catch (Exception e) {
60 throw new RuntimeException(e);
61 }
62 });
63 long t1 = System.nanoTime();
64 }
65 }