Ejemplo n.º 1
0
        public void ElementAt_should_throw_IndexOutOfRangException_if_index_is_less_than_0()
        {
            //Arrange
            var list  = new Structures.LinkedList <int>();
            int index = -1;

            //Act & Assert
            Assert.Throws <IndexOutOfRangeException>(() => list.ElementAt(index));
        }
Ejemplo n.º 2
0
        public void ElementAt_should_throw_IndexOutOfRangException_if_index_is_equal_to_count()
        {
            //Arrange
            var list  = new Structures.LinkedList <int>();
            int index = list.Length;

            //Act & Assert
            Assert.Throws <IndexOutOfRangeException>(() => list.ElementAt(index));
        }
Ejemplo n.º 3
0
        private Structures.LinkedList <int> GetIntegerList()
        {
            var list = new Structures.LinkedList <int>();

            for (int i = 0; i < 10; i++)
            {
                list.AddLast(i);
            }

            return(list);
        }
Ejemplo n.º 4
0
        private string GetStringOfElements(Structures.LinkedList <int> list)
        {
            var builder = new StringBuilder("");

            foreach (var el in list)
            {
                builder.Append(el);
            }

            return(builder.ToString());
        }
Ejemplo n.º 5
0
        public void Length_should_return_0_if_list_is_empty()
        {
            //Arrange
            var list           = new Structures.LinkedList <int>();
            var expectedLength = 0;

            //Act
            var length = list.Length;

            //Assert
            Assert.AreEqual(expectedLength, length);
        }
Ejemplo n.º 6
0
        public void Remove_should_return_false_if_item_does_not_exist()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);

            //Act
            var result = list.Remove(2);

            //Assert
            Assert.False(result);
        }
Ejemplo n.º 7
0
        public void Remove_should_return_true_if_item_has_been_deleted()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);

            //Act
            var result = list.Remove(1);

            //Assert
            Assert.True(result);
        }
Ejemplo n.º 8
0
        public void InsertAfter_should_return_false_if_list_is_empty()
        {
            //Arrange
            var list   = new Structures.LinkedList <int>();
            int target = 0;
            int data   = 0;

            //Act
            var actionResult = list.InsertAfter(target, data);

            //Assert
            Assert.False(actionResult);
        }
Ejemplo n.º 9
0
        public void AddAt_should_add_element_on_first_position_if_list_is_empty()
        {
            //Arrange
            var list  = new Structures.LinkedList <int>();
            int index = 0;
            int data  = 0;

            //Act
            var actionResult = list.AddAt(index, data);

            //Assert
            Assert.True(actionResult);
        }
Ejemplo n.º 10
0
        public void AddAt_should_return_false_if_index_is_out_of_range()
        {
            //Arrange
            var list  = new Structures.LinkedList <int>();
            int index = -1;
            int data  = 0;

            //Act
            var actionResult = list.AddAt(index, data);

            //Assert
            Assert.False(actionResult);
        }
Ejemplo n.º 11
0
        public void RemoveAt_should_return_false_if_index_if_out_of_range()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            int index = -1;

            //Act
            bool result = list.RemoveAt(index);

            //Assert
            Assert.False(result);
        }
Ejemplo n.º 12
0
        public void AddLast_should_return_list_with_one_element_if_it_was_empty()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            var expectedLength = 1;

            //Act
            var length = list.Length;

            //Assert
            Assert.AreEqual(expectedLength, length);
        }
Ejemplo n.º 13
0
        public void AddLast_should_add_data_on_last_position()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            list.AddLast(2);
            var expectedContent = "12";

            //Act
            var content = GetStringOfElements(list);

            //Assert
            Assert.AreEqual(expectedContent, content);
        }
Ejemplo n.º 14
0
        public void Count_should_return_count_of_elements_if_list_is_not_empty()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            list.AddLast(1);
            var expectedLength = 2;

            //Act
            var length = list.Length;

            //Assert
            Assert.AreEqual(expectedLength, length);
        }
Ejemplo n.º 15
0
        public void ElementAt_should_return_item_data_on_specified_position()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();
            int data = 1;

            list.AddLast(data);
            int index = 0;

            //Act
            var item = list.ElementAt(index);

            //Assert
            Assert.AreEqual(data, item);
        }
Ejemplo n.º 16
0
        public void Remove_should_decrease_count_if_success()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            var expectedLength = list.Length - 1;

            //Act
            list.Remove(1);
            var length = list.Length;

            //Assert
            Assert.AreEqual(expectedLength, length);
        }
Ejemplo n.º 17
0
        public void Remove_should_remove_first_occurence_of_item()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(1);
            string expectedResult = "21";

            //Act
            list.Remove(1);

            //Assert
            Assert.AreEqual(expectedResult, GetStringOfElements(list));
        }
Ejemplo n.º 18
0
        public void RemoveAt_should_decrease_count_if_success()
        {
            //Arrange
            Structures.LinkedList <int> list = GetIntegerList();
            int index = 0;

            list.AddLast(1);
            var expectedLength = list.Length - 1;

            //Act
            list.RemoveAt(index);
            var length = list.Length;

            //Assert
            Assert.AreEqual(expectedLength, length);
        }
Ejemplo n.º 19
0
        public void GetEnumerator_should_return_all_items()
        {
            //Arrange
            var list = new Structures.LinkedList <int>();

            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);
            var expectedResult = "123";
            var result         = "";

            //Act
            foreach (var el in list)
            {
                result += el;
            }

            //Assert
            Assert.AreEqual(expectedResult, result);
        }