Exemplo n.º 1
0
        public void Test_Remove_WhenFoundItemInTailTwoTimes()
        {
            var list         = new LinkedList2();
            var deletedValue = 3;
            var node1        = new Node(1);
            var node2        = new Node(2);
            var node3        = new Node(deletedValue);
            var node4        = new Node(deletedValue);

            list.AddInTail(node1);
            list.AddInTail(node2);
            list.AddInTail(node3);
            list.AddInTail(node4);
            var head = list.head;

            list.Remove(deletedValue);
            list.Remove(deletedValue);
            var expected        = "[1, 2]";
            var reverseExpected = "[2, 1]";

            Assert.AreEqual(expected, list.ToString());
            Assert.AreEqual(reverseExpected, list.ReverseToString());
            Assert.AreEqual(head, list.head);
            Assert.AreEqual(node2, list.tail);
        }
Exemplo n.º 2
0
        public void RemoveInEmptyList()
        {
            LinkedList2 list = new LinkedList2();

            list.RemoveAll(10);
            Assert.IsTrue(list.head == null && list.tail == null);
        }
Exemplo n.º 3
0
        public void FindAllInEmptyList()
        {
            LinkedList2 list     = new LinkedList2();
            List <Node> nodeList = list.FindAll(10);

            Assert.IsTrue(nodeList.Count == 0);
        }
Exemplo n.º 4
0
        public void Test_RemoveAll_WhenManyFoundItemsInMiddle()
        {
            var list         = new LinkedList2();
            var deletedValue = 2;
            var node1        = new Node(1);
            var node2        = new Node(deletedValue);
            var node3        = new Node(deletedValue);
            var node4        = new Node(3);

            list.AddInTail(node1);
            list.AddInTail(node2);
            list.AddInTail(node3);
            list.AddInTail(node4);
            var head = list.head;
            var tail = list.tail;

            list.RemoveAll(deletedValue);
            var expected        = "[1, 3]";
            var reverseExpected = "[3, 1]";

            Assert.AreEqual(expected, list.ToString());
            Assert.AreEqual(reverseExpected, list.ReverseToString());
            Assert.AreEqual(head, list.head);
            Assert.AreEqual(tail, list.tail);
        }
