/// Summary /// Time: 1 min 59 sec /// Pattern: AAAA, AllowedException public void AddRemoveVertexNotFound([PexAssumeUnderTest] AdjacencyGraph g) { IVertex v = RandomGraph.Vertex(g, new Random()); g.RemoveVertex(v); PexAssert.IsFalse(g.ContainsVertex(v)); g.RemoveVertex(v); PexAssert.IsTrue(false, "ArgumentNullException was expected"); }
/// Summary /// Time: 1 min 8 sec /// Pattern: AAAA, Allowed Exception public void AddEdgeTargetNotFound([PexAssumeUnderTest] AdjacencyGraph g) { IVertex v = RandomGraph.Vertex(g, new Random()); IVertex target = RandomGraph.Vertex(g, new Random()); PexAssume.IsTrue(v != target); g.RemoveVertex(target); IEdge e = g.AddEdge(v, target); PexAssert.IsTrue(false); //Should not be reached }
/// Summary /// Time: 1 min 3 sec /// Pattern: AAAA, Allowed Exception public void AddEdgeSourceNotFound([PexAssumeUnderTest] AdjacencyGraph g) { IVertex v = RandomGraph.Vertex(g, new Random()); IVertex source = RandomGraph.Vertex(g, new Random()); PexAssume.IsTrue(v != source); g.RemoveVertex(source); IEdge e = g.AddEdge(source, v); PexAssert.IsTrue(false); //Should not be reached }
public void GraphWithSelfEdgesPUT(AdjacencyGraph g, int loopBound, bool self) { Random rnd; //new Random(); var choose1 = PexChoose.FromCall(this); rnd = choose1.ChooseValue <Random>("Random object"); Init(); for (int i = 0; i < loopBound; ++i) { for (int j = 0; j < i * i; ++j) { RandomGraph.Graph(g, i, j, rnd, true); Init(); DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g); dfs.StartVertex += new VertexHandler(this.StartVertex); dfs.DiscoverVertex += new VertexHandler(this.DiscoverVertex); dfs.ExamineEdge += new EdgeHandler(this.ExamineEdge); dfs.TreeEdge += new EdgeHandler(this.TreeEdge); dfs.BackEdge += new EdgeHandler(this.BackEdge); dfs.ForwardOrCrossEdge += new EdgeHandler(this.FowardOrCrossEdge); dfs.FinishVertex += new VertexHandler(this.FinishVertex); Parents.Clear(); DiscoverTimes.Clear(); FinishTimes.Clear(); m_Time = 0; foreach (IVertex v in g.Vertices) { Parents[v] = v; } var choose = PexChoose.FromCall(this); if (choose.ChooseValue <bool>("to add a self ede")) { IVertex selfEdge = RandomGraph.Vertex(g, rnd); g.AddEdge(selfEdge, selfEdge); } // compute dfs.Compute(); CheckDfs(g, dfs); } } }
/// Summary /// Time: 8 min 17 sec /// Pattern: AAAA, Parameterized stub /// Pex Limitations - Not able to generate any test due to the following issue: /// <boundary> maxbranches - 40000 (maximum number of branches exceeded) /// [execution] Please notice: A branch in the method System.Collections.Hashtable+HashtableEnumerator.MoveNext was executed 5777 times; /// please check that the code is not stuck in an infinite loop. /// [test] (run 1) GraphWithoutSelfEdgesPUT01, pathboundsexceeded (duplicate) /// [execution] Please notice: A branch in the method System.Collections.Hashtable+HashtableEnumerator.MoveNext was executed 4344 times; /// please check that the code is not stuck in an infinite loop. /// [test] (run 2) GraphWithoutSelfEdgesPUT01, pathboundsexceeded (duplicate) /// <summary> /// @Author:Madhuri /// </summary> public void GraphWithSelfEdgesPUT(AdjacencyGraph g, int loopBound) { Random rnd = new Random(); Init(); for (int i = 0; i < loopBound; ++i) { for (int j = 0; j < i * i; ++j) { RandomGraph.Graph(g, i, j, rnd, true); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(g); bfs.InitializeVertex += new VertexHandler(this.InitializeVertex); bfs.DiscoverVertex += new VertexHandler(this.DiscoverVertex); bfs.ExamineEdge += new EdgeHandler(this.ExamineEdge); bfs.ExamineVertex += new VertexHandler(this.ExamineVertex); bfs.TreeEdge += new EdgeHandler(this.TreeEdge); bfs.NonTreeEdge += new EdgeHandler(this.NonTreeEdge); bfs.GrayTarget += new EdgeHandler(this.GrayTarget); bfs.BlackTarget += new EdgeHandler(this.BlackTarget); bfs.FinishVertex += new VertexHandler(this.FinishVertex); Parents.Clear(); Distances.Clear(); m_CurrentDistance = 0; m_SourceVertex = RandomGraph.Vertex(g, rnd); var choose = PexChoose.FromCall(this); if (choose.ChooseValue <bool>("to add a self ede")) { IVertex selfEdge = RandomGraph.Vertex(g, rnd); g.AddEdge(selfEdge, selfEdge); } // g.RemoveEdge(RandomGraph.Edge(g, rnd)); foreach (IVertex v in g.Vertices) { Distances[v] = int.MaxValue; Parents[v] = v; } Distances[SourceVertex] = 0; bfs.Compute(SourceVertex); CheckBfs(g, bfs); } } }
public void GraphWithSelfEdges() { Random rnd = new Random(); for (int i = 0; i < 10; ++i) { for (int j = 0; j < i * i; ++j) { AdjacencyGraph g = new AdjacencyGraph( new QuickGraph.Providers.VertexProvider(), new QuickGraph.Providers.EdgeProvider(), true); RandomGraph.Graph(g, i, j, rnd, true); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(g); bfs.InitializeVertex += new VertexEventHandler(this.InitializeVertex); bfs.DiscoverVertex += new VertexEventHandler(this.DiscoverVertex); bfs.ExamineEdge += new EdgeEventHandler(this.ExamineEdge); bfs.ExamineVertex += new VertexEventHandler(this.ExamineVertex); bfs.TreeEdge += new EdgeEventHandler(this.TreeEdge); bfs.NonTreeEdge += new EdgeEventHandler(this.NonTreeEdge); bfs.GrayTarget += new EdgeEventHandler(this.GrayTarget); bfs.BlackTarget += new EdgeEventHandler(this.BlackTarget); bfs.FinishVertex += new VertexEventHandler(this.FinishVertex); Parents.Clear(); Distances.Clear(); m_CurrentDistance = 0; m_SourceVertex = RandomGraph.Vertex(g, rnd); foreach (IVertex v in g.Vertices) { Distances[v] = int.MaxValue; Parents[v] = v; } Distances[SourceVertex] = 0; bfs.Compute(SourceVertex); CheckBfs(g, bfs); } } }
static void Main(string[] args) { try { /* * VertexStringDictionary verticesNames = new VertexStringDictionary(); * EdgeStringDictionary edgesNames = new EdgeStringDictionary(); * EdgeDoubleDictionary edgesWeights = new EdgeDoubleDictionary(); * IncidenceGraph g = new IncidenceGraph(true); * * // adding vertex * Vertex u = g.AddVertex(); * verticesNames[u]="u"; * Vertex v = g.AddVertex(); * verticesNames[v]="v"; * Vertex w = g.AddVertex(); * verticesNames[w]="w"; * Vertex x = g.AddVertex(); * verticesNames[x]="x"; * Vertex y = g.AddVertex(); * verticesNames[y]="y"; * Vertex z = g.AddVertex(); * verticesNames[z]="z"; * * // adding edges * Edge uv = g.AddEdge(u,v); * edgesNames[uv]="uv"; * edgesWeights[uv]=1; * Edge ux = g.AddEdge(u,x); * edgesNames[ux]="ux"; * edgesWeights[ux]=0.8; * Edge wu = g.AddEdge(w,u); * g.AddEdge(w,u); * edgesNames[wu]="wu"; * edgesWeights[wu]=0.2; * Edge xv = g.AddEdge(x,v); * edgesNames[xv]="xv"; * edgesWeights[xv]=1.1; * Edge vy = g.AddEdge(v,y); * edgesNames[vy]="vy"; * edgesWeights[vy]=2.0; * Edge wy = g.AddEdge(w,y); * edgesNames[wy]="wy"; * edgesWeights[wy]=1.5; * Edge yw = g.AddEdge(y,w); * edgesNames[yw]="yw"; * edgesWeights[yw]=0.2; * Edge wz = g.AddEdge(w,z); * edgesNames[wz]="wz"; * edgesWeights[wz]=0.1; * * RandomGraph.Graph(g, 20,50,new Random(),true); * * /* * // do a dfs serach * Console.WriteLine("---- DepthFirstSearch"); * DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g); * //TestDepthFirstSearchVisitor dfsVis = * // new TestDepthFirstSearchVisitor(dfs,verticesNames); * AlgorithmTracerVisitor dfstracer = new * AlgorithmTracerVisitor(g,"dfs",".",GraphvizImageType.Png); * dfstracer.VertexLabels = verticesNames; * dfstracer.RegisterVertexHandlers(dfs); * dfstracer.RegisterEdgeHandlers(dfs); * * dfs.Compute(); */ Vertex source = u; source = RandomGraph.Vertex(g, new Random()); Console.WriteLine("source: {0}", source.GetHashCode()); Console.WriteLine("---- BreathFirstSearch"); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(g); TestBreadthFirstSearchVisitor bfsVis = new TestBreadthFirstSearchVisitor(bfs, verticesNames, source); AlgorithmTracerVisitor bfstracer = new AlgorithmTracerVisitor(g, "bfs", ".", GraphvizImageType.Png); // bfstracer.VertexLabels = verticesNames; bfs.RegisterTreeEdgeBuilderHandlers(bfsTracer); bfs.RegisterVertexColorizeHandlers(bfsTracer); bfs.Compute(source); /* * Console.WriteLine("---- Dijkstra"); * DijkstraShortestPathAlgorithm dij = new DijkstraShortestPathAlgorithm( * g, * edgesWeights * ); * TestDijkstraShortestPathVisitor dijVis = new TestDijkstraShortestPathVisitor(dij,verticesNames); * AlgorithmTracerVisitor dijtracer = new * AlgorithmTracerVisitor(g,"dij",".",GraphvizImageType.Png); * dijtracer.VertexLabels = verticesNames; * dijtracer.EdgeLabels = edgesWeights; * dijtracer.RegisterVertexHandlers(dij); * // dijtracer.RegisterEdgeHandlers(dij); * dij.Compute(g.Vertex(0)); * * Console.WriteLine("Distance from {0}", verticesNames[g.Vertex(0)]); * foreach(DictionaryEntry de in dij.Distances) * { * * Console.WriteLine("\t-> {0}, {1}", * verticesNames[(Vertex)de.Key], * de.Value.ToString() * ); * } * * Console.WriteLine("---- Topological sort"); * VertexCollection vs = new VertexCollection(); * TopologicalSortAlgorithm tps= new TopologicalSortAlgorithm(g); * tps.Compute(vs); * foreach(Vertex ve in vs) * { * Console.WriteLine("v - {0}",verticesNames[ve]); * } * * Console.WriteLine("--- graphviz output"); * GraphvizWriterAlgorithm gw = new GraphvizWriterAlgorithm( * g,"dotgenerator",".",GraphvizImageType.Png); * TestGraphvizVertex gv = new TestGraphvizVertex(verticesNames); * gw.WriteVertex += new VertexHandler( gv.WriteVertex ); * gw.WriteEdge+= new EdgeHandler( gv.WriteEdge ); * gw.Write(GraphvizImageType.Png); * gw.Write(GraphvizImageType.Svg); * gw.Write(GraphvizImageType.Svgz); * gw.Write(GraphvizImageType.Gif); * gw.Write(GraphvizImageType.Jpeg); */ Console.WriteLine("Test finished"); String s2 = Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); String s = Console.ReadLine(); } }