Пример #1
0
        public void InsertAndRemoveAtAll <TPriority, TValue>(
            [PexAssumeUnderTest] BinaryHeap <TPriority, TValue> target,
            [PexAssumeNotNull] KeyValuePair <TPriority, TValue>[] kvs)
        {
            foreach (var kv in kvs)
            {
                target.Add(kv.Key, kv.Value);
            }
            var call = PexChoose.FromCall(this);

            for (int i = target.Count - 1; i > -1; ++i)
            {
                target.RemoveAt(call.ValueFromRange(i.ToString(), 0, target.Count - 1));
                AssertInvariant <TPriority, TValue>(target);
            }
        }
        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);
                }
            }
        }
Пример #3
0
        /// 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);
                }
            }
        }