コード例 #1
0
        public void Empty_Queue()
        {
            var threadSafeQueue = new ThreadSafeQueueSemaphore <int>();

            Assert.True(threadSafeQueue.IsEmpty());
            Assert.False(threadSafeQueue.IsFull());
        }
コード例 #2
0
        public void Add_Element_On_Queue()
        {
            var threadSafeQueue = new ThreadSafeQueueSemaphore <int>();

            threadSafeQueue.Enqueue(1);

            Assert.False(threadSafeQueue.IsEmpty());
            Assert.False(threadSafeQueue.IsFull());
        }
コード例 #3
0
        public void Enqueue_Then_Dequeue_An_Element()
        {
            int elementToAdd    = 1;
            var threadSafeQueue = new ThreadSafeQueueSemaphore <int>();

            threadSafeQueue.Enqueue(elementToAdd);
            var element = threadSafeQueue.Dequeue();

            Assert.True(threadSafeQueue.IsEmpty());
            Assert.False(threadSafeQueue.IsFull());
            Assert.Equal(elementToAdd, element);
        }
コード例 #4
0
        public void Add_Element_On_Queue_Until_Full_It()
        {
            var threadSafeQueue = new ThreadSafeQueueSemaphore <int>();

            threadSafeQueue.Enqueue(1);
            threadSafeQueue.Enqueue(2);
            threadSafeQueue.Enqueue(3);
            threadSafeQueue.Enqueue(4);
            threadSafeQueue.Enqueue(5);

            Assert.False(threadSafeQueue.IsEmpty());
            Assert.True(threadSafeQueue.IsFull());
        }
コード例 #5
0
        public void Dequeue_Only_After_Enqueue()
        {
            int element = 1;

            var multiThreadQueue = new ThreadSafeQueueSemaphore <int>();

            Task enqueueTask = Task.Run(() =>
            {
                Task.Delay(500).Wait();
                multiThreadQueue.Enqueue(element);
            });

            var elementDequeued = multiThreadQueue.Dequeue();

            Assert.Equal(element, elementDequeued);
            Assert.True(multiThreadQueue.IsEmpty());
            Assert.False(multiThreadQueue.IsFull());
        }