Beispiel #1
0
        static void Main()
        {
            var intList = new GenericList<int>();

            intList.AddRange(Enumerable.Range(1, 30).ToArray());

            Console.WriteLine("Number of elements: {0}", intList.Count);
            Console.WriteLine(intList);

            Console.WriteLine($"List contains 7: {intList.Contains(7)}");
            Console.WriteLine($"Index of 12: {intList.IndexOf(12)}");

            Console.WriteLine();

            var stringList = new GenericList<string>
            {
                "C#",
                "Java",
                "PHP",
                "SQL"
            };

            Console.WriteLine($"Number of elements: {stringList.Count}");
            Console.WriteLine(stringList);

            Console.WriteLine($"List contains \"Java\": {stringList.Contains("Java")}");
        }
        public void IndexOf_ListHasItemFromIndexUpToCount()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            Assert.AreEqual(4, myList.IndexOf(5, 2, 3));
        }
        public void Contains_TestListContainsItem()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            Assert.AreEqual(true, myList.Contains(2));
        }
        public void IndexOf_TestIndexOutOfRange()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            myList.IndexOf(2, 10);
        }
        public void IndexOf_ListDoesNotHaveItemFromIndex()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });

            Assert.AreEqual(-1, myList.IndexOf(10, 2));
        }
        public void IndexOf_ListHasItemAtEnd()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });

            Assert.AreEqual(5, myList.IndexOf(6));
        }
        public void Contains_TestListDoesNotContainItem()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });

            Assert.AreEqual(false, myList.Contains(10));
        }
        public void IndexOf_CountExceedsListCount_ExpectIndexOutOfRange()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });

            myList.IndexOf(7, 0, 10);
        }
        public void GetRange_TestGetRangeStartingIndex()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            GenericList <int> result = myList.GetRange(1);

            Assert.AreEqual("23456", result.ToString());
        }
        public void GetRange_TestGetRangeCountExceedsListCount()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            GenericList <int> result = myList.GetRange(3, 8);

            Assert.AreEqual("456", result.ToString());
        }
        public void RemoveRange_TestRemoveRangeExceedsListCount()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            myList.RemoveRange(1, 8);

            Assert.AreEqual("1", myList.ToString());
        }
        public void RemoveRange_TestRemoveRangeAllItems()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            myList.RemoveRange(0, 6);

            Assert.AreEqual("", myList.ToString());
        }
        public void Reverse_TestReversListStringEqual()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            myList.Reverse();

            Assert.AreEqual("654321", myList.ToString());
        }
        public void Reverse_TestReversList()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });
            myList.Reverse();

            Assert.AreEqual(5, myList[1]);
        }
        public void GetRange_TestGetRangeThreeItems()
        {
            GenericList <int> myList = new GenericList <int>();

            myList.AddRange(new List <int> {
                1, 2, 3, 4, 5, 6
            });

            GenericList <int> result = myList.GetRange(1, 3);

            Assert.AreEqual("234", result.ToString());
        }
Beispiel #16
0
 public IDeck Build()
 {
     var cards = new GenericList<ICard>();
     if (_numberOfDecks <= 0)
         throw new ArgumentOutOfRangeException("Number of decks must be a positive number!");
     else
         for (; _numberOfDecks > 0; _numberOfDecks--)
         {
             cards.AddRange(GetSingleDeck());
         }
     return new Deck(cards);
 }