示例#1
0
        public void DoubleLinkedListGetItemsList()
        {
            var    conditionSuccess = false;
            string firstValueToAdd  = "1";
            string secondValueToAdd = "2";
            string thirdValueToAdd  = "3";
            var    singleLinkedList = new SingleLinkedList <string>();

            singleLinkedList.Add(firstValueToAdd);
            singleLinkedList.Add(secondValueToAdd);
            singleLinkedList.Add(thirdValueToAdd);

            var allValues = singleLinkedList.GetListValues();

            if (allValues == null)
            {
                Assert.Fail($"{nameof(DoubleLinkedListGetItemsList)} method failed. Node is equals to null");
            }

            if (allValues.Count == 3 &&
                allValues.Contains(firstValueToAdd) &&
                allValues.Contains(secondValueToAdd) &&
                allValues.Contains(thirdValueToAdd))
            {
                conditionSuccess = true;
            }

            Assert.IsTrue(conditionSuccess, "Get list items test failed");
        }
示例#2
0
        public void RemoveValues()
        {
            var    keyExist         = false;
            string valueToAdd       = "1";
            string valueToRemove    = "2";
            var    singleLinkedList = new SingleLinkedList <string>();

            singleLinkedList.Add(valueToAdd);
            singleLinkedList.Add(valueToRemove);

            var listValues = singleLinkedList.GetListValues();

            if (listValues != null && listValues.Count > 0)
            {
                keyExist = listValues.Contains(valueToRemove);
            }

            Assert.IsTrue(keyExist, "Value adding to list failed");

            singleLinkedList.Remove(valueToRemove);

            listValues = singleLinkedList.GetListValues();
            if (listValues != null && listValues.Count > 0)
            {
                keyExist = !listValues.Contains(valueToRemove);
            }
            else
            {
                Assert.Fail("Remove values test fails");
            }

            Assert.IsTrue(keyExist, "Value was not removed from list successfully");
        }
示例#3
0
        static void MainLinkedList()
        {
            var singleLinkedList = new SingleLinkedList<int>();
            singleLinkedList.Add(2);
            singleLinkedList.Add(4);
            singleLinkedList.Add(6);
            singleLinkedList.Add(8);
            singleLinkedList.Add(1);
            singleLinkedList.Add(3);
            singleLinkedList.Add(5);
            singleLinkedList.Add(7);
            singleLinkedList.Add(9);

            foreach (var v in singleLinkedList)
                Console.Write(" {0} ", v);

            Console.WriteLine();
            singleLinkedList.Reverse();

            foreach (var v in singleLinkedList)
                Console.Write(" {0} ", v);

            Console.WriteLine();

            Console.ReadLine();
        }
        public void SLL_TENREMOVEALL()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            list.Add(7);
            list.Add(8);
            list.Add(9);
            list.Add(10);
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            list.Remove();
            Assert.AreEqual("", list.ToString());
        }
        public void AddTestMultipleItems()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Add("item2");
            Assert.AreEqual("item2", single.last.value);
        }
        public void AddTestMultipleItemFirstStillSame()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Add("item2");
            Assert.AreEqual("item", single.head.value);
        }
        public void AddNodeReferencesAreCorrectTest()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Add("item2");
            Assert.AreEqual("item2", single.head.next.value);
        }
        public void LengthWithMultipleItemsTest()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Add("item2");
            Assert.AreEqual(2, single.lenght);
        }
