Exemplo n.º 1
0
        public static void TestFindOrderedListIntDesc()
        {
            var list = new OrderedList <int>(false);

            Assert.AreEqual(0, list.Count(), "TestFindOrderedListIntAsc orderedList size must be 0, but not");
            list.Add(4);
            list.Add(3);
            list.Add(2);
            list.Add(1);
            Assert.AreEqual(4, list.Count(), "TestFindOrderedListIntAsc orderedList size must be 4, but not");

            var found = list.Find(3);

            Assert.AreEqual(3, found.value);
            Assert.AreEqual(4, found.prev.value);
            Assert.AreEqual(2, found.next.value);

            found = list.Find(4);
            Assert.AreEqual(4, found.value);
            Assert.AreEqual(3, found.next.value);
            Assert.IsNull(found.prev);

            found = list.Find(1);
            Assert.AreEqual(1, found.value);
            Assert.AreEqual(2, found.prev.value);
            Assert.IsNull(found.next);
        }
Exemplo n.º 2
0
        public void DeleteTest()
        {
            OrderedList <int> orderedListAsc = CreateOrderedList(
                true,
                0, 9, 8, 1, 2, 3, 7, 6, 5, 4);

            Assert.Equal(10, orderedListAsc.Count());

            orderedListAsc.Delete(10);
            Assert.Equal(10, orderedListAsc.Count());

            orderedListAsc.Delete(9);
            Assert.Equal(9, orderedListAsc.Count());
        }
        public void TestDeleteStringAsc_3()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add("Fat32");
            ord.Add("Fat32");
            ord.Add("Fat");
            ord.Add("Fat");

            Assert.AreEqual(4, ord.Count());

            ord.Delete("Fat");

            Assert.AreEqual(3, ord.Count());
        }
Exemplo n.º 4
0
        public void Find_in_Empty_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            Assert.IsNull(tList.Find(19));
            Assert.IsTrue(tList.Count() == 0);
        }
Exemplo n.º 5
0
        public void TestCreateSize()
        {
            var stack = new OrderedList <int>(true);

            Assert.True(stack.Count() == 0);
            Assert.True(stack.head == null);
            Assert.True(stack.tail == null);
        }
Exemplo n.º 6
0
        public void Delete_from_Empty_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Delete(42);

            Assert.IsTrue(tList.Count() == 0);
        }
Exemplo n.º 7
0
        public void CountTest()
        {
            OrderedList <int> orderedListAsc = CreateOrderedList(
                true,
                0, 9, 8, 1, 2, 3, 7, 6, 5, 4);

            Assert.Equal(10, orderedListAsc.Count());
        }
