/** * */ package it.univr.di.cstnu.graph; import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet; import it.unimi.dsi.fastutil.objects.ObjectList; import it.unimi.dsi.fastutil.objects.ObjectSortedSet; import org.apache.commons.lang3.tuple.Triple; import org.junit.Test; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import static org.junit.Assert.assertEquals; /** * @author posenato */ public class TNGraphTest { /** * */ static File fileSTNU = new File("src/test/resources/dc_500nodes_050ctgs_5lanes_001_SQRT_CTG_DENSE.stnu"); /** * */ TNGraphMLReader readerSTNU; /** * */ TNGraph stnu; /** * Check the method getEdgeCount() * * @throws IOException if any error * @throws ParserConfigurationException if any error * @throws SAXException if any error. */ @Test public void testSTNUGetEdgeCount() throws Exception { this.readerSTNU = new TNGraphMLReader<>(); this.stnu = this.readerSTNU.readGraph(fileSTNU, STNUEdgeInt.class); assertEquals(2254, this.stnu.getEdgeCount()); } /** * Dijkstra */ @Test public void testgetEdgesNodes() { final LabeledNode W = new LabeledNode("W"); final LabeledNode Y = new LabeledNode("Y"); final LabeledNode X = new LabeledNode("X"); final LabeledNode Z = new LabeledNode("Z"); final LabeledNode Ω = new LabeledNode("Ω"); final TNGraph graph = new TNGraph<>("graph", STNEdgeInt.class); graph.addVertex(W); graph.addVertex(X); graph.addVertex(Y); graph.addVertex(Z); STNEdge e = new STNEdgeInt("WΩ", -1); graph.addEdge(e, W, Ω); e = new STNEdgeInt("XW", -1); graph.addEdge(e, X, W); e = new STNEdgeInt("XY", 1); graph.addEdge(e, X, Y); e = new STNEdgeInt("XZ", 2); graph.addEdge(e, X, Z); e = new STNEdgeInt("YΩ", 0); graph.addEdge(e, Y, Ω); e = new STNEdgeInt("ZΩ", 3); graph.addEdge(e, Z, Ω); final ObjectList> list = graph.getEdgesAndNodes(); final ObjectSortedSet> sorted = new ObjectAVLTreeSet<>(list); assertEquals( "{(❮W❯,❮WΩ; requirement; -1; ❯,❮Ω❯), (❮X❯,❮XW; requirement; -1; ❯,❮W❯), (❮X❯,❮XY; requirement; 1; ❯,❮Y❯), (❮X❯,❮XZ; requirement; 2; ❯,❮Z❯), (❮Y❯,❮YΩ; requirement; 0; ❯,❮Ω❯), (❮Z❯,❮ZΩ; requirement; 3; ❯,❮Ω❯)}" , sorted.toString()); } }