public void CheckIfFirstArgumentsWorksCorrectly1()
        {
            DataStructures.ListCollection <string> array = new DataStructures.ListCollection <string>();
            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;

            Assert.Throws <InvalidOperationException>(() => DataStructures.LinqFunctions.First <string>(array, isUpperCase) == "Ana");
        }
        public void CheckIfAnyArgumentsWorksCorrectly()
        {
            DataStructures.ListCollection <string> array = null;
            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;

            Assert.Throws <ArgumentNullException>(() => DataStructures.LinqFunctions.Any <string>(array, isUpperCase));
        }
        public void CheckIfInsertIndexExceptionWorks2()
        {
            var array = new DataStructures.ListCollection <int> {
                0, 1, 2, 3
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => array.Insert(8, 5));
        }
        public void CheckIfIEnumWorksCorrectly()
        {
            var array = new DataStructures.ListCollection <int> {
                0, 1, 2, 3
            };

            Assert.Equal(0, array[0]);
        }
        public void CheckIfRemoveAtReadonlyExceptionWorks()
        {
            var array = new DataStructures.ListCollection <int> {
                0, 1, 2, 3
            };

            array.MakeReadOnly();
            Assert.Throws <NotSupportedException>(() => array.RemoveAt(2));
        }
        public void CheckIfAddWorksCorrectly()
        {
            var array = new DataStructures.ListCollection <int> {
                0, 1, 2, 3
            };

            array.Add(4);
            Assert.Equal(4, array[4]);
        }
        public void CheckIfCopyToOutOfExceptionWorks()
        {
            var array = new DataStructures.ListCollection <int> {
                0, 1, 2, 3
            };

            int[] copyArray = { 5, 2, 1 };
            Assert.Throws <ArgumentOutOfRangeException>(() => array.CopyTo(copyArray, -3));
        }
        public void CheckIfFirstWorksCorrectly2()
        {
            DataStructures.ListCollection <string> array = new DataStructures.ListCollection <string>();
            array.Add("ana");
            array.Add("Paul");
            array.Add("zero");
            array.Add("penelope");
            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;

            Assert.True(DataStructures.LinqFunctions.First <string>(array, isUpperCase) == "Paul");
        }
        public void CheckIfAllWorksCorrectly1()
        {
            DataStructures.ListCollection <string> array = new DataStructures.ListCollection <string>();
            array.Add("Ana");
            array.Add("Paul");
            array.Add("zero");
            array.Add("Penelope");
            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;

            Assert.False(DataStructures.LinqFunctions.All <string>(array, isUpperCase));
        }
        public void CheckIfWhereArgumentsWorksCorrectly1()
        {
            DataStructures.ListCollection <string> array = null;
            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;
            List <string>       list        = new List <string>();

            list.Add("Paul");
            Func <string, bool> isFirstUpperCase = x => (x[0] >= 65 && x[0] <= 90);

            Assert.Throws <ArgumentNullException>(() => DataStructures.LinqFunctions.All <string>(DataStructures.LinqFunctions.Where <string>(array, isUpperCase), isFirstUpperCase));
        }
        public void CheckIfWhereWorksCorrectly2()
        {
            DataStructures.ListCollection <string> array = new DataStructures.ListCollection <string>();
            array.Add("ana");
            array.Add("paul");
            array.Add("zero");
            array.Add("penelope");
            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;
            List <string>       list        = new List <string>();

            Assert.Equal(DataStructures.LinqFunctions.Where <string>(array, isUpperCase), list);
        }
        public void CheckIfSelectManyWorksCorrectly()
        {
            DataStructures.ListCollection <List <string> > array = new DataStructures.ListCollection <List <string> >();
            array.Add(new List <string> {
                "Ana", "alex", "Andrei"
            });
            array.Add(new List <string> {
                "Paul", "paula", "Pelena", "penelope"
            });
            array.Add(new List <string> {
                "zero", "Zen", "zohan"
            });
            Func <List <string>, List <List <string> > > makeUpperCaseFirstAndAll = x =>
            {
                List <List <string> > returnList = new List <List <string> >();
                foreach (var obj in x)
                {
                    string first = obj;
                    if (obj[0] >= 97 && obj[0] <= 122)
                    {
                        first = obj[0].ToString().ToUpper() + obj.Substring(1, obj.Length - 1);
                    }

                    string all = obj.ToUpper();
                    returnList.Add(new List <string> {
                        first, all
                    });
                }

                return(returnList);
            };

            Func <List <string>, bool> isFirstUpperCase = x =>
            {
                foreach (var obj in x)
                {
                    if (!(obj[0] >= 65 && obj[0] <= 90))
                    {
                        return(false);
                    }
                }

                return(true);
            };

            Assert.True(DataStructures.LinqFunctions.All(DataStructures.LinqFunctions.SelectMany <List <string>, List <string> >(array, makeUpperCaseFirstAndAll), isFirstUpperCase));
        }
        public void CheckIfSelectArgumentsWorksCorrectly()
        {
            DataStructures.ListCollection <string> array = null;
            Func <string, string> makeUpperCase          = x =>
            {
                string y = x;
                if (x[0] >= 97 && x[0] <= 122)
                {
                    y = x[0].ToString().ToUpper() + x.Substring(1, x.Length - 1);
                }

                return(y);
            };

            Func <string, bool> isUpperCase = x => x[0] >= 65 && x[0] <= 90;

            Assert.Throws <ArgumentNullException>(() => DataStructures.LinqFunctions.All(DataStructures.LinqFunctions.Select(array, makeUpperCase), isUpperCase));
        }
        public void CheckIfSelectManyArgumentsWorksCorrectly()
        {
            DataStructures.ListCollection <List <string> > array = null;
            Func <List <string>, List <List <string> > >   makeUpperCaseFirstAndAll = x =>
            {
                List <List <string> > returnList = new List <List <string> >();
                foreach (var obj in x)
                {
                    string first = obj;
                    if (obj[0] >= 97 && obj[0] <= 122)
                    {
                        first = obj[0].ToString().ToUpper() + obj.Substring(1, obj.Length - 1);
                    }

                    string all = obj.ToUpper();
                    returnList.Add(new List <string> {
                        first, all
                    });
                }

                return(returnList);
            };

            Func <List <string>, bool> isFirstUpperCase = x =>
            {
                foreach (var obj in x)
                {
                    if (!(obj[0] >= 65 && obj[0] <= 90))
                    {
                        return(false);
                    }
                }

                return(true);
            };

            Assert.Throws <ArgumentNullException>(() => DataStructures.LinqFunctions.All(
                                                      DataStructures.LinqFunctions.SelectMany <List <string>, List <string> >(array, makeUpperCaseFirstAndAll), isFirstUpperCase));
        }
        public void CheckIfSelectWorksCorrectly2()
        {
            DataStructures.ListCollection <string> array = new DataStructures.ListCollection <string>();
            array.Add("ana");
            array.Add("paul");
            array.Add("zero");
            array.Add("penelope");
            Func <string, string> makeUpperCase = x =>
            {
                string y = x;
                if (x[0] >= 97 && x[0] <= 122)
                {
                    y = x[0].ToString().ToUpper() + x.Substring(1, x.Length - 1);
                }

                return(y);
            };

            Func <string, bool> isLowerCase = x => x[0] >= 97 && x[0] <= 122;

            Assert.False(DataStructures.LinqFunctions.Any(DataStructures.LinqFunctions.Select(array, makeUpperCase), isLowerCase));
        }
        public void CheckIfGroupByWorksCorrectly()
        {
            Person magnus = new Person {
                Name = "Magnus"
            };
            Person terry = new Person {
                Name = "Terry"
            };
            Person charlotte = new Person {
                Name = "Charlotte"
            };
            List <Pet> pets = new List <Pet>
            {
                new Pet {
                    Name = "Barley", Owner = magnus
                },
                new Pet {
                    Name = "Maddison", Owner = terry
                },
                new Pet {
                    Name = "Pudding", Owner = charlotte
                },
                new Pet {
                    Name = "Apple", Owner = magnus
                },
                new Pet {
                    Name = "Ketchup", Owner = terry
                },
                new Pet {
                    Name = "Rufus", Owner = charlotte
                },
                new Pet {
                    Name = "Donut", Owner = magnus
                },
                new Pet {
                    Name = "Roger", Owner = terry
                },
                new Pet {
                    Name = "Kitten", Owner = charlotte
                }
            };
            Func <Pet, Person> ownerSelector = x => x.Owner;
            Func <Pet, string> nameSelector  = x => x.Name;
            Func <Person, IEnumerable <string>, DataStructures.Grouping <Person, string> > resultSelector = (x, y) => new DataStructures.Grouping <Person, string>(x, y);

            DataStructures.ListCollection <DataStructures.Grouping <Person, string> > finalGroups = new DataStructures.ListCollection <DataStructures.Grouping <Person, string> >
            {
                new DataStructures.Grouping <Person, string>(magnus, new DataStructures.ListCollection <string> {
                    "Barley", "Apple", "Donut"
                }),
                new DataStructures.Grouping <Person, string>(terry, new DataStructures.ListCollection <string> {
                    "Maddison", "Ketchup", "Roger"
                }),
                new DataStructures.Grouping <Person, string>(charlotte, new DataStructures.ListCollection <string> {
                    "Pudding", "Rufus", "Kitten"
                })
            };

            PersonEqualityComparer comparer = new PersonEqualityComparer();

            Assert.Equal(
                finalGroups,
                DataStructures.LinqFunctions.GroupBy <Pet, Person, string, DataStructures.Grouping <Person, string> >(pets, ownerSelector, nameSelector, resultSelector, comparer));
        }