Пример #1
0
        public void Remove_First_Test()
        {
            ILinkedList <char> linkedList = new SingleLinkedListTailless <char>();
            var a = linkedList.AddFirst('A');
            var b = linkedList.AddFirst('B');
            var c = linkedList.AddFirst('C');
            var d = linkedList.AddFirst('D');

            linkedList.RemoveFirst();
            d.Next.Should().BeNull();
            linkedList.First.Value.Should().Be('C');
            linkedList.Count.Should().Be(3);
            linkedList.RemoveFirst();
            c.Next.Should().BeNull();
            linkedList.First.Value.Should().Be('B');
            linkedList.Count.Should().Be(2);
            linkedList.RemoveFirst();
            b.Next.Should().BeNull();
            linkedList.First.Value.Should().Be('A');
            linkedList.Count.Should().Be(1);
            linkedList.RemoveFirst();
            a.Next.Should().BeNull();
            linkedList.First.Should().BeNull();
            linkedList.IsEmpty.Should().BeTrue();

            Action act = () => linkedList.RemoveFirst();

            act.Should().Throw <IndexOutOfRangeException>()
            .WithMessage("Linked list is empty.");
        }
Пример #2
0
        public void Find_Test()
        {
            ILinkedList <char> linkedList = new SingleLinkedListTailless <char>();
            var a = linkedList.AddFirst('A');
            var b = linkedList.AddFirst('B');
            var c = linkedList.AddFirst('C');
            var d = linkedList.AddFirst('D');

            linkedList.Find('B').Value.Should().Be('B');
            linkedList.Find('E').Should().BeNull();
        }
Пример #3
0
        public void Clear_Test()
        {
            ILinkedList <char> linkedList = new SingleLinkedListTailless <char>();
            var a = linkedList.AddFirst('A');
            var b = linkedList.AddFirst('B');
            var c = linkedList.AddFirst('C');
            var d = linkedList.AddFirst('D');

            linkedList.Clear();
            linkedList.First.Should().BeNull();
            linkedList.Count.Should().Be(0);
            linkedList.IsEmpty.Should().BeTrue();
        }
Пример #4
0
        public void Reverse_Test()
        {
            ILinkedList <char> linkedList = new SingleLinkedListTailless <char>();
            var a = linkedList.AddFirst('A');
            var b = linkedList.AddFirst('B');
            var c = linkedList.AddFirst('C');
            var d = linkedList.AddFirst('D');

            linkedList.Reverse();
            linkedList.First.Value.Should().Be('A');
            linkedList.First.Next.Value.Should().Be('B');
            linkedList.First.Next.Next.Value.Should().Be('C');
            linkedList.First.Next.Next.Next.Value.Should().Be('D');
        }
Пример #5
0
        public void Contains_Test()
        {
            ILinkedList <char> linkedList = new SingleLinkedListTailless <char>();
            var a = linkedList.AddFirst('A');
            var b = linkedList.AddFirst('B');
            var c = linkedList.AddFirst('C');
            var d = linkedList.AddFirst('D');

            linkedList.First.Value.Should().Be('D');
            linkedList.Count.Should().Be(4);
            linkedList.Contains('A').Should().BeTrue();
            linkedList.Contains('C').Should().BeTrue();
            linkedList.Contains('D').Should().BeTrue();
            linkedList.Contains('E').Should().BeFalse();
        }
Пример #6
0
        public void Add_First_Simple_Test()
        {
            ILinkedList <char> linkedList = new SingleLinkedListTailless <char>();
            var a = linkedList.AddFirst('A');
            var b = linkedList.AddFirst('B');
            var c = linkedList.AddFirst('C');
            var d = linkedList.AddFirst('D');

            linkedList.First.Value.Should().Be('D');
            linkedList.Count.Should().Be(4);
            d.Next.Value.Should().Be('C');
            c.Next.Value.Should().Be('B');
            b.Next.Value.Should().Be('A');
            a.Next.Should().BeNull();
        }