Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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));
        }
Beispiel #4
0
        private Structures.LinkedList <int> GetIntegerList()
        {
            var list = new Structures.LinkedList <int>();

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

            return(list);
        }
Beispiel #5
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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
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);
        }
Beispiel #11
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);
        }
Beispiel #12
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);
        }