Commit | Line | Data |
---|---|---|
655d677d FG |
1 | /******************************************************************************* |
2 | * Copyright (c) 2015 École Polytechnique de Montréal | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | *******************************************************************************/ | |
9 | ||
10 | package org.eclipse.tracecompass.analysis.graph.core.tests.stubs; | |
11 | ||
12 | import static org.junit.Assert.assertEquals; | |
13 | import static org.junit.Assert.assertNotNull; | |
14 | import static org.junit.Assert.assertNull; | |
15 | ||
16 | import java.util.List; | |
17 | import java.util.Set; | |
18 | ||
19 | import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker; | |
20 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge; | |
21 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph; | |
22 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex; | |
23 | import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection; | |
24 | ||
25 | /** | |
26 | * Class that implements static operations on vertices and edges. The sets of | |
27 | * nodes and vertices can then be transformed to a graph. | |
28 | * | |
29 | * @author Geneviève Bastien | |
30 | * @author Francis Giraldeau | |
31 | */ | |
32 | public class GraphOps { | |
33 | ||
34 | /** | |
35 | * Check whether 2 graphs are identical | |
36 | * | |
37 | * @param g1 | |
38 | * The first graph to compare | |
39 | * @param g2 | |
40 | * The second graph | |
41 | */ | |
42 | public static void checkEquality(TmfGraph g1, TmfGraph g2) { | |
43 | assertEquals("Graph size", g1.size(), g2.size()); | |
44 | Set<IGraphWorker> obj1 = g1.getWorkers(); | |
45 | Set<IGraphWorker> obj2 = g2.getWorkers(); | |
46 | assertEquals("Graph objects", obj1, obj2); | |
47 | for (IGraphWorker graphObject : obj1) { | |
48 | assertNotNull(graphObject); | |
49 | List<TmfVertex> nodesOf1 = g1.getNodesOf(graphObject); | |
50 | List<TmfVertex> nodesOf2 = g2.getNodesOf(graphObject); | |
51 | for (int i = 0; i < nodesOf1.size(); i++) { | |
52 | TmfVertex v1 = nodesOf1.get(i); | |
53 | TmfVertex v2 = nodesOf2.get(i); | |
54 | assertEquals("Node timestamps", v1.getTs(), v2.getTs()); | |
55 | /* Check each edge */ | |
56 | for (EdgeDirection dir : EdgeDirection.values()) { | |
655d677d FG |
57 | TmfEdge edge1 = v1.getEdge(dir); |
58 | TmfEdge edge2 = v2.getEdge(dir); | |
59 | if (edge1 == null) { | |
60 | assertNull(edge2); | |
61 | continue; | |
62 | } | |
63 | assertNotNull(edge2); | |
64 | assertEquals("Edge type for " + graphObject + ", node " + i, edge1.getType(), edge2.getType()); | |
65 | assertEquals("Edge duration for " + graphObject + ", node " + i + " edge direction " + dir, edge1.getDuration(), edge2.getDuration()); | |
66 | assertEquals("From objects for " + graphObject + ", node " + i, g1.getParentOf(edge1.getVertexFrom()), g2.getParentOf(edge2.getVertexFrom())); | |
67 | assertEquals("To objects for" + graphObject + ", node " + i, g1.getParentOf(edge1.getVertexTo()), g2.getParentOf(edge2.getVertexTo())); | |
68 | } | |
69 | } | |
70 | } | |
71 | } | |
72 | ||
73 | } |