コード例 #1
0
        public List <string> CheckNextLinks(DoublyLinkedList.DoublyLinkedList testList)
        {
            List <string> actual = new List <string>();

            foreach (string item in testList)
            {
                actual.Add(item);
            }

            return(actual);
        }
コード例 #2
0
        public void AddAtWrongIndex_IndexOutOfRangeException()
        {
            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("4");
            testList.AddToTail("5");

            Assert.ThrowsException <IndexOutOfRangeException>(
                () => testList.AddAtIndex("3", 7));
        }
コード例 #3
0
        public void GetTheOnlyFirstElement_TheElementIsGotten()
        {
            string expected = "1";

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");

            string actual = testList.FirstElement();

            Xunit.Assert.Equal(expected, actual);
        }
コード例 #4
0
        public void DeleteAtIndex_IndexOutOfRangeException(int index)
        {
            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("3");
            testList.AddToTail("4");
            testList.AddToTail("5");

            Xunit.Assert.Throws <IndexOutOfRangeException>(
                () => testList.DeleteAtIndex(index));
        }
コード例 #5
0
        public List <string> CheckPreviousLinks(DoublyLinkedList.DoublyLinkedList testList)
        {
            List <string> actual = new List <string>();
            Node          item   = testList.Tail;

            while (item != null)
            {
                actual.Add(item.Value);
                item = item.Previous;
            }

            return(actual);
        }
コード例 #6
0
        public void DeleteTheOnlyExistedElement_TheListIsEmpty()
        {
            List <string> expected = new List <string> {
            };

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");

            testList.DeleteAtIndex(1);

            List <string> actual = CheckNextLinks(testList);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #7
0
        public void GetTheLastElement_TheRightElementIsGotten()
        {
            string expected = "5";

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("3");
            testList.AddToTail("4");
            testList.AddToTail("5");

            string actual = testList.LastElement();

            Xunit.Assert.Equal(expected, actual);
        }
コード例 #8
0
        public void AddElementsToHead_ElementsAreAddedInRightOrder_FromTail()
        {
            List <string> expected = new List <string> {
                "1", "2", "3"
            };

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();

            testList.AddToHead("1");
            testList.AddToHead("2");
            testList.AddToHead("3");

            List <string> actual = CheckPreviousLinks(testList);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #9
0
        public void AddOneElementToTheMiddle_ElementsAreInRightOrder_FromTail()
        {
            List <string> expected = new List <string> {
                "5", "4", "3", "2", "1"
            };

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("4");
            testList.AddToTail("5");

            testList.AddAtIndex("3", 3);

            List <string> actual = CheckPreviousLinks(testList);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #10
0
        public void DeleteOneMiddleElement_ElementIsDeletedCorrectly_FromTail()
        {
            List <string> expected = new List <string> {
                "5", "4", "2", "1"
            };

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("3");
            testList.AddToTail("4");
            testList.AddToTail("5");

            testList.DeleteAtIndex(3);

            List <string> actual = CheckPreviousLinks(testList);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #11
0
        public void DeleteOneMiddleAndOneLastElements_ElementsAreDeletedCorrectly_FromHead()
        {
            List <string> expected = new List <string> {
                "1", "2", "4"
            };

            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("3");
            testList.AddToTail("4");
            testList.AddToTail("5");

            testList.DeleteAtIndex(3);
            testList.DeleteAtIndex(4);

            List <string> actual = CheckNextLinks(testList);

            CollectionAssert.AreEqual(expected, actual);
        }
コード例 #12
0
        public void DeleteAtIndex_TheRightElementIsDeleted(int value1)
        {
            DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
            testList.AddToTail("1");
            testList.AddToTail("2");
            testList.AddToTail("3");
            testList.AddToTail("4");
            testList.AddToTail("5");
            List <string> expected = new List <string> {
                "1", "2", "3", "4", "5"
            };

            testList.DeleteAtIndex(value1);
            expected.RemoveAt(value1 - 1);

            List <string> actualNextLinks     = CheckNextLinks(testList);
            List <string> actualPreviousLinks = CheckPreviousLinks(testList);

            CollectionAssert.AreEqual(actualNextLinks, expected);
            expected.Reverse();
            CollectionAssert.AreEqual(actualPreviousLinks, expected);
        }
コード例 #13
0
 public void GetTheLastElementInEmptyList_OutOfRangeException()
 {
     DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
     Xunit.Assert.Throws <IndexOutOfRangeException>(
         () => testList.LastElement());
 }
コード例 #14
0
 public void GetTheFirstElementInEmptyList_OutOfRangeException()
 {
     DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
     Assert.ThrowsException <IndexOutOfRangeException>(
         () => testList.FirstElement());
 }
コード例 #15
0
 public void DeleteInEmptyList_IndexOutOfRangeExeption()
 {
     DoublyLinkedList.DoublyLinkedList testList = new DoublyLinkedList.DoublyLinkedList();
     Assert.ThrowsException <IndexOutOfRangeException>(
         () => testList.DeleteAtIndex(1));
 }