Exemplo n.º 8
0
        public static void TestAddOrderedListIntAsc()
        {
            var list = new OrderedList <int>(true);

            Assert.AreEqual(0, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 0, but not");
            list.Add(1);
            Assert.AreEqual(1, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 1, but not");
            list.Add(3);
            Assert.AreEqual(2, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 2, but not");
            list.Add(4);
            Assert.AreEqual(3, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 3, but not");
            list.Add(2);
            Assert.AreEqual(4, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 4, but not");
            list.Add(0);
            Assert.AreEqual(5, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 5, but not");
            list.Add(-1);
            Assert.AreEqual(6, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 6, but not");

            var counter = -1;
            var node    = list.head;

            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestAddOrderedListIntAsc failed. List sequence is not correct");
                counter += 1;
                node     = node.next;
            }
            Assert.AreEqual(5, counter, "TestAddOrderedListIntAsc counter must be 6, but not");
        }
        public void Test_Count_WhenNotFound()
        {
            var list = new OrderedList <int>(true);

            list.Add(1);
            list.Add(2);
            list.Add(3);
            var result = list.Count();

            Assert.AreEqual(3, result);
        }
Exemplo n.º 10
0
        public void TestClearAsc()
        {
            var stack = new OrderedList <int>(true);

            stack.Add(1);
            stack.Add(3);
            stack.Add(5);
            stack.Add(0);
            stack.Add(2);
            stack.Add(7);
            stack.Add(4);
            stack.Add(4);

            stack.Clear(true);
            Assert.True(stack.Count() == 0);
            stack.Add(1);
            stack.Add(2);

            Assert.True(stack.ToString().Equals("1 2"));
            Assert.True(stack.Count() == 2);
        }
Exemplo n.º 11
0
        public void Add_Empty_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(19);

            int expectedSize = 1;
            int actualSize   = tList.Count();

            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.value == 19);
            Assert.IsTrue(tList.tail.value == 19);
        }
Exemplo n.º 12
0
        public void TestCountAsc_1()
        {
            OrderedList <int> ord = new OrderedList <int>(true);

            ord.Add(3);
            ord.Add(2);
            ord.Add(1);

            Assert.AreEqual(3, ord.Count());

            ord.Delete(1);

            Assert.AreEqual(2, ord.Count());

            ord.Delete(2);
            ord.Delete(3);

            Assert.AreEqual(0, ord.Count());

            ord.Delete(1);

            Assert.AreEqual(0, ord.Count());
        }
Exemplo n.º 13
0
        public static void TestRemoveOrderedListIntDesc()
        {
            var list = new OrderedList <int>(false);

            Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 0, but not");
            list.Add(4);
            list.Add(3);
            list.Add(2);
            list.Add(1);
            Assert.AreEqual(4, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 4, but not");

            var counter = 4;
            var node    = list.head;

            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct");
                counter -= 1;
                node     = node.next;
            }

            list.Delete(3);
            Assert.AreEqual(3, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 3, but not");
            list.Delete(2);
            Assert.AreEqual(2, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 2, but not");
            counter = 4;
            node    = list.head;
            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct");
                counter -= 3;
                node     = node.next;
            }

            list.Delete(1);
            Assert.AreEqual(1, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 1, but not");
            counter = 4;
            node    = list.head;
            while (node != null)
            {
                Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct");
                counter -= 1;
                node     = node.next;
            }

            list.Delete(4);
            Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 0, but not");

            list.Delete(4);
            Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntAsc orderedList size must be 0, but not");
        }
Exemplo n.º 14
0
        private void CheckCorrectOrder(OrderedList <int> orderedList, bool ascending)
        {
            switch (orderedList.Count())
            {
            case 0:
                Assert.Null(orderedList.head);
                Assert.Null(orderedList.tail);
                return;

            case 1:
                Assert.Null(orderedList.head.prev);
                Assert.NotNull(orderedList.head);
                Assert.Null(orderedList.head.next);
                Assert.Null(orderedList.tail.prev);
                Assert.NotNull(orderedList.tail);
                Assert.Null(orderedList.tail.next);
                return;
            }

            Node <int> node = orderedList.head;

            if (ascending)
            {
                while (node != null)
                {
                    if (node.next != null)
                    {
                        Assert.True(node.next.value >= node.value);
                    }

                    node = node.next;
                }
            }
            else
            {
                while (node != null)
                {
                    if (node.next != null)
                    {
                        Assert.True(node.next.value <= node.value);
                    }

                    node = node.next;
                }
            }
        }
Exemplo n.º 15
0
        public void Delete_if_Elem_Is_Not_Exists_in_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(12);
            tList.Add(48);
            tList.Add(35);
            tList.Add(-101);

            tList.Delete(42);
            Node <int> actualFoundValue = tList.Find(42);
            int        expectedSize     = 4;
            int        actualSize       = tList.Count();

            Assert.IsNull(actualFoundValue);
            Assert.AreEqual(expectedSize, actualSize);
        }
Exemplo n.º 16
0
        public void TestAddStringAsc_6()
        {
            OrderedList <string> ord = new OrderedList <string>(true);

            ord.Add("");
            ord.Add("");
            Assert.AreEqual("", ord.head.value);
            Assert.AreEqual("", ord.head.next.value);
            Assert.AreEqual("", ord.tail.value);
            Assert.AreEqual("", ord.tail.prev.value);

            ord.Add(" ");
            Assert.AreEqual(" ", ord.head.next.next.value);
            Assert.AreEqual("", ord.tail.prev.value);

            Assert.AreEqual(3, ord.Count());
        }
Exemplo n.º 17
0
        public void Add_if_Less_than_the_Head_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(2);
            tList.Add(3);
            tList.Add(9);

            tList.Add(0);

            int expectedSize = 4;
            int actualSize   = tList.Count();

            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.value == 0);
            Assert.IsTrue(tList.head.next.value == 2);
            Assert.IsTrue(tList.tail.value == 9);
        }
Exemplo n.º 18
0
        public void Add_if_More_than_the_Tail_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(1);
            tList.Add(2);
            tList.Add(3);

            tList.Add(9);

            int expectedSize = 4;
            int actualSize   = tList.Count();

            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.value == 1);
            Assert.IsTrue(tList.tail.value == 9);
            Assert.IsTrue(tList.tail.prev.value == 3);
        }
Exemplo n.º 19
0
        public void Add_in_between_nodes_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(9);
            tList.Add(7);

            tList.Add(8);

            int expectedSize = 3;
            int actualSize   = tList.Count();

            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.value == 9);
            Assert.IsTrue(tList.head.next.value == 8);
            Assert.IsTrue(tList.tail.value == 7);
            Assert.IsTrue(tList.tail.prev.value == 8);
        }
