Пример #1
0
        public void should_throw_when_dequeue_from_empty()
        {
            IQueue <int> queue = new Services.Queue <int>();

            Action act = () => queue.Dequeue();

            act.Should().Throw <InvalidOperationException>();
        }
Пример #2
0
        public void should_return_false_when_trydequeue_from_empty()
        {
            IQueue <int> queue = new Services.Queue <int>();

            int result;

            queue.TryDequeue(out result).Should().BeFalse();
        }
Пример #3
0
        public void should_return_true_when_trydequeue_after_enqueue()
        {
            IQueue <int> queue = new Services.Queue <int>();

            queue.Enqueue(123);

            int  dequeued;
            bool result = queue.TryDequeue(out dequeued);

            result.Should().BeTrue();
            dequeued.Should().Be(123);
        }
Пример #4
0
        public void should_allow_many_items(int itemCount)
        {
            IQueue <double> queue = new Services.Queue <double>();

            Action act = () =>
            {
                for (int i = 0; i < itemCount; i++)
                {
                    queue.Enqueue(1.0 / i);
                }
            };

            act.Should().NotThrow();
        }
Пример #5
0
        public void should_still_contain_items_after_trydequeue()
        {
            IQueue <int> queue = new Services.Queue <int>();

            queue.Enqueue(321);

            int dequeueped;

            queue.TryDequeue(out dequeueped);

            Action act = () => queue.Dequeue();

            act.Should().NotThrow();
        }
Пример #6
0
            public static IEnumerable <TestCaseData> GetNonEmptyTestObjects()
            {
                var stack = new Services.Stack <string>();

                stack.Push("Bravo");
                stack.Push("Alpha");
                yield return(new TestCaseData(stack, "Alpha").SetName("{m}_stack"));

                var queue = new Services.Queue <string>();

                queue.Enqueue("Bravo");
                queue.Enqueue("Alpha");
                yield return(new TestCaseData(queue, "Bravo").SetName("{m}_queue"));
            }
Пример #7
0
        public void should_be_empty_after_dequeueing_all_items()
        {
            IQueue <string> queue = new Services.Queue <string>();

            var items = new[] { "Alpha", "Bravo", "Charlie", "Delta" };

            foreach (string s in items)
            {
                queue.Enqueue(s);
            }

            for (int i = 0; i < items.Length; i++)
            {
                queue.Dequeue();
            }

            queue.Invoking(q => q.Dequeue()).Should().Throw <InvalidOperationException>();
        }
Пример #8
0
        public void should_dequeue_items_correctly(int itemCount)
        {
            IQueue <int> queue = new Services.Queue <int>();

            int[] range    = Enumerable.Range(1, itemCount).ToArray();
            int[] expected = range;

            foreach (int i in range)
            {
                queue.Enqueue(i);
            }

            var actual = new int[range.Length];
            int index  = 0;

            foreach (int i in range)
            {
                actual[index++] = queue.Dequeue();
            }

            actual.Should().BeEquivalentTo(expected);
        }