Add() public method

public Add ( item ) : void
return void
        public void MinusOperator_SubstractingSecondListHasMoreItems_ShouldReturnSubstractedList()
        {
            // arrange
            CustomClassList <int> test1     = new CustomClassList <int>();
            CustomClassList <int> test2     = new CustomClassList <int>();
            CustomClassList <int> expected1 = new CustomClassList <int>();
            CustomClassList <int> actual1   = new CustomClassList <int>();

            test1.Add(0);
            test1.Add(1);
            test1.Add(2);
            test2.Add(1);
            test2.Add(3);
            test2.Add(4);
            test2.Add(5);
            expected1.Add(0);
            expected1.Add(2);
            string expected = expected1.ToString();

            // act
            actual1 = test1 - test2;
            string actual = actual1.ToString();

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void PlusOperator_AddTwoCustomIntegerListsTogether_LastItemShouldBeTheLastIndexOfSecondList()
        {
            // arrange
            CustomClassList <int> test1 = new CustomClassList <int>();
            CustomClassList <int> test2 = new CustomClassList <int>();

            test1.Add(1);
            test1.Add(3);
            test1.Add(5);
            test2.Add(2);
            test2.Add(4);
            test2.Add(6);
            CustomClassList <int> result;
            int expected;
            int actual;

            // act
            result   = new CustomClassList <int>();
            result   = test1 + test2;
            actual   = test2[2];
            expected = result[5];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 3
0
        public void PlusOperator_AddTwoCustomIntegerListsWithThreeAndFiveItems_FourthItemOfResultListShouldBeFirstIndexOfSecondList()
        {
            // arrange
            CustomClassList <int> test1 = new CustomClassList <int>();
            CustomClassList <int> test2 = new CustomClassList <int>();

            test1.Add(1);
            test1.Add(2);
            test1.Add(3);
            test2.Add(4);
            test2.Add(5);
            test2.Add(6);
            test2.Add(7);
            test2.Add(8);
            CustomClassList <int> result;
            int expected;
            int actual;

            // act
            result   = new CustomClassList <int>();
            result   = test1 + test2;
            actual   = test2[0];
            expected = result[3];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void ToString_AListOfBooleans_ReturnFirstBoolPlusSecond()
        {
            // arrange
            CustomClassList <bool> test = new CustomClassList <bool>();

            test.Add(true);
            test.Add(false);
            test.Add(true);
            string actual;

            // act
            actual = test.ToString();

            // assert
            actual.Should().Be("TrueFalseTrue");
        }
Ejemplo n.º 5
0
        public void Remove_ListDoesNotContainTheItem_ReturnsFalse()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            bool expected = false;
            bool actual;

            // act
            actual = test.Remove(3);

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void Indexer_GettingValueOfIndexNotExists_ThrowsError()
        {
            // Arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            int value;

            // Act
            Action act = () => value = test[4];

            // Assert
            act.Should().Throw <ArgumentOutOfRangeException>();
        }
Ejemplo n.º 7
0
        public void Add_AddToListWithTwoItems_CountGoesUpByOne()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(1);
            test.Add(2);
            int expected = 3;
            int actual;

            // act
            test.Add(3);
            actual = test[2];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void ToString_ApplyTOAListOfIntegers_ShouldReturnString()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            string actual;

            // act
            actual = test.ToString();

            // assert
            actual.Should().Be("0123");
        }
Ejemplo n.º 9
0
        public void Add_AddToListWithTwoItems_ValueGoesToIndexTwo()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(1);
            test.Add(2);
            int expected = 8;
            int actual;

            // act
            test.Add(8);
            actual = test[2];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public void Remove_RemoveAnItemFromList_CountDecreasesByOne()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            int expected = 2;
            int actual;

            // act
            test.Remove(2);
            actual = test.Count;

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void Remove_RemoveItemFromTheList_ShiftsRemainderItemsAccordingly()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            int expected = 1;
            int actual;

            // act
            test.Remove(0);
            actual = test[0];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void ToString_ApplyToAListOfIntegers_CountDoesntChange()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            int expected = 4;
            int actual;

            // act
            test.ToString();
            actual = test.Count;

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void Add_AddItemsToListMoreThanCurrentCapacity_GoesToNextIndex()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(1);
            test.Add(2);
            test.Add(3);
            test.Add(4);
            int expected = 5;
            int actual;

            // act
            test.Add(5);
            actual = test[4];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void Add_AddItemsToListMoreThanCurrentCapacity_CapacityIncreases()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            int expected = 8;
            int actual;

            // act
            test.Add(4);
            actual = test.Capacity;

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void ToString_ApplyToAListOfIntegers_TurnsEachNumberToString()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            char   expected = '1';
            string returnedString;
            char   actual;

            // act
            returnedString = test.ToString();
            actual         = returnedString[1];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void Zip_TwoListsWithTwoItems_SecondItemInTheResultListShouldBeTheFirstItemInTheSecondList()
        {
            // arrange
            CustomClassList <int> test1  = new CustomClassList <int>();
            CustomClassList <int> test2  = new CustomClassList <int>();
            CustomClassList <int> result = new CustomClassList <int>();

            test1.Add(0);
            test1.Add(2);
            test2.Add(1);
            test2.Add(3);
            int expected = 1;
            int actual;

            // act
            result = test1.Zip(test2);
            actual = result[1];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void Zip_ZippingTwoListsWithTwoItems_FirstItemShouldBeFirstItemInTheFirstList()
        {
            // arrange
            CustomClassList <int> test1  = new CustomClassList <int>();
            CustomClassList <int> test2  = new CustomClassList <int>();
            CustomClassList <int> result = new CustomClassList <int>();

            test1.Add(0);
            test1.Add(2);
            test2.Add(1);
            test2.Add(3);
            int expected = 0;
            int actual;

            // act
            result = test1.Zip(test2);
            actual = result[0];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 18
0
        public void Zip_FirstListHasTwoSecondListHasThreeItems_ResultListsFourthItemShouldBeSecondListsSecondItem()
        {
            // arrange
            CustomClassList <int> test1  = new CustomClassList <int>();
            CustomClassList <int> test2  = new CustomClassList <int>();
            CustomClassList <int> result = new CustomClassList <int>();

            test1.Add(0);
            test1.Add(2);
            test2.Add(1);
            test2.Add(3);
            test2.Add(4);
            int expected = 3;
            int actual;

            // act
            result = test1.Zip(test2);
            actual = result[3];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 19
0
        public void Zip_SecondListHasMoreItems_ExtraItemsShouldBeAddedAtTheEndOfTheResultList()
        {
            // arrange
            CustomClassList <int> test1  = new CustomClassList <int>();
            CustomClassList <int> test2  = new CustomClassList <int>();
            CustomClassList <int> result = new CustomClassList <int>();

            test1.Add(0);
            test1.Add(2);
            test2.Add(1);
            test2.Add(3);
            test2.Add(5);
            test2.Add(7);
            int expected = 7;
            int actual;

            // act
            result = test1.Zip(test2);
            actual = result[5];

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 20
0
        public void Add_AddToEmptyList_ValueGoesToIndexZero()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();
            int expected = 10;
            int actual;

            // act
            test.Add(10);
            actual = test[0];

            // assert
            Assert.AreEqual(expected, actual);
        }
        public void MinusOperator_SubstractingTwoLists_ResultListShouldNotIncludeAnyItemsFromSecondList()
        {
            // arrange
            CustomClassList <int> test1     = new CustomClassList <int>();
            CustomClassList <int> test2     = new CustomClassList <int>();
            CustomClassList <int> expected1 = new CustomClassList <int>();
            CustomClassList <int> actual1   = new CustomClassList <int>();

            test1.Add(0);
            test1.Add(1);
            test1.Add(2);
            test2.Add(1);
            test2.Add(2);
            test2.Add(5);
            expected1.Add(0);
            string expected = expected1.ToString();

            // act
            actual1 = test1 - test2;
            string actual = actual1.ToString();

            // assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 22
0
        public void Iteration_AddNumbersInTheList_SumOfTheNumbers()
        {
            // arrange
            CustomClassList <int> test = new CustomClassList <int>();

            test.Add(0);
            test.Add(1);
            test.Add(2);
            test.Add(3);
            test.Add(4);
            test.Add(5);
            int expected = 15;
            int actual   = 0;

            // act
            foreach (int item in test)
            {
                actual += item;
            }

            // assert
            Assert.AreEqual(expected, actual);
        }