Пример #1
0
        public void GetAllDataTest()
        {
            // arrange
            UniLinkedList <int> llist = new UniLinkedList <int>();

            llist.Add(1);
            llist.Add(2);
            llist.Add(3);
            int[] check  = new int[] { 1, 2, 3 };
            bool  result = true;

            // act
            var list = llist.GetAllData().ToArray();

            for (int i = 0, n = llist.Count - 1; i < n; i++)
            {
                if (list[i] != check[i])
                {
                    result = false;
                    break;
                }
            }

            //asserts
            Assert.IsTrue(result);
        }
Пример #2
0
        public void Add_Contains(int x)
        {
            UniLinkedList <int> llist = new UniLinkedList <int>();

            llist.Add(x);
            bool result = llist.Contains(x);


            Assert.IsTrue(result);
        }
Пример #3
0
        public void Remove()
        {
            // arrange
            UniLinkedList <int> llist = new UniLinkedList <int>();

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

            // act
            bool remove_result   = llist.Remove(2);
            bool contains_result = llist.Contains(2);

            //assert
            Assert.IsTrue(remove_result);
            Assert.IsFalse(contains_result);
        }
Пример #4
0
        public void AppendAfter()
        {
            // arrange
            UniLinkedList <int> llist = new UniLinkedList <int>();

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

            bool app_result   = llist.AppendAfter(8, 3);
            bool app_tail_res = llist.Last.Data == 8;

            llist.AppendAfter(12, 1);
            bool app_middle_res = llist.First.Next.Data == 12;

            // assert
            Assert.IsTrue(app_result);
            Assert.IsTrue(app_tail_res);
            Assert.IsTrue(app_middle_res);
        }
Пример #5
0
        public void AppendFirst()
        {
            // arrange
            UniLinkedList <int> llist = new UniLinkedList <int>();

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

            // act
            bool init_head_res  = llist.First.Data == 1;
            bool init_count_res = llist.Count == 3;

            llist.AppendFirst(5);
            bool count_res = llist.Count == 4;
            bool head_res  = llist.First.Data == 5;

            // asserts
            Assert.IsTrue(init_head_res);
            Assert.IsTrue(init_count_res);
            Assert.IsTrue(count_res);
            Assert.IsTrue(head_res);
        }