public void SortCorrelatedLists_With_Jagged_Correlated_Lists_Throws_Exception()
        {
            var ex = Assert.Throws <IndexOutOfRangeException>(() =>
            {
                IList <string> listToSort = new List <string>()
                {
                    "2", "4", "1", "3"
                };

                IList <IList <string> > correlatedLists = new List <IList <string> >();
                List <string> list1 = new List <string>()
                {
                    "One", "Two"
                };
                List <string> list2 = new List <string>()
                {
                    "Four", "One", "Two", "Three", "Foo"
                };
                List <string> list3 = new List <string>()
                {
                    "Three", "Four", "One", "Two"
                };
                correlatedLists.Add(list1);
                correlatedLists.Add(list2);
                correlatedLists.Add(list3);

                ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists, sortAscending: true);
            });

            Assert.That(ex.Message, Is.EqualTo("Method cannot correlate sorting of jagged lists! \r\nMake sure all lists provided are of equal length to each other and the primary list being sorted."));
        }
        public void SortCorrelatedLists_With_All_Lists_Empty_Returns_All_Empty()
        {
            IList <string>          listToSort      = new List <string>();
            IList <IList <string> > correlatedLists = new List <IList <string> >();

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists);

            Assert.IsEmpty(listToSort);
            Assert.IsEmpty(correlatedLists);
        }
        public void SortCorrelatedLists_With_All_Lists_Null_Returns_All_Null()
        {
            IList <string>          listToSort      = null;
            IList <IList <string> > correlatedLists = null;

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists);

            Assert.IsNull(listToSort);
            Assert.IsNull(correlatedLists);
        }
        public void SortCorrelatedLists_With_CorrelatedLists_Null_Sorts_List_Returns_Null_CorrelatedLists()
        {
            IList <string> listToSort = new List <string>()
            {
                "2", "4", "1", "3"
            };
            IList <IList <string> > correlatedLists = null;

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists);

            Assert.IsNull(correlatedLists);
            Assert.AreEqual("1", listToSort[0]);
            Assert.AreEqual("2", listToSort[1]);
            Assert.AreEqual("3", listToSort[2]);
            Assert.AreEqual("4", listToSort[3]);
        }
        public void SortCorrelatedLists_With_Correlated_Lists_Containing_Different_List_Types()
        {
            IList <string> listToSort = new List <string>()
            {
                "2", "4", "1", "3"
            };

            IList <IList <string> > correlatedLists = new List <IList <string> >();
            List <string>           list1           = new List <string>()
            {
                "One", "Two", "Three", "Four"
            };
            Collection <string> list2 = new Collection <string>()
            {
                "Four", "One", "Two", "Three"
            };
            ObservableCollection <string> list3 = new ObservableCollection <string>()
            {
                "Three", "Four", "One", "Two"
            };

            correlatedLists.Add(list1);
            correlatedLists.Add(list2);
            correlatedLists.Add(list3);

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists);

            Assert.AreEqual("1", listToSort[0]);
            Assert.AreEqual("2", listToSort[1]);
            Assert.AreEqual("3", listToSort[2]);
            Assert.AreEqual("4", listToSort[3]);

            Assert.AreEqual(list1[2], correlatedLists[0][0]);
            Assert.AreEqual(list1[0], correlatedLists[0][1]);
            Assert.AreEqual(list1[3], correlatedLists[0][2]);
            Assert.AreEqual(list1[1], correlatedLists[0][3]);

            Assert.AreEqual(list2[2], correlatedLists[1][0]);
            Assert.AreEqual(list2[0], correlatedLists[1][1]);
            Assert.AreEqual(list2[3], correlatedLists[1][2]);
            Assert.AreEqual(list2[1], correlatedLists[1][3]);

            Assert.AreEqual(list3[2], correlatedLists[2][0]);
            Assert.AreEqual(list3[0], correlatedLists[2][1]);
            Assert.AreEqual(list3[3], correlatedLists[2][2]);
            Assert.AreEqual(list3[1], correlatedLists[2][3]);
        }
        public void SortCorrelatedLists_Sorts_Descending()
        {
            IList <string> listToSort = new List <string>()
            {
                "2", "4", "1", "3"
            };

            IList <IList <string> > correlatedLists = new List <IList <string> >();
            List <string>           list1           = new List <string>()
            {
                "One", "Two", "Three", "Four"
            };
            List <string> list2 = new List <string>()
            {
                "Four", "One", "Two", "Three"
            };
            List <string> list3 = new List <string>()
            {
                "Three", "Four", "One", "Two"
            };

            correlatedLists.Add(list1);
            correlatedLists.Add(list2);
            correlatedLists.Add(list3);

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists, sortAscending: false);

            Assert.AreEqual("4", listToSort[0]);
            Assert.AreEqual("3", listToSort[1]);
            Assert.AreEqual("2", listToSort[2]);
            Assert.AreEqual("1", listToSort[3]);

            Assert.AreEqual(list1[1], correlatedLists[0][0]);
            Assert.AreEqual(list1[3], correlatedLists[0][1]);
            Assert.AreEqual(list1[0], correlatedLists[0][2]);
            Assert.AreEqual(list1[2], correlatedLists[0][3]);

            Assert.AreEqual(list2[1], correlatedLists[1][0]);
            Assert.AreEqual(list2[3], correlatedLists[1][1]);
            Assert.AreEqual(list2[0], correlatedLists[1][2]);
            Assert.AreEqual(list2[2], correlatedLists[1][3]);

            Assert.AreEqual(list3[1], correlatedLists[2][0]);
            Assert.AreEqual(list3[3], correlatedLists[2][1]);
            Assert.AreEqual(list3[0], correlatedLists[2][2]);
            Assert.AreEqual(list3[2], correlatedLists[2][3]);
        }
        public void SortCorrelatedLists_With_Correlated_Lists_Containing_Empty_Sorts_Lists_Setting_Null_Lists_To_Empty()
        {
            IList <string> listToSort = new List <string>()
            {
                "2", "4", "1", "3"
            };

            IList <IList <string> > correlatedLists = new List <IList <string> >();
            List <string>           list1           = new List <string>()
            {
                "One", "Two", "Three", "Four"
            };
            List <string> list2 = new List <string>();
            List <string> list3 = new List <string>()
            {
                "Three", "Four", "One", "Two"
            };

            correlatedLists.Add(list1);
            correlatedLists.Add(list2);
            correlatedLists.Add(list3);

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists);

            Assert.AreEqual("1", listToSort[0]);
            Assert.AreEqual("2", listToSort[1]);
            Assert.AreEqual("3", listToSort[2]);
            Assert.AreEqual("4", listToSort[3]);

            Assert.AreEqual(list1[2], correlatedLists[0][0]);
            Assert.AreEqual(list1[0], correlatedLists[0][1]);
            Assert.AreEqual(list1[3], correlatedLists[0][2]);
            Assert.AreEqual(list1[1], correlatedLists[0][3]);

            Assert.IsEmpty(correlatedLists[1]);

            Assert.AreEqual(list3[2], correlatedLists[2][0]);
            Assert.AreEqual(list3[0], correlatedLists[2][1]);
            Assert.AreEqual(list3[3], correlatedLists[2][2]);
            Assert.AreEqual(list3[1], correlatedLists[2][3]);
        }
        public void SortCorrelatedLists_With_ListToSort_Empty_Returns_Lists_As_Is()
        {
            IList <string> listToSort = new List <string>();

            IList <IList <string> > correlatedLists = new List <IList <string> >();
            List <string>           list1           = new List <string>()
            {
                "One", "Two", "Three", "Four"
            };
            List <string> list2 = new List <string>()
            {
                "Four", "One", "Two", "Three"
            };
            List <string> list3 = new List <string>()
            {
                "Three", "Four", "One", "Two"
            };

            correlatedLists.Add(list1);
            correlatedLists.Add(list2);
            correlatedLists.Add(list3);

            ListLibrary.SortCorrelatedLists(ref listToSort, ref correlatedLists);

            Assert.IsEmpty(listToSort);

            Assert.AreEqual(list1[0], correlatedLists[0][0]);
            Assert.AreEqual(list1[1], correlatedLists[0][1]);
            Assert.AreEqual(list1[2], correlatedLists[0][2]);
            Assert.AreEqual(list1[3], correlatedLists[0][3]);

            Assert.AreEqual(list2[0], correlatedLists[1][0]);
            Assert.AreEqual(list2[1], correlatedLists[1][1]);
            Assert.AreEqual(list2[2], correlatedLists[1][2]);
            Assert.AreEqual(list2[3], correlatedLists[1][3]);

            Assert.AreEqual(list3[0], correlatedLists[2][0]);
            Assert.AreEqual(list3[1], correlatedLists[2][1]);
            Assert.AreEqual(list3[2], correlatedLists[2][2]);
            Assert.AreEqual(list3[3], correlatedLists[2][3]);
        }