예제 #1
0
        public void Zip_StringListsWithUnequalCount_ResultingCountEqualsTwiceLowerCount()
        {
            //Arrange
            FakeList <string> firstFakeList = new FakeList <string>()
            {
                "a", "b", "c"
            };
            FakeList <string> secondFakeList = new FakeList <string>()
            {
                "a"
            };
            int firstListCount  = firstFakeList.Count;
            int secondListCount = secondFakeList.Count;
            int shorterListCount;

            //Act
            FakeList <string> zippedList = firstFakeList.Zip(secondFakeList);

            if (firstListCount < secondListCount)
            {
                shorterListCount = firstListCount;
            }
            else
            {
                shorterListCount = secondListCount;
            }
            int expectedZippedListCount = 2 * shorterListCount;

            //Assert
            Assert.AreEqual(expectedZippedListCount, zippedList.Count);
        }
예제 #2
0
        public void MinusOverload_IntegerToRemoveDNE_FirstListUnchanged()
        {
            //Arrange
            FakeList <int> firstFakeList = new FakeList <int>()
            {
                1, 2, 2, 3
            };
            FakeList <int> secondFakeList = new FakeList <int>()
            {
                6
            };
            bool firstFakeListUnchanged = true;

            //Act
            FakeList <int> resultingList = firstFakeList - secondFakeList;

            for (int i = 0; i < resultingList.Count; i++)
            {
                if (resultingList[i] != firstFakeList[i])
                {
                    firstFakeListUnchanged = false;
                }
            }

            Assert.IsTrue(firstFakeListUnchanged);
        }
예제 #3
0
        public FakeList <T> Zip(FakeList <T> firstAddedList, FakeList <T> secondAddedList)
        {
            int countOfShorterAddedList = (firstAddedList.Count >= secondAddedList.Count) ?
                                          secondAddedList.Count : firstAddedList.Count;
            int          countOfShortestList = (count >= countOfShorterAddedList) ? count : countOfShorterAddedList;
            int          countOfZipper       = 3 * countOfShortestList;
            FakeList <T> resultingList       = new FakeList <T>();

            for (int i = 0; i < countOfZipper; i++)
            {
                if (i % 3 == 0)
                {
                    resultingList.Add(items[i / 3]);
                }
                else if (i % 3 == 1)
                {
                    resultingList.Add(firstAddedList[(i - 1) / 3]);
                }
                else if (i % 3 == 2)
                {
                    resultingList.Add(secondAddedList[(i - 2) / 3]);
                }
            }
            return(resultingList);
        }
예제 #4
0
        public FakeList <T> Zip(FakeList <T> firstAddedList, FakeList <T> secondAddedList,
                                FakeList <T> thirdAddedList)
        {
            int countOfShortestList;

            if (count <= firstAddedList.Count && count <= secondAddedList.Count && count <= thirdAddedList.Count)
            {
                countOfShortestList = count;
            }
            else if (firstAddedList.Count <= count && firstAddedList.Count <= secondAddedList.Count &&
                     firstAddedList.Count <= thirdAddedList.Count)
            {
                countOfShortestList = firstAddedList.Count;
            }
            else if (secondAddedList.Count <= count && secondAddedList.Count <= firstAddedList.Count &&
                     secondAddedList.Count <= thirdAddedList.Count)
            {
                countOfShortestList = secondAddedList.Count;
            }
            else if (thirdAddedList.Count <= count && thirdAddedList.Count <= firstAddedList.Count &&
                     thirdAddedList.Count <= secondAddedList.Count)
            {
                countOfShortestList = thirdAddedList.Count;
            }
            else
            {
                countOfShortestList = count;
            }

            int          countOfZipper = 4 * countOfShortestList;
            FakeList <T> resultingList = new FakeList <T>();

            for (int i = 0; i < countOfZipper; i++)
            {
                if (i % 4 == 0)
                {
                    resultingList.Add(items[i / 4]);
                }
                else if (i % 4 == 1)
                {
                    resultingList.Add(firstAddedList[(i - 1) / 4]);
                }
                else if (i % 4 == 2)
                {
                    resultingList.Add(secondAddedList[(i - 2) / 4]);
                }
                else if (i % 4 == 3)
                {
                    resultingList.Add(thirdAddedList[(i - 3) / 4]);
                }
            }
            return(resultingList);
        }
