Пример #1
0
        public void TestEnqueue1()
        {
            FirstInFirstOut<int> fifo = new FirstInFirstOut<int>();
            Assert.AreEqual(0, fifo.Queue.Count);

            fifo.Enqueue(1);
            fifo.Enqueue(3);
            Assert.AreEqual(2, fifo.Queue.Count);

            fifo.Enqueue(5);
            Assert.AreEqual(3, fifo.Queue.Count);

            fifo.Enqueue(7);
            fifo.Enqueue(9);
            fifo.Enqueue(11);

            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7, 9, 11 });
            ReadOnlyCollection<int> actual = fifo.Queue;
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
            Assert.AreEqual(expected[3], actual[3]);
            Assert.AreEqual(expected[4], actual[4]);
            Assert.AreEqual(expected[5], actual[5]);
        }
Пример #2
0
        public void FirstInFirstOutTest()
        {
            var firstInFirstOut = new FirstInFirstOut<string>(new BridgeListImpl<int, string>());

            firstInFirstOut.Push("string 1");
            firstInFirstOut.Push("string 2");
            firstInFirstOut.Push("string 3");

            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 1"));
            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 2"));
            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 3"));

            firstInFirstOut = new FirstInFirstOut<string>(new BridgeDictionaryImpl<int, string>());

            firstInFirstOut.Push("string 1");
            firstInFirstOut.Push("string 2");
            firstInFirstOut.Push("string 3");

            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 1"));
            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 2"));
            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 3"));

            firstInFirstOut = new FirstInFirstOut<string>(new BridgeNodeImpl<int, string>());

            firstInFirstOut.Push("string 1");
            firstInFirstOut.Push("string 2");
            firstInFirstOut.Push("string 3");

            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 1"));
            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 2"));
            Assert.That(firstInFirstOut.Pop(), Is.EqualTo("string 3"));
        }
Пример #3
0
        public void TestFirstInFirstOutConstructor2()
        {
            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7, 9, 11 });
            FirstInFirstOut<int> fifo = new FirstInFirstOut<int>(expected);

            ReadOnlyCollection<int> actual = fifo.Queue;
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
            Assert.AreEqual(expected[3], actual[3]);
            Assert.AreEqual(expected[4], actual[4]);
            Assert.AreEqual(expected[5], actual[5]);
        }
Пример #4
0
        public void TestEnqueue3()
        {
            FirstInFirstOut<int> fifo = new FirstInFirstOut<int>();

            fifo.Enqueue(1);
            fifo.Enqueue(3);
            fifo.Enqueue(5);
            fifo.Enqueue(7);
            fifo.Enqueue(9);
            fifo.Enqueue(11);

            fifo.Remove(3);
            fifo.Remove(5);
            fifo.Remove(9);

            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 7, 11 });
            ReadOnlyCollection<int> actual = fifo.Queue;
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
        }
Пример #5
0
        public void TestDequeue2()
        {
            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7, 9, 11 });
            FirstInFirstOut<int> fifo = new FirstInFirstOut<int>(expected);

            Assert.AreEqual(expected[0], fifo.Dequeue());
            Assert.AreEqual(expected[1], fifo.Dequeue());
            fifo.Enqueue(10);
            Assert.AreEqual(expected[2], fifo.Dequeue());
            fifo.Enqueue(6);
            Assert.AreEqual(expected[3], fifo.Dequeue());

            expected = new ReadOnlyCollection<int>(new int[] { 9, 11, 10, 6 });
            ReadOnlyCollection<int> actual = fifo.Queue;
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
            Assert.AreEqual(expected[3], actual[3]);
        }
Пример #6
0
        public void TestDequeue1()
        {
            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7, 9, 11 });
            FirstInFirstOut<int> fifo = new FirstInFirstOut<int>(expected);

            Assert.AreEqual(expected[0], fifo.Dequeue());
            Assert.AreEqual(expected.Count - 1, fifo.Queue.Count);

            Assert.AreEqual(expected[1], fifo.Dequeue());
            Assert.AreEqual(expected[2], fifo.Dequeue());

            Assert.AreEqual(expected[3], fifo.Peek());
            Assert.AreEqual(expected[3], fifo.Dequeue());
            Assert.AreEqual(expected[4], fifo.Peek());
        }
Пример #7
0
        public void TestFirstInFirstOutConstructor1()
        {
            FirstInFirstOut<int> fifo = new FirstInFirstOut<int>(3, 4, null);

            Assert.AreEqual(0, fifo.Queue.Count);
        }