public void T05_SortItems()
        {
            Pet pet1 = new Pet()
            {
                Age = 10
            };
            Pet pet2 = new Pet()
            {
                Age = 7
            };
            Pet pet3 = new Pet()
            {
                Age = 1
            };
            Pet pet4 = new Pet()
            {
                Age = 8
            };
            Pet pet5 = new Pet()
            {
                Age = 11
            };
            SortableArrayList list = new SortableArrayList();

            list.Add(pet1);
            list.Add(pet2);
            list.Add(pet3);
            list.Add(pet4);
            list.Add(pet5);
            list.Sort();
            Assert.AreEqual(pet3, list[0], "pet3 should be on first position");
            Assert.AreEqual(pet2, list[1], "pet2 should be on second position");
            Assert.AreEqual(pet4, list[2], "pet4 should be on third position");
            Assert.AreEqual(pet1, list[3], "pet1 should be on fourth position");
            Assert.AreEqual(pet5, list[4], "pet5 should be on fifth position");
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            SortableArrayList myPupilList = new SortableArrayList();
            Pupil             p1          = new Pupil();

            p1.LastName  = "Maier";
            p1.FirstName = "Franz";
            p1.BirthDate = new DateTime(1993, 3, 30);
            Pupil p2 = new Pupil();

            p2.LastName  = "Allinger";
            p2.FirstName = "Franziska";
            p2.BirthDate = new DateTime(1990, 5, 6);
            Pupil p3 = new Pupil();

            p3.LastName  = "Ehrmann";
            p3.FirstName = "Heide";
            p3.BirthDate = new DateTime(1920, 8, 8);

            myPupilList.Add(p1);
            myPupilList.Add(p2);
            myPupilList.Add(p3);

            Console.WriteLine("===========Schüler Unsortiert=======================");
            for (int i = 0; i < myPupilList.Count(); i++)
            {
                Console.WriteLine($"{(myPupilList[i] as Pupil).FirstName} {(myPupilList[i] as Pupil).LastName}");
            }

            myPupilList.Sort();
            Console.WriteLine("===========Schüler Sortierte Ausgabe================");
            for (int i = 0; i < myPupilList.Count(); i++)
            {
                Console.WriteLine($"{(myPupilList[i] as Pupil).FirstName} {(myPupilList[i] as Pupil).LastName}");
            }
        }