Example #1
0
        public static void ThreadWorker()
        {
            int total = operationsPerThread;

            GraphOperation op;
            int            u, v;
            Random         rand     = new Random();
            int            vertexId = 1;

            while (total > 0)
            {
                op = GetRandomOperation(rand);
                u  = rand.Next() % vertexId;
                v  = rand.Next() % vertexId;

                switch (op)
                {
                case GraphOperation.AddVertex:
                    u = vertexId;
                    vertexId++;
                    graph.AddVertex(u);
                    break;

                case GraphOperation.AddEdge:
                    graph.AddEdge(u, v);
                    break;

                case GraphOperation.RemoveVertex:
                    graph.RemoveVertex(u);
                    break;

                case GraphOperation.RemoveEdge:
                    graph.RemoveEdge(u, v);
                    break;

                case GraphOperation.ContainsVertex:
                    graph.ContainsVertex(u);
                    break;

                case GraphOperation.ContainsEdge:
                    break;

                case GraphOperation.BFS:
                    IExtendedGraph extendedGraph = graph as IExtendedGraph;
                    if (extendedGraph != null)
                    {
                        extendedGraph.BFS(u);
                    }

                    break;
                }

                total--;
            }
        }
        public void AddRemoveCountTest()
        {
            Init();

            foreach (var currGraph in graphs)
            {
                this.graph = currGraph;
                Thread[] threads = new Thread[3];

                for (int i = 0; i < 3; i++)
                {
                    threads[i] = new Thread(AddRemoveCountTestThread);
                    threads[i].Start();
                }

                for (int i = 0; i < 3; i++)
                {
                    threads[i].Join();
                }

                Assert.AreEqual(0, graph.GetVertexCount());
            }
        }