public void InsertAt()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(122));
            Assert.AreEqual(list.FindAtIndex(0).Value, 122);
        }
        public void FindLastNode()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(12));
            list.AddAt(0, new SinglyLinkedListNode <int>(13));
            list.AddAt(0, new SinglyLinkedListNode <int>(14));

            Assert.AreEqual(list.FindLastNode()?.Value, 1);
        }
        public void DeleteFirstNode()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(12));
            list.AddAt(0, new SinglyLinkedListNode <int>(13));
            list.AddAt(0, new SinglyLinkedListNode <int>(14));
            list.RemoveFirstNode();

            Assert.AreEqual(list.FindFirstNode()?.Value, 13);
        }
        public void Count()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.RemoveAt(0);
            list.AddAt(0, new SinglyLinkedListNode <int>(1));

            Assert.AreEqual(list.Count(), 3);
        }
        public void IsEmpty()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.RemoveAt(0);
            list.RemoveAt(0);
            list.RemoveAt(0);
            list.RemoveAt(0);

            Assert.AreEqual(list.IsEmpty(), true);
        }
        public void BatchTest()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.AddLast(new SinglyLinkedListNode <int>(i));
            }

            for (int i = 1; i < 10; i += 2)
            {
                list.AddAt(i, new SinglyLinkedListNode <int>(100 + i * i));
            }


            int count = list.Count();

            for (int i = 0; i < count; i++)
            {
                if (i > 0)
                {
                    Debug.Write("-");
                }

                Debug.Write(list.FindAtIndex(i).Value);
            }

            Assert.IsTrue(true);
        }
Exemple #7
0
        public void AddMiddleException2Test()
        {
            var list = new SinglyLinkedList <string>();

            Assert.Throws <ArgumentOutOfRangeException>(
                () =>
            {
                list.AddAt(-1, "Alpha");
            });
        }
Exemple #8
0
        public void AddAt()
        {
            SinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddEnd(0);
            list.AddEnd(1);
            list.AddEnd(2);
            list.AddAt(3, 3);
            int i = 0;

            foreach (var num in list)
            {
                Assert.True(num == i);
                i++;
            }
        }
Exemple #9
0
        public void AddMiddleTest()
        {
            var list = new SinglyLinkedList <string>();

            list.AddBack("Alpha");
            list.AddBack("Beta");
            list.AddBack("Delta");
            list.AddBack("Echo");
            list.AddAt(2, "Charlie");

            Assert.AreEqual(5, list.Count);
            Assert.AreEqual("Alpha", list.GetAt(0));
            Assert.AreEqual("Beta", list.GetAt(1));
            Assert.AreEqual("Charlie", list.GetAt(2));
            Assert.AreEqual("Delta", list.GetAt(3));
            Assert.AreEqual("Echo", list.GetAt(4));
        }
 public void AddAt_WhenIndexIsOutOfRange_ShouldThrowOutOfRangeException(int index, int value)
 {
     // Arrange & Act & Assert
     Assert.Throws <IndexOutOfRangeException>(() => _list.AddAt(index, value));
 }