コード例 #1
0
        public void LastInFirstOutTest()
        {
            var lastInFirstOut = new LastInFirstOut <string>(new BridgeListImpl <int, string>());

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

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

            lastInFirstOut = new LastInFirstOut <string>(new BridgeDictionaryImpl <int, string>());

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

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

            lastInFirstOut = new LastInFirstOut <string>(new BridgeNodeImpl <int, string>());

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

            Assert.That(lastInFirstOut.Pop(), Is.EqualTo("string 3"));
            Assert.That(lastInFirstOut.Pop(), Is.EqualTo("string 2"));
            Assert.That(lastInFirstOut.Pop(), Is.EqualTo("string 1"));
        }
コード例 #2
0
ファイル: BridgeTests.cs プロジェクト: agabani/DesignPatterns
        public void LastInFirstOutTest()
        {
            var lastInFirstOut = new LastInFirstOut<string>(new BridgeListImpl<int, string>());

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

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

            lastInFirstOut = new LastInFirstOut<string>(new BridgeDictionaryImpl<int, string>());

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

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

            lastInFirstOut = new LastInFirstOut<string>(new BridgeNodeImpl<int, string>());

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

            Assert.That(lastInFirstOut.Pop(), Is.EqualTo("string 3"));
            Assert.That(lastInFirstOut.Pop(), Is.EqualTo("string 2"));
            Assert.That(lastInFirstOut.Pop(), Is.EqualTo("string 1"));
        }
コード例 #3
0
        public void TestPush5()
        {
            LastInFirstOut <int> lifo = new LastInFirstOut <int>();

            lifo.Push(1);
            lifo.Push(3);
            lifo.Push(5);
            lifo.Push(7);
            lifo.Push(9);
            lifo.Push(11);

            lifo.Remove(3);
            lifo.Push(10);
            lifo.Remove(5);
            lifo.Push(6);
            lifo.Remove(9);

            ReadOnlyCollection <int> expected = new ReadOnlyCollection <int>(new int[] { 1, 7, 11, 6, 10 });
            ReadOnlyCollection <int> actual   = lifo.Stack;

            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.AreNotEqual(expected[3], actual[3]);
            Assert.AreNotEqual(expected[4], actual[4]);

            Assert.AreEqual(expected[4], actual[3]);
            Assert.AreEqual(expected[3], actual[4]);
        }
コード例 #4
0
        public void TestPop2()
        {
            ReadOnlyCollection <int> expected = new ReadOnlyCollection <int>(new int[] { 1, 3, 5, 7, 9, 11 });
            LastInFirstOut <int>     lifo     = new LastInFirstOut <int>(expected);

            Assert.AreEqual(expected[5], lifo.Pop());
            Assert.AreEqual(expected[4], lifo.Pop());
            lifo.Push(10);
            Assert.AreEqual(10, lifo.Pop());
            lifo.Push(6);
            Assert.AreEqual(6, lifo.Pop());

            expected = new ReadOnlyCollection <int>(new int[] { 1, 3, 5, 7 });
            ReadOnlyCollection <int> actual = lifo.Stack;

            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]);
        }
コード例 #5
0
        public void TestPush1()
        {
            LastInFirstOut<int> lifo = new LastInFirstOut<int>();
            Assert.AreEqual(0, lifo.Stack.Count);

            lifo.Push(1);
            lifo.Push(3);
            Assert.AreEqual(2, lifo.Stack.Count);

            lifo.Push(5);
            Assert.AreEqual(3, lifo.Stack.Count);

            lifo.Push(7);
            lifo.Push(9);
            lifo.Push(11);

            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7, 9, 11 });
            ReadOnlyCollection<int> actual = lifo.Stack;
            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]);
        }
コード例 #6
0
        public void TestPush1()
        {
            LastInFirstOut <int> lifo = new LastInFirstOut <int>();

            Assert.AreEqual(0, lifo.Stack.Count);

            lifo.Push(1);
            lifo.Push(3);
            Assert.AreEqual(2, lifo.Stack.Count);

            lifo.Push(5);
            Assert.AreEqual(3, lifo.Stack.Count);

            lifo.Push(7);
            lifo.Push(9);
            lifo.Push(11);

            ReadOnlyCollection <int> expected = new ReadOnlyCollection <int>(new int[] { 1, 3, 5, 7, 9, 11 });
            ReadOnlyCollection <int> actual   = lifo.Stack;

            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]);
        }
コード例 #7
0
        public void TestPush3()
        {
            LastInFirstOut<int> lifo = new LastInFirstOut<int>();

            lifo.Push(1);
            lifo.Push(3);
            lifo.Push(5);
            lifo.Push(7);
            lifo.Push(9);
            lifo.Push(11);

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

            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 7, 11 });
            ReadOnlyCollection<int> actual = lifo.Stack;
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1], actual[1]);
            Assert.AreEqual(expected[2], actual[2]);
        }
コード例 #8
0
        public void TestPop2()
        {
            ReadOnlyCollection<int> expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7, 9, 11 });
            LastInFirstOut<int> lifo = new LastInFirstOut<int>(expected);

            Assert.AreEqual(expected[5], lifo.Pop());
            Assert.AreEqual(expected[4], lifo.Pop());
            lifo.Push(10);
            Assert.AreEqual(10, lifo.Pop());
            lifo.Push(6);
            Assert.AreEqual(6, lifo.Pop());

            expected = new ReadOnlyCollection<int>(new int[] { 1, 3, 5, 7 });
            ReadOnlyCollection<int> actual = lifo.Stack;
            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]);
        }