Пример #1
0
        public void TestRemoveNode()
        {
            // Arrange
            ReadCopyUpdateList <int> list = new ReadCopyUpdateList <int>();

            // Assume
            AssertThrow <ArgumentNullException>(() => list.Remove(null));

            // Act
            bool removeFromEmptyList           = list.Remove(new ReadCopyUpdateListNode <int>(0));
            ReadCopyUpdateListNode <int> node0 = list.AddFirst(0);
            ReadCopyUpdateListNode <int> node1 = list.AddAfter(node0, 1);
            ReadCopyUpdateListNode <int> node2 = list.AddAfter(node1, 2);
            ReadCopyUpdateListNode <int> node3 = list.AddAfter(node2, 3);
            ReadCopyUpdateListNode <int> node4 = list.AddAfter(node3, 4);

            list.AddAfter(node4, 5);

            bool removed3      = list.Remove(node3);
            bool removed3Again = list.Remove(node3);
            bool removed72     = list.Remove(new ReadCopyUpdateListNode <int>(72));
            bool removed0      = list.Remove(node0);

            // Assert
            Assert.IsFalse(removeFromEmptyList);
            Assert.IsTrue(removed3);
            Assert.IsFalse(removed3Again);
            Assert.IsFalse(removed72);
            Assert.IsTrue(removed0);
        }
Пример #2
0
        public void TestAddAfter()
        {
            // Arrange
            ReadCopyUpdateList <int> list = new ReadCopyUpdateList <int>();

            // Assume
            AssertThrow <ArgumentNullException>(() => list.AddAfter(null, 4));

            // Act
            ReadCopyUpdateListNode <int> last    = list.AddFirst(0); // Will be last when next node added
            ReadCopyUpdateListNode <int> first   = list.AddFirst(1);
            ReadCopyUpdateListNode <int> newLast = list.AddAfter(last, 2);
            ReadCopyUpdateListNode <int> mid     = list.AddAfter(first, 3);

            // Assert
            Assert.AreEqual(first, list.First);
            Assert.AreEqual(mid, first.Next);
            Assert.AreEqual(last, mid.Next);
            Assert.AreEqual(newLast, last.Next);
        }