private static void Main(string[] args) { string headLine = $"{"KatNr",5} | {"Vorname",-20} | {"Nachname",-20} | {"Alter",5}"; Console.WriteLine("Dynamische Schülerliste"); for (int k = 0; k < headLine.Length; k++) { Console.Write("="); } Console.WriteLine(); //Testdaten PupilList pupils = new PupilList(); Pupil pupil1 = new Pupil(1, "Simon", "P", 17); pupils.Add(pupil1); Pupil pupil2 = new Pupil(2, "Anna", "Lutz", 16); Pupil pupil3 = new Pupil(3, "Fritz", "Auer", 15); Pupil pupil4 = new Pupil(6, "Hans", "Huber", 14); Pupil pupil5 = new Pupil(5, "Moritz", "Maier", 13); pupils.Add(pupil2); pupils.Remove(pupil1); pupils.Add(pupil5); pupils.Insert(1, pupil4); pupils.GetAt(1); pupils.Sort(); pupils.Add(pupil3); Console.WriteLine(headLine); for (int k = 0; k < headLine.Length; k++) { Console.Write("="); } Console.WriteLine(); for (int i = 0; i < pupils.Count; i++) { Console.WriteLine($"{pupils.GetAt(i).CatalogNumber,5} | {pupils.GetAt(i).FirstName,-20} | {pupils.GetAt(i).LastName,-20} | {pupils.GetAt(i).Age,5}"); } }
public void T05_SortItems() { Pupil pupil1 = new Pupil() { Age = 10 }; Pupil pupil2 = new Pupil() { Age = 7 }; Pupil pupil3 = new Pupil() { Age = 1 }; Pupil pupil4 = new Pupil() { Age = 8 }; Pupil pupil5 = new Pupil() { Age = 11 }; PupilList list = new PupilList(); list.Add(pupil1); list.Add(pupil2); list.Add(pupil3); list.Add(pupil4); list.Add(pupil5); list.Sort(); Assert.AreEqual(pupil3, list.GetAt(0), "pupil3 should be on first position"); Assert.AreEqual(pupil2, list.GetAt(1), "pupil2 should be on second position"); Assert.AreEqual(pupil4, list.GetAt(2), "pupil4 should be on third position"); Assert.AreEqual(pupil1, list.GetAt(3), "pupil1 should be on fourth position"); Assert.AreEqual(pupil5, list.GetAt(4), "pupil5 should be on fifth position"); }