예제 #1
0
        static void TestFindElements()
        {
            Console.WriteLine("find elements test");

            var list = new LinkedList2();

            list.AddInTail(new Node(20));
            list.AddInTail(new Node(24));
            list.AddInTail(new Node(10));
            list.AddInTail(new Node(15));
            list.AddInTail(new Node(77));
            list.AddInTail(new Node(24));

            Console.WriteLine("find 20");
            var result = list.FindAll(20);

            foreach (var item in result)
            {
                Console.WriteLine(item.value);
            }

            Console.WriteLine("find 24");
            result = list.FindAll(24);
            foreach (var item in result)
            {
                Console.WriteLine(item.value);
            }

            Console.WriteLine(new string('=', 30));
        }
예제 #2
0
        public void FindAllInEmptyList()
        {
            LinkedList2 list     = new LinkedList2();
            List <Node> nodeList = list.FindAll(10);

            Assert.IsTrue(nodeList.Count == 0);
        }
예제 #3
0
        private void FindAllTest(int valueToFind, params Node[] nodes)
        {
            LinkedList2 list = GetLinkedList(nodes);

            IEnumerable <Node> expectedNodes = nodes.Where(node => node.value == valueToFind);

            Assert.True(expectedNodes.SequenceEqual(
                            list.FindAll(valueToFind),
                            new NodeValueEqualityComparer()));
        }
        public void AddInHead_if_List_Is_Contain_the_Same_NodeValue()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            testList.AddInTail(new Node(4));
            testList.AddInHead(new Node(4));
            int expected = 7;
            int actual   = testList.Count();


            List <Node> resultsList = testList.FindAll(4);

            Assert.AreEqual(expected, actual);
            Assert.IsTrue(testList.FindAll(4).Count == 5);
        }
예제 #5
0
        public void FindAllInFilledList()
        {
            LinkedList2 list = new LinkedList2();

            list.AddInTail(new Node(10));
            list.AddInTail(new Node(20));
            list.AddInTail(new Node(10));
            list.AddInTail(new Node(30));
            list.AddInTail(new Node(10));
            List <Node> nodeList = list.FindAll(10);

            Assert.IsTrue(nodeList.Count == 3);
        }
예제 #6
0
        public static void TestFindAll()
        {
            var testList = new LinkedList2();

            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(4));
            var foundList = testList.FindAll(1);

            Assert.AreEqual(3, foundList.Count, "Test TestFindAll failed. List foundList count not equal 3");
        }
예제 #7
0
        public void Test_FindAll_WhenNoFoundItems()
        {
            var list      = new LinkedList2();
            var sameValue = 2;
            var node1     = new Node(1);
            var node2     = new Node(sameValue);
            var node3     = new Node(4);
            var node4     = new Node(sameValue);
            var expected  = new List <Node>();

            list.AddInTail(node1);
            list.AddInTail(node2);
            list.AddInTail(node3);
            list.AddInTail(node4);
            var foundNodes = list.FindAll(0);

            CollectionAssert.AreEqual(expected, foundNodes);
        }
예제 #8
0
        public void TestFindAll()
        {
            var testBigValue = 1000;
            var list         = new LinkedList2();

            list.AddInTail(new Node(testBigValue));
            Program.GenerateLinkedListElements(list, ElementsCount);
            list.AddInTail(new Node(testBigValue));
            Program.GenerateLinkedListElements(list, ElementsCount);
            list.AddInTail(new Node(testBigValue));

            var resultList = list.FindAll(testBigValue);

            Assert.AreEqual(3, resultList.Count);
            foreach (var e in resultList)
            {
                Assert.AreEqual(testBigValue, e.value);
            }
        }
        public void Remove_if_more_One_Exists()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInTail(new Node(0));
            testList.AddInTail(new Node(1));
            testList.AddInTail(new Node(5));
            testList.AddInTail(new Node(2));
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(4));
            testList.AddInTail(new Node(5));
            int expected = 6;

            testList.Remove(5);
            int actual = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsTrue(testList.FindAll(5).Count >= 1);
        }