Example #1
0
        public void AddBefore(int oldItem, int item)
        {
            for (int i = 1; i <= 5; i++)
            {
                singlyLinkedList.AddLast(i);
            }

            singlyLinkedList.AddBefore(oldItem, item);

            Assert.AreEqual(singlyLinkedList.Count(), 6, "invalid count");
            Assert.IsTrue(singlyLinkedList.Contains(item), "Item doesn't exists.");
        }
Example #2
0
 /// Summary
 /// Time: 12 min 35 sec
 /// Pattern: Round Trip
 /// Combines two tests AddBeforeTailTest and AddBeforeMiddleNodeTest into one single PUT
 public void AddBeforeTailTest([PexAssumeUnderTest] SinglyLinkedList <int> sll, int positionToAdd, int elemToAdd)
 {
     PexAssume.IsTrue(sll.Count > 3);
     PexAssume.IsTrue(positionToAdd >= 0 && positionToAdd < sll.Count);
     sll.AddBefore(sll.Head.Next.Next.Next, elemToAdd);
     PexAssert.AreEqual(elemToAdd, sll.Head.Next.Next.Next.Value);
 }
Example #3
0
        public void AddBeforeTheMiddleNodeAndCheckForOrder()
        {
            var list = new SinglyLinkedList <int>();

            int itemCount  = 1000;
            var middleNode = new SinglyLinkedListNode <int>(0);

            for (int i = 0; i < itemCount; i++)
            {
                if (i == itemCount / 2)
                {
                    middleNode = list.AddLast(i);
                }
                else
                {
                    list.AddLast(i);
                }
            }

            for (int i = 0; i < itemCount; i++)
            {
                list.AddBefore(middleNode, i);
            }

            int j = 0;
            int k = 0;
            int numberOfElementsInList = 0;

            foreach (var item in list)
            {
                if (j < itemCount / 2)
                {
                    if (j != item)
                    {
                        Assert.Fail("1");
                    }
                }
                else if (j >= itemCount / 2 && j < itemCount + itemCount / 2)
                {
                    if (k++ != item)
                    {
                        Assert.Fail("2");
                    }
                }
                else
                {
                    if (j - itemCount != item)
                    {
                        Assert.Fail("3");
                    }
                }

                j++;
                numberOfElementsInList++;
            }

            Assert.IsTrue(list.Count == 2 * itemCount &&
                          numberOfElementsInList == list.Count);
        }
        public void InsertBefore()
        {
            ISinglyLinkedList <int> list = new SinglyLinkedList <int>();

            list.AddAt(0, new SinglyLinkedListNode <int>(1));
            list.AddBefore(1, new SinglyLinkedListNode <int>(122));
            Assert.AreEqual(list.FindAtIndex(0).Value, 122);
        }
Example #5
0
        public void AddBeforeTailTest()
        {
            SinglyLinkedList <int> sll = new SinglyLinkedList <int> {
                10, 20, 30, 40
            };

            sll.AddBefore(sll.Head.Next.Next.Next, 35);

            Assert.AreEqual(35, sll.Head.Next.Next.Next.Value);
        }
Example #6
0
        /// Summary
        /// Time: 2 min 20 sec
        /// Pattern: AAA, State Relation, Round Trip
        public void AddBeforeHeadTest([PexAssumeUnderTest] SinglyLinkedList <string> sll, string newElement)
        {
            PexAssume.IsTrue(sll.Count > 0);
            string prevValue = sll.Head.Value;
            int    prevCount = sll.Count;

            sll.AddBefore(sll.Head, newElement);
            PexAssert.AreEqual(newElement, sll.Head.Value);
            PexAssert.AreEqual(prevValue, sll.Head.Next.Value);
            PexAssert.AreEqual(prevCount + 1, sll.Count);
        }
        public void TestAddBefore()
        {
            var expected = new int[3] { 0, 1, 2 };

            var list = new SinglyLinkedList<int>();
            list.AddLast(0);
            var node = list.AddLast(2);

            list.AddBefore(node, 1);

            Verify(expected, list);
        }
Example #8
0
        public void AddBeforeMiddleNodeTest()
        {
            SinglyLinkedList <int> sll = new SinglyLinkedList <int> {
                10, 20, 30
            };

            sll.AddBefore(sll.Head.Next, 15);

            Assert.AreEqual(15, sll.Head.Next.Value);
            Assert.AreEqual(20, sll.Head.Next.Next.Value);
            Assert.AreEqual(4, sll.Count);
        }
Example #9
0
        public void AddBeforeHeadTest()
        {
            SinglyLinkedList <int> sll = new SinglyLinkedList <int> {
                10, 20, 30
            };

            sll.AddBefore(sll.Head, 5);

            Assert.AreEqual(5, sll.Head.Value);
            Assert.AreEqual(10, sll.Head.Next.Value);
            Assert.AreEqual(4, sll.Count);
        }
Example #10
0
        public void AddNullItem()
        {
            var list = new SinglyLinkedList <string>();

            list.AddFirst(null);
            list.AddLast(null);
            list.AddAfter(null, null);
            list.AddBefore(null, null);
            Assert.AreEqual(list.Count(), 4, "invalid count");
            list.Remove(null);
            list.RemoveFirst();
            list.RemoveLast();
            Assert.AreEqual(list.Count(), 1, "invalid count");
        }
Example #11
0
 public void AddBeforeEmptyListTest(int newElement)
 {
     SinglyLinkedList<int> sll = new SinglyLinkedList<int>();
     sll.AddBefore(sll.Head, newElement);
 }
        public void TestAddBeforeFirst()
        {
            var expected = new int[3] { 0, 1, 2 };

            var list = new SinglyLinkedList<int>();
            list.AddLast(1);
            list.AddLast(2);

            var node = list.AddBefore(list.First, 0);

            Verify(expected, list);
            Assert.AreSame(list.First, node);
        }
Example #13
0
        public void AddBeforeEmptyListTest()
        {
            SinglyLinkedList <int> sll = new SinglyLinkedList <int>();

            sll.AddBefore(sll.Head, 10);
        }
Example #14
0
        /// Summary
        /// Time: 0 min 45 sec
        /// Pattern: Allowed Exception
        public void AddBeforeEmptyListTest(int newElement)
        {
            SinglyLinkedList <int> sll = new SinglyLinkedList <int>();

            sll.AddBefore(sll.Head, newElement);
        }
Example #15
0
        public void AddBeforeHeadTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30};

            sll.AddBefore(sll.Head, 5);

            Assert.AreEqual(5, sll.Head.Value);
            Assert.AreEqual(10, sll.Head.Next.Value);
            Assert.AreEqual(4, sll.Count);
        }
Example #16
0
        public void AddBeforeEmptyListTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int>();

            sll.AddBefore(sll.Head, 10);
        }
Example #17
0
        public void AddBeforeTailTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30, 40};

            sll.AddBefore(sll.Head.Next.Next.Next, 35);

            Assert.AreEqual(35, sll.Head.Next.Next.Next.Value);
        }
Example #18
0
        public void AddBeforeMiddleNodeTest()
        {
            SinglyLinkedList<int> sll = new SinglyLinkedList<int> {10, 20, 30};

            sll.AddBefore(sll.Head.Next, 15);

            Assert.AreEqual(15, sll.Head.Next.Value);
            Assert.AreEqual(20, sll.Head.Next.Next.Value);
            Assert.AreEqual(4, sll.Count);
        }