Пример #1
0
 public void 大きさが足りないarrayにCopyToすると例外が飛ぶ()
 {
     linkedList = new ShosLinkedList <int> {
         10, 30
     };
     linkedList.CopyTo(new int[2], 1);
 }
Пример #2
0
        public void Removeできる()
        {
            linkedList = new ShosLinkedList <int> {
                10, 70, 30, 40, 60, 90, 100
            };

            Assert.IsTrue(linkedList.Remove(10));
            AssertExtensions.AreEqual(new[] { 70, 30, 40, 60, 90, 100 }, linkedList);
            Assert.IsTrue(linkedList.Remove(100));
            AssertExtensions.AreEqual(new[] { 70, 30, 40, 60, 90 }, linkedList);
            Assert.IsTrue(linkedList.Remove(40));
            AssertExtensions.AreEqual(new[] { 70, 30, 60, 90 }, linkedList);
            Assert.IsFalse(linkedList.Remove(40));
            AssertExtensions.AreEqual(new[] { 70, 30, 60, 90 }, linkedList);

            var node = linkedList.Find(70);

            linkedList.Remove(node);
            AssertExtensions.AreEqual(new[] { 30, 60, 90 }, linkedList);
            node = linkedList.Find(60);
            linkedList.Remove(node);
            AssertExtensions.AreEqual(new[] { 30, 90 }, linkedList);
            node = linkedList.Find(90);
            linkedList.Remove(node);
            AssertExtensions.AreEqual(new[] { 30 }, linkedList);
        }
Пример #3
0
 public void 初期化リストが使える()
 {
     linkedList = new ShosLinkedList <int> {
         10, 60, 30
     };
     AssertExtensions.AreEqual(new[] { 10, 60, 30 }, linkedList);
 }
Пример #4
0
 public void FindLastTest()
 {
     ShosLinkedList <int> .Node?node = null;
     for (var number = 1; number <= dataNumber; number++)
     {
         node = linkedList.FindLast(dataNumber / 2);
     }
 }
Пример #5
0
 public void Containsできる()
 {
     Assert.IsFalse(linkedList.Contains(10));
     linkedList = new ShosLinkedList <int> {
         30, 60
     };
     Assert.IsTrue(linkedList.Contains(30));
     Assert.IsFalse(linkedList.Contains(40));
 }
Пример #6
0
        public void コレクションでCreateできる()
        {
            linkedList = new ShosLinkedList <int>(new int[] { });
            Assert.AreEqual(0, linkedList.Count);

            linkedList = new ShosLinkedList <int>(new[] { 10, 30, 70 });
            Assert.AreEqual(3, linkedList.Count);
            AssertExtensions.AreEqual(new[] { 10, 30, 70 }, linkedList);
        }
Пример #7
0
 public void RemoveLastできる()
 {
     linkedList = new ShosLinkedList <int> {
         20, 40, 80
     };
     linkedList.RemoveLast();
     AssertExtensions.AreEqual(new[] { 20, 40 }, linkedList);
     linkedList.RemoveLast();
     AssertExtensions.AreEqual(new[] { 20 }, linkedList);
     linkedList.RemoveLast();
     AssertExtensions.AreEqual(new int[] { }, linkedList);
 }
Пример #8
0
 public void RemoveFirstできる()
 {
     linkedList = new ShosLinkedList <int> {
         60, 30, 20
     };
     linkedList.RemoveFirst();
     AssertExtensions.AreEqual(new[] { 30, 20 }, linkedList);
     linkedList.RemoveFirst();
     AssertExtensions.AreEqual(new[] { 20 }, linkedList);
     linkedList.RemoveFirst();
     AssertExtensions.AreEqual(new int[] {}, linkedList);
 }
Пример #9
0
        public void Clearできる()
        {
            linkedList = new ShosLinkedList <int> {
                10, 70, 30
            };
            linkedList.Clear();
            Assert.AreEqual(0, linkedList.Count);
            Assert.IsNull(linkedList.First);
            Assert.IsNull(linkedList.Last);

            linkedList.AddLast(40);
            linkedList.AddLast(20);
            AssertExtensions.AreEqual(new[] { 40, 20 }, linkedList);
        }
Пример #10
0
        public void AddBeforeできる()
        {
            linkedList = new ShosLinkedList <int> {
                10
            };
            linkedList.AddBefore(linkedList.First, 30);
            AssertExtensions.AreEqual(new[] { 30, 10 }, linkedList);

            linkedList.AddBefore(linkedList.Last, 90);
            AssertExtensions.AreEqual(new[] { 30, 90, 10 }, linkedList);

            var node = linkedList.Find(90);

            linkedList.AddBefore(node, 110);
            AssertExtensions.AreEqual(new[] { 30, 110, 90, 10 }, linkedList);
        }
Пример #11
0
        public void AddAfterできる()
        {
            linkedList = new ShosLinkedList <int> {
                10
            };
            linkedList.AddAfter(linkedList.First, 70);
            AssertExtensions.AreEqual(new[] { 10, 70 }, linkedList);

            linkedList.AddAfter(linkedList.Last, 40);
            AssertExtensions.AreEqual(new[] { 10, 70, 40 }, linkedList);

            var node = linkedList.Find(70);

            linkedList.AddAfter(node, 100);
            AssertExtensions.AreEqual(new[] { 10, 70, 100, 40 }, linkedList);
        }
Пример #12
0
        public void FindLastできる()
        {
            Assert.IsNull(linkedList.FindLast(10));
            linkedList = new ShosLinkedList <int> {
                40, 30, 60, 30, 40, 20, 40
            };
            Assert.IsNull(linkedList.FindLast(100));

            var node = linkedList.FindLast(40);

            Assert.IsNotNull(node);
            Assert.AreEqual(40, node.Value);
            Assert.AreSame(node, linkedList.Last);
            linkedList.Remove(node);
            AssertExtensions.AreEqual(new[] { 40, 30, 60, 30, 40, 20 }, linkedList);
            linkedList.Remove(linkedList.FindLast(30));
            AssertExtensions.AreEqual(new[] { 40, 30, 60, 40, 20 }, linkedList);
        }
Пример #13
0
        public void CopyToできる()
        {
            var array = new int[] { };

            linkedList.CopyTo(array, 0);
            AssertExtensions.AreEqual(new int[] { }, array);

            linkedList = new ShosLinkedList <int> {
                30, 60
            };
            array = new int[] { 10, 20 };
            linkedList.CopyTo(array, 0);
            AssertExtensions.AreEqual(array, linkedList);
            array = new int[] { 10, 20, 30 };
            linkedList.CopyTo(array, 0);
            AssertExtensions.AreEqual(new [] { 30, 60, 30 }, array);
            linkedList.CopyTo(array, 1);
            AssertExtensions.AreEqual(new[] { 30, 30, 60 }, array);
        }
Пример #14
0
 public void Setup() => linkedList = new ShosLinkedList <int>();