Example #1
0
        public void Can_add_to_list_beyond_initial_capacity()
        {
            // Arrange
            const int           Capacity = 1;
            MyGenericList <int> myList   = new MyGenericList <int>(Capacity);

            myList.Add(5);

            // Act
            myList.Add(10);

            // Assert
            Assert.Equal(2, myList.Count);
            Assert.Equal(5, myList[0]);
            Assert.Equal(10, myList[1]);

            // Act
            myList.Add(20);
            myList.Add(40);
            myList.Add(80);

            // Assert
            Assert.Equal(5, myList.Count);
            Assert.Equal(80, myList[4]);
        }
Example #2
0
        public void Initial_list_is_empty()
        {
            // Arrange

            // Act
            MyGenericList <string> myList = new MyGenericList <string>();

            // Assert
            Assert.Equal(0, myList.Count);
        }
Example #3
0
        public void List_of_Dates()
        {
            MyGenericList <DateTime> nowish = new MyGenericList <DateTime>
            {
                DateTime.Now,
            };

            MyGenericList <DayOfWeek> days = new MyGenericList <DayOfWeek>
            {
                DayOfWeek.Tuesday,
                default(DayOfWeek),
Example #4
0
        public void Can_add_to_empty_list()
        {
            // Arrange
            MyGenericList <int> myList = new MyGenericList <int>();

            // Act
            myList.Add(5);

            // Assert
            Assert.Equal(1, myList.Count);
            Assert.Equal(5, myList[0]);
        }
Example #5
0
        public void Can_reduce_numbers_for_sum()
        {
            var numbers = new MyGenericList <int>
            {
                1, 1, 2, 3, 5, 8,
            };

            // numbers = "oops"; // Not legal even though type was inferred

            int result = numbers.Aggregate(0, (sum, next) => sum + next);

            Assert.Equal(20, result);
        }
Example #6
0
        public void Can_enumerate_a_list()
        {
            // Behind the scenes, just calls Add()
            MyGenericList <string> myList = new MyGenericList <string>
            {
                "Keith",
                "Craig",
                "Ian",
            };

            foreach (string item in myList)
            {
                Assert.NotNull(item);
            }

            Assert.Equal(
                new[] { "Keith", "Craig", "Ian" },
                myList);
        }