예제 #5
0
        public void Add_OneIntegerAddedToEmptyList_SingleIntegerInResultingList()
        {
            //Arrange
            FakeList <int> fakelist     = new FakeList <int>();
            int            integerAdded = 1;


            //Act
            fakelist.Add(integerAdded);
            //Assert
            Assert.AreEqual(integerAdded, fakelist[0]);
        }
예제 #6
0
        public void GetItem_IndexRequestedOutOfRange_OutOfRangeException()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 2
            };

            //Act
            fakelist.GetItem(3);
            //Assert is taken care of already. Test passes if exception is thrown
        }
예제 #7
0
        public void Add_OneLetterAddedToEmptyList_SingleLetterString()
        {
            //Arrange
            FakeList <string> fakelist       = new FakeList <string>();
            string            stringAdded    = "a";
            string            expectedResult = "a";

            //Act
            fakelist.Add(stringAdded);

            //Assert
            Assert.AreEqual(expectedResult, fakelist[0]);
        }
예제 #8
0
        public void Add_IntAddedToEmptyList_CountIncreasesByOne()
        {
            //Arrange
            FakeList <int> fakelist      = new FakeList <int>();
            int            expectedCount = 1;


            //Act
            fakelist.Add(1);

            //Assert
            Assert.AreEqual(expectedCount, fakelist.Count);
        }
예제 #9
0
        public void Add_SimpleIntegerLists_InitialValueRemains()
        {
            //Arrange
            FakeList <int> fakelist           = new FakeList <int>();
            int            integerInZeroIndex = 1;
            int            integerAdded       = 2;

            //Act
            fakelist.Add(integerInZeroIndex);
            fakelist.Add(integerAdded);
            //Assert
            Assert.AreEqual(integerInZeroIndex, fakelist[0]);
        }
예제 #10
0
        public void Add_IntegerToExistingList_ExistingListThenIntegerNotSum()
        {
            //Arrange
            FakeList <int> fakelist           = new FakeList <int>();
            int            integerInZeroIndex = 1;
            int            integerAdded       = 2;

            //Act
            fakelist.Add(integerInZeroIndex);
            fakelist.Add(integerAdded);

            //Assert
            Assert.AreEqual(integerAdded, fakelist[1]);
        }
예제 #11
0
        public static FakeList <T> operator +(FakeList <T> list1, FakeList <T> list2)
        {
            FakeList <T> combinedList = new FakeList <T>();

            for (int i = 0; i < list1.Count; i++)
            {
                combinedList.Add(list1[i]);
            }
            foreach (T item in list2)
            {
                combinedList.Add(item);
            }
            return(combinedList);
        }
예제 #12
0
        public void ToString_ListOfCustomCarClassObjects_CarClassToStringTestResult()
        {
            //Arrange
            Car            car            = new Car();
            FakeList <Car> fakelist       = new FakeList <Car>();
            string         expectedString = "ConsoleApplication3.Car";

            //Act
            fakelist.Add(car);
            string resultingString = fakelist.ToString();

            //Assert
            Assert.AreEqual(resultingString, expectedString);
        }
예제 #13
0
        public void Add_ArrayOfIntegersAddedToEmptyList_AddedArray()
        {
            //Arrange
            FakeList <Array> fakelist = new FakeList <Array>();

            int[] expectedResult = new int[2] {
                1, 2
            };

            //Act
            fakelist.Add(expectedResult);

            //Assert
            Assert.AreEqual(expectedResult, fakelist[0]);
        }
