Exemple #1
0
        public void Can_listen_for_extendedqueue_enqueue_dequeue()
        {
            ExtendedQueue <object> queue = new ExtendedQueue <object>();

            queue.Enqueued += Queue_Enqueued;

            queue.Dequeued += Queue_Dequeued;

            queue.Enqueue(1);

            object result = queue.Dequeue();

            Assert.True((int)result == 1);

            queue.Enqueued -= Queue_Enqueued;

            queue.Dequeued -= Queue_Dequeued;

            queue.Enqueued += Queue_Enqueued_Invalid;

            queue.Dequeued += Queue_Dequeued_Invalid;

            queue.Dequeue();

            queue.Enqueue(null);
        }
        public void UndirectedGraphTraverseBFS()
        {
            ExtendedQueue <Vertex> queue = new ExtendedQueue <Vertex>();

            queue.AddListBox(this.listBox);
            if (Vertex.startPoint == null)
            {
                MessageBox.Show("Válasszon ki egy kezdőpontot");
            }
            else
            {
                if (!queue.Contains(Vertex.startPoint))
                {
                    queue.Enqueue(Vertex.startPoint);
                }
            }

            while (queue.Count > 0)
            {
                Vertex tempNode = queue.Dequeue();
                tempNode.logicalState = Vertex.LogicalState.Visited;
                foreach (Edge edge in tempNode.Edges)
                {
                    Vertex otherVertex;
                    if (tempNode == edge.Start)
                    {
                        otherVertex = edge.End;
                    }
                    else
                    {
                        otherVertex = edge.Start;
                    }

                    if (otherVertex.logicalState != Vertex.LogicalState.Visited && !queue.Contains(otherVertex))
                    {
                        queue.Enqueue(otherVertex);
                    }
                    wait(edge);
                    edge.logicalState = Edge.LogicalState.Visited;
                    wait(edge);
                    otherVertex.logicalState = Vertex.LogicalState.Visited;

                    /*
                     * if(ProceedOnlyOnButtonPress)
                     * {
                     *  waitToButton();
                     *
                     *  waitToButton();
                     *  otherVertex.logicalState = Vertex.LogicalState.Visited;
                     * }
                     * else
                     * {
                     *  edge.logicalState = Edge.LogicalState.Visited;
                     *  wait(edge);
                     *  otherVertex.logicalState = Vertex.LogicalState.Visited;
                     *  wait(edge);
                     * }*/
                }
            }
        }
Exemple #3
0
        public void Can_listen_for_extendedqueue_clear()
        {
            ExtendedQueue <int> queue = new ExtendedQueue <int>();

            queue.Cleared += Queue_Cleared;

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);

            Assert.True(queue.Count == 3);

            queue.Clear();

            Assert.True(queue.Count == 0);

            queue.Cleared -= Queue_Cleared;
        }