1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.graph
.core
.tests
.stubs
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNull
;
16 import java
.util
.List
;
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
;
26 * Class that implements static operations on vertices and edges. The sets of
27 * nodes and vertices can then be transformed to a graph.
29 * @author Geneviève Bastien
30 * @author Francis Giraldeau
32 public class GraphOps
{
35 * Check whether 2 graphs are identical
38 * The first graph to compare
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());
56 for (EdgeDirection dir
: EdgeDirection
.values()) {
58 throw new NullPointerException();
60 TmfEdge edge1
= v1
.getEdge(dir
);
61 TmfEdge edge2
= v2
.getEdge(dir
);
67 assertEquals("Edge type for " + graphObject
+ ", node " + i
, edge1
.getType(), edge2
.getType());
68 assertEquals("Edge duration for " + graphObject
+ ", node " + i
+ " edge direction " + dir
, edge1
.getDuration(), edge2
.getDuration());
69 assertEquals("From objects for " + graphObject
+ ", node " + i
, g1
.getParentOf(edge1
.getVertexFrom()), g2
.getParentOf(edge2
.getVertexFrom()));
70 assertEquals("To objects for" + graphObject
+ ", node " + i
, g1
.getParentOf(edge1
.getVertexTo()), g2
.getParentOf(edge2
.getVertexTo()));
This page took 0.031601 seconds and 5 git commands to generate.