예제 #14
0
        public void ToString_ListOfStrings_OneStringWithCommas()
        {
            //Arrange
            FakeList <string> fakelist = new FakeList <string>()
            {
                "a", "b", "dog"
            };
            string expectedResult = "a, b, dog";

            //Act
            string resultingString = fakelist.ToString();

            //Assert
            Assert.AreEqual(expectedResult, resultingString);
        }
예제 #15
0
        public void GetItem_ItemExistsInList_ItemInIndexReturned()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 2, 3, 4
            };
            int itemExpectedInIndexOne = 2;

            //Act
            int returnedItem = fakelist.GetItem(1);

            //Assert
            Assert.AreEqual(itemExpectedInIndexOne, returnedItem);
        }
예제 #16
0
        public void ToString_EmptyStringInList_SpaceInResultingString()
        {
            //Arrange
            FakeList <string> fakelist = new FakeList <string>()
            {
                "a", " ", "b"
            };
            string expectedResult = "a,  , b";

            //Act
            string resultingString = fakelist.ToString();

            //Assert
            Assert.AreEqual(expectedResult, resultingString);
        }
예제 #17
0
        public void ToString_ListOfIntegers_OneStringWithCommas()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 2, 3, 44
            };
            string expectedResult = "1, 2, 3, 44";

            //Act
            string resultingString = fakelist.ToString();

            //Assert
            Assert.AreEqual(expectedResult, resultingString);
        }
예제 #18
0
        public void Add_StringToExistingList_ExistingPlusNewString()
        {
            //Arrange
            FakeList <string> fakelist = new FakeList <string>();

            fakelist.Add("a");
            string stringAdded             = "b";
            string expectedValueInIndexOne = "b";

            //Act
            fakelist.Add(stringAdded);

            //Assert
            Assert.AreEqual(expectedValueInIndexOne, fakelist[1]);
        }
예제 #19
0
        public void Remove_IntegerRemovedFromList_SubsequentIndexesDecrementOne()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 2, 3, 4
            };
            int integerToRemove           = 2;
            int valueExpectedInThirdIndex = 4;

            //Act
            fakelist.Remove(integerToRemove);

            //Assert
            Assert.AreEqual(valueExpectedInThirdIndex, fakelist[2]);
        }
예제 #20
0
        public void Remove_OneItemInListRemoved_CountDecreasesByOne()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 2, 3, 4
            };
            int integerToRemove           = 2;
            int expectedCountAfterRemoval = 3;

            //Act
            fakelist.Remove(integerToRemove);

            //Assert
            Assert.AreEqual(expectedCountAfterRemoval, fakelist.Count);
        }
예제 #21
0
        public void Remove_ListContainsItemToRemove_TrueReturned()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1
            };
            int  integerRemoved = 1;
            bool expectedReturnBool;

            //Act
            expectedReturnBool = fakelist.Remove(integerRemoved);

            //Assert
            Assert.IsTrue(expectedReturnBool);
        }
예제 #22
0
        public void Add_TwoStringsAddedToListofOne_ThirdIndexHoldsSecondAddedString()
        {
            //Arrange
            FakeList <string> fakelist         = new FakeList <string>();
            string            valueInZeroIndex = "a";
            string            valueAddedSecond = "b";
            string            valueAddedThird  = "c";

            //Act
            fakelist.Add(valueInZeroIndex);
            fakelist.Add(valueAddedSecond);
            fakelist.Add(valueAddedThird);

            //Assert
            Assert.AreEqual(valueAddedThird, fakelist[2]);
        }
예제 #23
0
        public void Remove_ListWithoutItemToRemove_FalseReturned()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                2
            };
            int  integerRemoved = 2;
            bool expectedReturnBool;

            //Act
            expectedReturnBool = fakelist.Remove(integerRemoved);

            //Assert
            Assert.IsTrue(expectedReturnBool);
        }