示例#9
0
        public static void Main()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
        }
        public void RemoveIsWorkingWithMultipleElementTest()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Add("item2");
            single.Add("item3");
            single.Remove("item3");
            Assert.AreEqual("item2", single.last.value);
        }
        public void RemoveIsWorkingWitChangedHeadTest()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Add("item2");
            single.Add("item3");
            single.Remove("item");
            Assert.AreEqual("item2", single.head.value);
        }
        public static void Start()
        {
            SingleLinkedList <int> List = new SingleLinkedList <int>();

            List.Add(3);
            List.Add(1);
            List.Add(89);
            List.ShowNodes();
            Console.ReadLine();
        }
        static void Main()
        {
            //var listNumbers = TakeInput.ListIntPrepare();

            //var groupSequence = listNumbers
            //    .GroupBy(x => x)
            //    .OrderBy(x => x.Key)
            //    .ToList();

            //foreach (var seq in groupSequence)
            //{
            //    Console.WriteLine("{0} => {1} time{2}",
            //        seq.Key,
            //        seq.Count(),
            //        seq.Count() > 1 ? "s" : "");
            //}

            SingleLinkedList<int> linkedList = new SingleLinkedList<int>();

            linkedList.Add(2);  // 0
            linkedList.Add(5);  // 1
            linkedList.Add(7);  // 2
            linkedList.Add(7);  // 3
            linkedList.Add(13); // 4
            linkedList.Add(19); // 5
            linkedList.Add(21); // 6
            linkedList.Add(34); // 7
            linkedList.Add(13); // 8

            Console.WriteLine(linkedList.LastIndexOf(7));
        }
示例#14
0
        public void AddTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);

            Assert.AreEqual(0, testList[0]);
            Assert.AreEqual(1, testList[1]);
            Assert.AreEqual(2, testList.Count);
        }
示例#15
0
        public void IndexOfTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            Assert.AreEqual(0, testList.IndexOf(0));
            Assert.AreEqual(2, testList.IndexOf(2));
        }
示例#16
0
        static void Main(string[] args)
        {
            SingleLinkedList <string> list = new SingleLinkedList <string>();

            list.Add("Hello");
            list.Add("Brave");
            SingleLinkedList <string> .Node del = list.Add("New");
            list.Add("World");
            list.Insert("Oh");
            list.FindNthToLast(3);
        }
示例#17
0
        public void CopyToArrayArrayIndexTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            int[] array = new int[4];

            Assert.Catch <ArgumentOutOfRangeException>(() => testList.CopyTo(array, -1));
        }
示例#18
0
        public void RemoveStartTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);

            testList.Remove(0);

            Assert.AreEqual(1, testList[0]);
            Assert.AreEqual(1, testList.Count);
        }
示例#19
0
        public void ContainsTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            Assert.IsTrue(testList.Contains(0));
            Assert.IsTrue(testList.Contains(1));
            Assert.IsTrue(testList.Contains(2));
        }
示例#20
0
        public void CopyToArrayToSmallTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            int[] array = new int[4];

            Assert.Catch <ArgumentException>(() => testList.CopyTo(array, 2));
        }
示例#21
0
        public void ClearTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            testList.Clear();

            Assert.AreEqual(0, testList.Count);
            Assert.IsFalse(testList.Contains(0));
        }
        public void contains_does_not_find_value_in_list()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);
            list.Add(45);

            // assert
            Assert.AreEqual(false, list.Contains(99));
        }
        public void head_and_tail_must_have_correct_values()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);

            // assert
            Assert.AreEqual(5, list.First.Value);
            Assert.AreEqual(15, list.Last.Value);
        }
示例#24
0
        public void SLL_AddTest()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            Assert.AreEqual(0, list.Count);

            list.Add(4);
            list.Add(3);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(4, list.Head.Value);
            Assert.AreEqual(3, list.Head.Next.Value);
        }
示例#25
0
        public void RemoveEndTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            testList.Remove(2);

            Assert.AreEqual(0, testList[0]);
            Assert.AreEqual(1, testList[2]);
            Assert.AreEqual(2, testList.Count);
        }
        public void contains_finds_value_in_list()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);
            list.Add(45);

            // assert
            Assert.AreEqual(true, list.Contains(5));
            Assert.AreEqual(true, list.Contains(15));
            Assert.AreEqual(true, list.Contains(45));
        }
示例#27
0
        public void SLL_InsertTest()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            Assert.ThrowsException <IndexOutOfRangeException>(() => list.Insert(6, -1));

            list.Add(4);
            list.Add(3);

            list.Insert(6, 1);
            Assert.ThrowsException <IndexOutOfRangeException>(() => list.Insert(6, 99));

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(6, list.Get(1));
        }