Exemplo n.º 5
0
        public static void TestInsertAfter()
        {
            var testList = new LinkedList2();

            testList.InsertAfter(null, new Node(1));
            Assert.AreEqual(1, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 1");
            testList.AddInTail(new Node(3));
            testList.AddInTail(new Node(5));
            testList.InsertAfter(new Node(3), new Node(4));
            Assert.AreEqual(4, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 4");
            testList.InsertAfter(new Node(1), new Node(2));
            Assert.AreEqual(5, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 5");
            testList.InsertAfter(new Node(5), new Node(6));
            Assert.AreEqual(6, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 6");
            testList.InsertAfter(null, new Node(0));
            Assert.AreEqual(7, testList.Count(), "Test TestInsertAfter failed. List count have to be equal 7");
            Assert.AreEqual(0, testList.head.value, "Test TestInsertAfter failed. List head.value have to be equal 0");
            Assert.AreEqual(6, testList.tail.value, "Test TestInsertAfter failed. List tail.value have to be equal 6");
            Assert.IsNull(testList.tail.next, "Test TestInsertAfter failed. List tail.next have to be equal NULL");
            Assert.IsNull(testList.head.prev, "Test TestInsertAfter failed. List head.prev have to be equal NULL");
            Assert.IsNotNull(testList.tail.prev, "Test TestInsertAfter failed. List tail.prev have to be equal NOT NULL");
            Assert.IsNotNull(testList.head.next, "Test TestInsertAfter failed. List head.next have to be equal NOT NULL");

            int  counter = -1;
            Node node    = testList.head;

            while (node != null)
            {
                counter += 1;
                Assert.AreEqual(counter, node.value, "Test TestInsertAfter failed. List sequence is not correct");
                node = node.next;
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        static void TestFindElement()
        {
            Console.WriteLine("find element 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.Find(20);

            Console.WriteLine("result " + result.value);

            Console.WriteLine("find 10");
            result = list.Find(10);
            Console.WriteLine("result " + result.value);

            Console.WriteLine("find 24");
            result = list.Find(24);
            Console.WriteLine("result " + result.value);

            Console.WriteLine(new string('=', 30));
        }
Exemplo n.º 8
0
        public PackedExponentTape(
            PackedExponentTape src,
            bool cutOffLeft  = false,
            bool cutOffRight = false)
        {
            if (src == null)
            {
                throw new ArgumentNullException();
            }

            Macro            = new MacroPacker(src.Macro);
            _PositionInMacro = src._PositionInMacro;
            FacingRight      = src.FacingRight;
            Shifts           = src.Shifts;

            if (!cutOffLeft)
            {
                _L = new LinkedList2 <Cell> (src._L.Select(c => c.Clone()));
            }
            if (!cutOffRight)
            {
                _R = new LinkedList2 <Cell> (src._R.Select(c => c.Clone()));
            }

            CheckConsistency();
        }
Exemplo n.º 9
0
        public void Test_Count_WhenEmpty()
        {
            var list  = new LinkedList2();
            var count = list.Count();

            Assert.AreEqual(0, count);
        }
Exemplo n.º 10
0
        public void AddInEmptyList()
        {
            LinkedList2 list = new LinkedList2();
            Node        node = new Node(10);

            list.AddInHead(node);
            Assert.IsTrue(list.head == node && list.tail == node);
        }
Exemplo n.º 11
0
        private void FindTest(int valueToFind, params Node[] nodes)
        {
            LinkedList2 list = GetLinkedList(nodes);

            Node expectedNode = nodes.FirstOrDefault(n => n.value == valueToFind);

            Assert.Same(expectedNode, list.Find(valueToFind));
        }
Exemplo n.º 12
0
        public void InsertInEmptyList()
        {
            LinkedList2 list  = new LinkedList2();
            Node        node  = new Node(10);
            Node        node2 = new Node(20);

            list.InsertAfter(node2, node);
            Assert.IsTrue(list.head == node && list.tail == node);
        }
Exemplo n.º 13
0
        public void Test_AddInTail_Once()
        {
            var list  = new LinkedList2();
            var node1 = new Node(1);

            list.AddInTail(node1);
            Assert.AreEqual(list.tail, list.head);
            Assert.AreEqual(node1, list.head);
        }
Exemplo n.º 14
0
        private void ClearTest(params Node[] nodes)
        {
            LinkedList2 list = GetLinkedList(nodes);

            list.Clear();

            Assert.Null(list.head);
            Assert.Null(list.tail);
        }
Exemplo n.º 15
0
        public void FindInFilledList()
        {
            LinkedList2 list     = new LinkedList2();
            Node        testNode = new Node(12);

            list.AddInTail(new Node(10));
            list.AddInTail(new Node(11));
            list.AddInTail(testNode);
            Assert.IsTrue(list.Find(13) == null && list.Find(12) == testNode);
        }
Exemplo n.º 16
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()));
        }
Exemplo n.º 17
0
        public void InsertInFilledOneListWithoutNodeAfter()
        {
            LinkedList2 list  = new LinkedList2();
            Node        node  = new Node(10);
            Node        node2 = new Node(20);

            list.AddInTail(node2);
            list.InsertAfter(null, node);
            Assert.IsTrue(list.head == node && list.tail == node2);
        }
Exemplo n.º 18
0
        public void TestMethod1()
        {
            LinkedList2 list = new LinkedList2();

            list.AddInTail(new Node(10));
            list.AddInTail(new Node(11));
            list.AddInTail(new Node(12));
            list.Clear();
            Assert.IsTrue(list.head == null && list.tail == null);
        }
Exemplo n.º 19
0
        public void Test_Count_WhenNonEmpty()
        {
            var list = new LinkedList2();
            var node = new Node(1);

            list.AddInTail(node);
            var count = list.Count();

            Assert.AreEqual(1, count);
        }
Exemplo n.º 20
0
        public void Test_AddInTail_TwoTimes()
        {
            var list  = new LinkedList2();
            var node1 = new Node(1);
            var node2 = new Node(1);

            list.AddInTail(node1);
            list.AddInTail(node2);
            Assert.AreEqual(node1, list.head);
            Assert.AreEqual(node2, list.tail);
        }
        public void AddInHead_in_EmptyList()
        {
            LinkedList2 testList = new LinkedList2();

            testList.AddInHead(new Node(21));

            int expected = 1;
            int actual   = testList.Count();

            Assert.AreEqual(expected, actual);
            Assert.IsNotNull(testList.Find(21));
        }
Exemplo n.º 22
0
        public void Test_Find_WhenOneFoundItem()
        {
            var list  = new LinkedList2();
            var node1 = new Node(1);
            var node2 = new Node(2);

            list.AddInTail(node1);
            list.AddInTail(node2);
            var foundNode = list.Find(node2.value);

            Assert.AreEqual(node2, foundNode);
        }
Exemplo n.º 23
0
        public void RemoveAllTest507()
        {
            LinkedList2 linkedList;

            linkedList      = new LinkedList2();
            linkedList.head = (Node)null;
            linkedList.tail = (Node)null;
            this.RemoveAllTest(linkedList2, 0);
            Assert.IsNotNull((object)linkedList);
            Assert.IsNull((object)(linkedList.head));
            Assert.IsNull((object)(linkedList.tail));
        }
Exemplo n.º 24
0
        public void Test_InsertAfter_WhenEmpty()
        {
            var list     = new LinkedList2();
            var head     = list.head;
            var node1    = new Node(1);
            var expected = "[1]";

            list.InsertAfter(head, node1);
            Assert.AreEqual(node1, list.head);
            Assert.AreEqual(node1, list.tail);
            Assert.AreEqual(expected, list.ToString());
        }
Exemplo n.º 25
0
        public static void TestAddInTail()
        {
            var testList = new LinkedList2();

            Assert.AreEqual(0, testList.Count(), "Test TestAddInTail failed. Initial list count have to be equal 0");
            testList.AddInTail(new Node(1));
            Assert.AreEqual(1, testList.Count(), "Test TestAddInTail failed. List count have to be equal 1");
            testList.AddInTail(new Node(2));
            Assert.AreEqual(2, testList.Count(), "Test TestAddInTail failed. List count have to be equal 2");
            testList.AddInTail(new Node(3));
            Assert.AreEqual(3, testList.Count(), "Test TestAddInTail failed. List count have to be equal 3");
            Assert.IsNull(testList.tail.next, "Test TestAddInTail failed. List tail.next not equal NULL");
        }
Exemplo n.º 26
0
        public static void TestClear()
        {
            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));
            testList.Clear();
            Assert.AreEqual(0, testList.Count(), "Test TestClear failed. List count not equal 0");
        }
Exemplo n.º 27
0
        public void Test_RemoveAll_WhenListIsEmpty()
        {
            var list         = new LinkedList2();
            var deletedValue = 2;

            list.RemoveAll(deletedValue);
            var expected = "[]";

            Assert.AreEqual(expected, list.ToString());
            Assert.AreEqual(expected, list.ReverseToString());
            Assert.AreEqual(null, list.head);
            Assert.AreEqual(null, list.tail);
        }
Exemplo n.º 28
0
        public void Test_Clear_WhenNonEmpty()
        {
            var list  = new LinkedList2();
            var node1 = new Node(1);

            list.AddInTail(node1);
            list.Clear();
            var count = list.Count();

            Assert.AreEqual(null, list.head);
            Assert.AreEqual(null, list.tail);
            Assert.AreEqual(0, count);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        public void RemoveAll_10()
        {
            LinkedList2 list = new LinkedList2();

            list.AddInTail(new Node(10));
            list.AddInTail(new Node(11));
            list.AddInTail(new Node(10));
            list.AddInTail(new Node(12));
            list.AddInTail(new Node(10));
            list.AddInTail(new Node(13));
            list.RemoveAll(10);
            Assert.IsTrue(list.head.value == 11 && list.head.next.value == 12 && list.tail.value == 13);
        }
        public static void Main()
        {
            var test = new LinkedList2<string>();

            test.AddFirst("First string");
            test.AddLast("Second string");
            test.AddFirst("Should be before first");
            test.AddLast("Should be after last");

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

            test.Clear();
            foreach (var item in test)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 32
0
		public PackedExponentTape (
			PackedExponentTape src,
			bool cutOffLeft = false,
			bool cutOffRight = false)
		{
			if (src == null)
				throw new ArgumentNullException ();

			Macro = new MacroPacker (src.Macro);
			_PositionInMacro = src._PositionInMacro;
			FacingRight = src.FacingRight;
			Shifts = src.Shifts;

			if (!cutOffLeft) {
				_L = new LinkedList2<Cell> (src._L.Select (c => c.Clone ()));
			}
			if (!cutOffRight) {
				_R = new LinkedList2<Cell> (src._R.Select (c => c.Clone ()));
			}

			CheckConsistency ();
		}