Exemplo n.º 20
0
        public void Add_in_between_nodes_Asc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(true);

            tList.Add(1);
            tList.Add(3);

            tList.Add(2);

            int expectedSize = 3;
            int actualSize   = tList.Count();

            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.value == 1);
            Assert.IsTrue(tList.head.next.value == 2);
            Assert.IsTrue(tList.tail.value == 3);
            Assert.IsTrue(tList.tail.prev.value == 2);
        }
Exemplo n.º 21
0
        public void Add_if_More_than_the_Head_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(5);
            tList.Add(6);
            tList.Add(8);

            tList.Add(19);

            int expectedSize = 4;
            int actualSize   = tList.Count();

            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.value == 19);
            Assert.IsTrue(tList.tail.value == 5);
            Assert.IsTrue(tList.head.next.value == 8);
        }
Exemplo n.º 22
0
        public void Delete_if_Elem_Is_Not_Exists_in_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(122);
            tList.Add(7);
            tList.Add(21);
            tList.Add(7);
            tList.Add(0);

            tList.Delete(42);
            Node <int> actualFoundValue = tList.Find(42);

            int expectedSize = 5;
            int actualSize   = tList.Count();

            Assert.IsNull(actualFoundValue);
            Assert.AreEqual(expectedSize, actualSize);
        }
Exemplo n.º 23
0
        public void Add_if_Exists_Duplicate_Element_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(10);
            tList.Add(9);
            tList.Add(1);
            tList.Add(5);
            tList.Add(1);
            tList.Add(6);
            tList.Add(2);
            tList.Add(8);
            tList.Add(7);
            tList.Add(4);

            Assert.IsTrue(tList.Count() == 10);
            Assert.IsTrue(tList.tail.value == 1);
            Assert.IsTrue(tList.tail.prev.value == 1);
            Assert.IsTrue(tList.tail.prev.next.value == 1);
            Assert.IsTrue(tList.tail.prev.prev.value == 2);
        }
Exemplo n.º 24
0
        public void Delete_if_Elem_Is_Exists_in_Desc_List()
        {
            OrderedList <int> tList = new OrderedList <int>(false);

            tList.Add(12);
            tList.Add(48);
            tList.Add(35);
            tList.Add(-101);

            tList.Delete(12);

            Node <int> actualFoundValue = tList.Find(12);

            int expectedSize = 3;
            int actualSize   = tList.Count();

            Assert.IsNull(actualFoundValue);
            Assert.AreEqual(expectedSize, actualSize);
            Assert.IsTrue(tList.head.next.next.value == -101);
            Assert.IsTrue(tList.tail.prev.value == 35);
        }
Exemplo n.º 25
0
        public void AddTest()
        {
            OrderedList <int> orderedListAsc = CreateOrderedList(
                true,
                0, 9, 8, 1, 2, 3, 7, 6, 5, 4);

            orderedListAsc.Add(101);
            orderedListAsc.Add(50);
            orderedListAsc.Add(150);
            CheckCorrectOrder(orderedListAsc, true);
            Assert.Equal(13, orderedListAsc.Count());

            OrderedList <int> orderedListDesc = CreateOrderedList(
                false,
                9, 8, 1, 2, 3, 7, 6, 5, 4);

            orderedListDesc.Add(101);
            orderedListDesc.Add(50);
            orderedListDesc.Add(150);
            orderedListDesc.Add(0);

            CheckCorrectOrder(orderedListDesc, false);
            Assert.Equal(13, orderedListDesc.Count());
        }
Exemplo n.º 26
0
        public static void TestAddOrderedListStringAsc()
        {
            var list   = new OrderedList <string>(true);
            var etalon = new Dictionary <int, string>();

            Assert.AreEqual(0, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 0, but not");
            list.Add("c");
            etalon.Add(1, "c");
            Assert.AreEqual(1, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 1, but not");
            list.Add("e");
            etalon.Add(3, "e");
            Assert.AreEqual(2, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 2, but not");
            list.Add("f");
            etalon.Add(4, "f");
            Assert.AreEqual(3, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 3, but not");
            list.Add("d");
            etalon.Add(2, "d");
            Assert.AreEqual(4, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 4, but not");
            list.Add("b");
            etalon.Add(0, "b");
            Assert.AreEqual(5, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 5, but not");
            list.Add("a");
            etalon.Add(-1, "a");
            Assert.AreEqual(6, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 6, but not");

            var counter = -1;
            var node    = list.head;

            while (node != null)
            {
                Assert.AreEqual(etalon[counter], node.value, "Test TestAddOrderedListStringAsc failed. List sequence is not correct");
                counter += 1;
                node     = node.next;
            }
            Assert.AreEqual(5, counter, "TestAddOrderedListStringAsc counter must be 6, but not");
        }