@Test public void nodesBeforeEdges() { GraphWidget graph = parse("graph{1;2;3;4; 1->2;2->3;2->4}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(4, graph.getNodes().size()); Assert.assertEquals(3, graph.getConnections().size()); }
@Test public void globalEdgeStyle() { GraphWidget graph = parse("graph Sample{edge[style=dashed];1;2;1->2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( SWT.LINE_DASH, ((GraphConnection) graph.getConnections().get(0)).getLineStyle()); }
@Test /* see http://www.graphviz.org/doc/info/attrs.html#d:style */ public void edgeStyleInvis() { GraphWidget graph = parse("digraph{1->2[style=invis]}"); // $NON-NLS-1$ assertEquals(2, graph.getNodes().size()); assertEquals(1, graph.getConnections().size()); }
@Test public void headerCommentGraph() { GraphWidget graph = parse("/*A header comment*/\ngraph{1--2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(2, graph.getNodes().size()); Assert.assertEquals(1, graph.getConnections().size()); }
@Test public void globalNodeLabel() { GraphWidget graph = parse("graph Sample{node[label=\"Node1\"];1;}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "Node1", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); }
@Test public void nodesAfterEdges() { GraphWidget graph = parse("graph{1->2;2->3;2->4;1[label=\"node\"];2;3;4}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(4, graph.getNodes().size()); Assert.assertEquals(3, graph.getConnections().size()); Assert.assertEquals("node", ((GraphNode) graph.getNodes().get(0)).getText()); }
@Test public void nodeDefaultLabel() { GraphWidget graph = parse("graph Sample{1}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "1", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); }
@Test public void otherUnsupportedStyles() { GraphWidget graph = parse( "graph Sample{node[style=other];edge[style=other];1[style=other];2;1->2[style=other]}"); //$NON-NLS-1$ assertEquals(2, graph.getNodes().size()); assertEquals(1, graph.getConnections().size()); }
@Test public void globalNodeAttributeAdHocNodes() { GraphWidget graph = parse("graph{node[label=\"TEXT\"];1--2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "TEXT", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); }
@Test public void undeclaredNodes() { GraphWidget graph = new GraphWidget( new DotImport("digraph{1->2;1->3}").newGraphInstance(), new Shell(), SWT.NONE); Assert.assertEquals(3, graph.getNodes().size()); Assert.assertEquals(2, graph.getConnections().size()); }
@Test public void graphType() { GraphWidget graph = parse("graph Sample{1;2;1--2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(ZestStyles.CONNECTIONS_SOLID, graph.getConnectionStyle()); Assert.assertEquals( ZestStyles.CONNECTIONS_SOLID, ((GraphConnection) graph.getConnections().get(0)).getConnectionStyle()); }
@Test public void layoutHorizontalTreeViaAttribute() { GraphWidget graph = parse("graph Sample{rankdir=LR;1;}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(TreeLayoutAlgorithm.class, graph.getLayoutAlgorithm().getClass()); Assert.assertEquals( TreeLayoutAlgorithm.LEFT_RIGHT, ((TreeLayoutAlgorithm) (graph.getLayoutAlgorithm())).getDirection()); }
@Test public void clusterSubgraph() { Shell shell = new Shell(); DotImport dotImport = new DotImport("digraph{subgraph cluster_1{1->2}; subgraph cluster_2{1->3}}"); GraphWidget graph = new GraphWidget(dotImport.newGraphInstance(), shell, SWT.NONE); assertEquals("Cluster subgraphs are ignored in rendering", 3, graph.getNodes().size()); assertEquals(2, graph.getConnections().size()); }
@Test public void dotImport() { Shell shell = new Shell(); DotImport importer = new DotImport("digraph Sample{1;2;1->2}"); // $NON-NLS-1$ GraphWidget graph = new GraphWidget(importer.newGraphInstance(), shell, SWT.NONE); Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(ZestStyles.CONNECTIONS_DIRECTED, graph.getConnectionStyle()); // open(shell); }
@Test public void newLinesInLabels() { String dot = "graph{n1[label=\"node\n1\"]}"; // $NON-NLS-1$ GraphWidget graph = parse(dot); Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "node\n1", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); }
@Test public void useInterpreterTwice() { String dot = "graph{1;2;3;4; 1->2;2->3;2->4}"; // $NON-NLS-1$ GraphWidget graph = parse(dot); graph = parse(dot); Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(4, graph.getNodes().size()); Assert.assertEquals(3, graph.getConnections().size()); }
@Test public void multiEdgeStatements() { GraphWidget graph = parse("digraph{1->2->3->4}"); // $NON-NLS-1$ assertEquals(4, graph.getNodes().size()); assertEquals(3, graph.getConnections().size()); /* Each node should be connected to one other, the next node: */ assertEquals(1, ((GraphNode) graph.getNodes().get(0)).getSourceConnections().size()); assertEquals(1, ((GraphNode) graph.getNodes().get(1)).getSourceConnections().size()); assertEquals(1, ((GraphNode) graph.getNodes().get(2)).getSourceConnections().size()); }
@Test public void globalEdgeAttributeAdHocNodes() { GraphWidget graph = parse("graph{edge[label=\"TEXT\"];1--2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "TEXT", ((GraphConnection) graph .getConnections() //$NON-NLS-1$ .get(0)) .getText()); }
@Test public void globalEdgeLabel() { GraphWidget graph = parse("graph Sample{edge[label=\"Edge1\"];1;2;1->2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "Edge1", ((GraphConnection) graph .getConnections() //$NON-NLS-1$ .get(0)) .getText()); }
@Test public void idsWithQuotes() { String dot = "graph{\"node 1\";\"node 2\"}"; // $NON-NLS-1$ GraphWidget graph = parse(dot); Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "node 1", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); Assert.assertEquals( "node 2", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(1)).getText()); }
@Test public void fullyQuoted() { String dot = "graph{\"n1\";\"n2\";\"n1\"->\"n2\"}"; // $NON-NLS-1$ GraphWidget graph = parse(dot); Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(2, graph.getNodes().size()); Assert.assertEquals(1, graph.getConnections().size()); Assert.assertEquals( "n1", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); Assert.assertEquals( "n2", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(1)).getText()); }
@Test public void labelsWithQuotes() { String dot = "graph{n1[label=\"node 1\"];n2[label=\"node 2\"];n1--n2[label=\"edge 1\"]}"; //$NON-NLS-1$ GraphWidget graph = parse(dot); Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals( "node 1", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(0)).getText()); Assert.assertEquals( "node 2", //$NON-NLS-1$ ((GraphNode) graph.getNodes().get(1)).getText()); Assert.assertEquals( "edge 1", ((GraphConnection) graph .getConnections() //$NON-NLS-1$ .get(0)) .getText()); }
@Test public void layoutTree() { GraphWidget graph = parse("graph Sample{graph[layout=dot];1;}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(TreeLayoutAlgorithm.class, graph.getLayoutAlgorithm().getClass()); }
@Test public void edgeCount() { GraphWidget graph = parse("graph Sample{1;2;1->2;2->2;1->1}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(3, graph.getConnections().size()); }
@Test public void nodeCount() { GraphWidget graph = parse("graph Sample{1;2}"); // $NON-NLS-1$ Assert.assertNotNull("Created graph must not be null", graph); // $NON-NLS-1$ Assert.assertEquals(2, graph.getNodes().size()); }