예제 #24
0
        public void Remove_RepeatedIntegersExist_OnlyOneRemoved()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 3, 3, 4, 4
            };
            int integerToRemove           = 4;
            int expectedValueInIndexThree = 4;


            //Act
            fakelist.Remove(integerToRemove);

            //Assert
            Assert.AreEqual(expectedValueInIndexThree, fakelist[3]);
        }
예제 #25
0
        public void Remove_RepeatedIntegerRemovedFromIntList_NewListWithoutFirstInt()
        {
            //Arrange
            FakeList <int> fakelist = new FakeList <int>()
            {
                1, 2, 3, 3, 4
            };
            int integerToRemove           = 3;
            int expectedValueInIndexThree = 4;


            //Act
            fakelist.Remove(integerToRemove);

            //Assert
            Assert.AreEqual(expectedValueInIndexThree, fakelist[3]);
        }
예제 #26
0
        public void Zip_EqualCountIntegerLists_SecondListFirstIndexBecomesSecondIndexOfZipper()
        {
            //Arrange
            FakeList <int> firstFakeList  = new FakeList <int>(); //{1,2,3};
            FakeList <int> secondFakeList = new FakeList <int>(); //{4,5,6};

            //Act
            firstFakeList.Add(1);
            firstFakeList.Add(2);
            firstFakeList.Add(3);
            secondFakeList.Add(4);
            secondFakeList.Add(5);
            secondFakeList.Add(6);
            FakeList <int> zippedList = firstFakeList.Zip(secondFakeList);

            //Assert
            Assert.AreEqual(secondFakeList[0], zippedList[1]);
        }
예제 #27
0
        public void Add_TwoIntegerArraysAddedToEmptyList_ArraysNotCombined()
        {
            //Arrange
            FakeList <Array> fakelist = new FakeList <Array>();

            int[] firstArrayAdded = new int[2] {
                1, 2
            };
            int[] secondArrayAdded = new int[2] {
                3, 4
            };

            //Act
            fakelist.Add(firstArrayAdded);
            fakelist.Add(secondArrayAdded);
            //Assert
            Assert.AreEqual(secondArrayAdded, fakelist[1]);
        }
예제 #28
0
        public FakeList <T> Zip(FakeList <T> listToZipWith)
        {
            int          countOfShorterList = (count >= listToZipWith.Count) ? listToZipWith.count : count;
            int          countOfZipper      = 2 * countOfShorterList;
            FakeList <T> resultingList      = new FakeList <T>();

            for (int i = 0; i < countOfZipper; i++)
            {
                if (i % 2 == 0)
                {
                    resultingList.Add(items[i / 2]);
                }
                else
                {
                    resultingList.Add(listToZipWith[(i - 1) / 2]);
                }
            }
            return(resultingList);
        }
예제 #29
0
        [TestMethod]//To show {1,2,3}.Zip({4,5}) --> {1,4,2,5}
        public void Zip_SecondIntegerListCountLower_FirstListLosesItems()
        {
            //Arrange
            FakeList <int> firstFakeList = new FakeList <int>()
            {
                1, 2, 3
            };
            FakeList <int> secondFakeList = new FakeList <int>()
            {
                4, 5
            };
            int expectedZippedListCount = 4;

            //Act
            FakeList <int> zippedList = firstFakeList.Zip(secondFakeList);

            //Assert
            Assert.AreEqual(expectedZippedListCount, zippedList.Count);
        }
예제 #30
0
        public void MinusOverLoad_RepeatedIntegerInListSubtracted_SecondInstanceRemains()
        {
            //Arrange
            FakeList <int> firstFakeList = new FakeList <int>()
            {
                1, 2, 2, 3
            };
            FakeList <int> secondFakeList = new FakeList <int>()
            {
                2
            };
            int valueExpectedSecondIndex = 2;

            //Act
            FakeList <int> resultingFakeList = firstFakeList - secondFakeList;

            //Assert
            Assert.AreEqual(valueExpectedSecondIndex, resultingFakeList[1]);
        }