示例#28
0
        public void SLL_CountTest()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            Assert.AreEqual(0, list.Count);

            list.Add(4);
            list.Add(3);

            Assert.AreEqual(2, list.Count);

            list.Add(2);
            list.Add(1);

            Assert.AreEqual(4, list.Count);
        }
        public void SLL_SearchForValueAtHead()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(10);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            list.Add(7);
            list.Add(8);
            list.Add(9);
            list.Add(10);
            Assert.AreEqual(0, list.Search(10));
        }
        public void SLL_TENGETAT9()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            list.Add(7);
            list.Add(8);
            list.Add(9);
            list.Add(10);
            Assert.AreEqual(10, list.Get(9));
        }
示例#31
0
        public void CopyToTest()
        {
            SingleLinkedList <int> testList = new SingleLinkedList <int>();

            testList.Add(0);
            testList.Add(1);
            testList.Add(2);

            int[] array = new int[5];

            testList.CopyTo(array, 2);

            Assert.AreEqual(0, array[2]);
            Assert.AreEqual(1, array[3]);
            Assert.AreEqual(2, array[4]);
        }
        public void SLL_REMOVEONE()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(1);
            list.Remove();
            Assert.AreEqual("", list.ToString());
        }
        public void SLL_TENREMOVEAT9()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            list.Add(7);
            list.Add(8);
            list.Add(9);
            list.Add(10);
            list.RemoveAt(9);
            Assert.AreEqual("1, 2, 3, 4, 5, 6, 7, 8, 9", list.ToString());
        }
        public void add_value_must_be_in_correct_order()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(15);
            list.Add(45);

            var node = list.First;

            // assert
            Assert.AreEqual(5, node.Value);
            Assert.AreEqual(15, node.Next.Value);
            Assert.AreEqual(45, node.Next.Next.Value);
        }
        public void SLL_TENCLEAR()
        {
            SingleLinkedList <int> list = new SingleLinkedList <int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);
            list.Add(6);
            list.Add(7);
            list.Add(8);
            list.Add(9);
            list.Add(10);
            list.Clear();
            Assert.AreEqual("", list.ToString());
        }
        public void RemoveIsWorkingTest()
        {
            SingleLinkedList <string> single = new SingleLinkedList <string>();

            single.Add("item");
            single.Remove("item");
            Assert.AreEqual(true, single.IsEmpty());
        }
示例#37
0
        static void Main()
        {
            SingleLinkedList<int> test = new SingleLinkedList<int>();

            test.Add(5);
            test.Add(2);
            test.Add(10);
            test.Remove(0);
            test.Add(10);

            Console.WriteLine(test.LastIndexOf(10));

            Console.WriteLine("--" + test.Count);

            foreach (var i in test)
            {
                Console.Write(i + " ");
            }

            Console.WriteLine();
        }
        public void iterate_through_entire_list_and_yield_results()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(10);
            list.Add(15);

            var result = "";

            foreach (var item in list.Traverse())
            {
                result += item.ToString();
            }

            // assert
            Assert.AreEqual("51015", result);
        }
        public void remove_one_node_in_list_with_only_one_node()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);

            // assert
            Assert.AreEqual(true, list.Remove(5));
            Assert.IsNull(list.First);
            Assert.IsNull(list.Last);
        }
        public void remove_node_in_middle_of_list_with_multiple_nodes()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(5);
            list.Add(10);
            list.Add(15);

            // assert
            Assert.AreEqual(true, list.Remove(10));
            Assert.AreEqual(5, list.First.Value);
            Assert.AreEqual(15, list.Last.Value);
            Assert.AreEqual(15, list.First.Next.Value);
        }
        public void must_add_node_with_correct_value()
        {
            // assemble
            var list = new SingleLinkedList<int>();

            // act
            list.Add(10);

            // assert
            Assert.AreEqual(10, list.First.Value);
        }