public void T10_RemoveItem_WhichIsDuplicateInList()
        {
            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(pupil3);
            Assert.IsTrue(list.Remove(pupil3), "Should return true");
            Assert.AreEqual(4, list.Count, "Count should be reduced by 1");
            Assert.AreEqual(pupil3, list.GetAt(3), "Second occurence of pupil3 should not be deleted");
        }
示例#2
0
        public Pupil FindPupil(string firstName, string lastName)
        {
            Pupil pupil = new Pupil();

            pupil = PupilList.Find(p => (p.FirstName == firstName) && (p.LastName == lastName));
            return(pupil);
        }
        public void T08_RemoveItem_WhichIsNotInList()
        {
            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);
            Assert.AreEqual(4, list.Count, "Count not working properly");
            Assert.IsFalse(list.Remove(pupil5), "Remove should return false");
            Assert.AreEqual(4, list.Count, "Count should not be reduced, when no object is removed");
        }
        public void T12_Insert()
        {
            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.Insert(0, pupil1);
            Assert.AreEqual(pupil1, list.GetAt(0), "pupil1 should be on first position");

            list.Insert(1, pupil2);
            Assert.AreEqual(pupil2, list.GetAt(1), "pupil2 should be on second position");

            list.Insert(1, pupil3);
            Assert.AreEqual(pupil1, list.GetAt(0), "pupil1 should be on first position");
            Assert.AreEqual(pupil3, list.GetAt(1), "pupil3 should be on second position");
            Assert.AreEqual(pupil2, list.GetAt(2), "pupil2 should be on third position");
        }
        public void T09_RemoveItem_WhichIsInList()
        {
            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);
            Assert.IsTrue(list.Remove(pupil3), "Should return true");
            Assert.AreEqual(3, list.Count, "Count should be reduced");
        }
        public void T02_AddItems_TestCount()
        {
            PupilList list = new PupilList();

            list.Add(new Pupil());
            Assert.AreEqual(1, list.Count, "Count should return 1 after first add");
            list.Add(new Pupil());
            Assert.AreEqual(2, list.Count, "Count should return 2 after second add");
        }
        public void T03_InsertItems_TestCount()
        {
            PupilList list = new PupilList();

            list.Insert(0, new Pupil());
            Assert.AreEqual(1, list.Count, "Count should return 1 after first insert");
            list.Insert(0, new Pupil());
            Assert.AreEqual(2, list.Count, "Count should return 2 after second insert");
            list.Insert(1, new Pupil());
            Assert.AreEqual(3, list.Count, "Count should return 3 after third insert");
        }
        public void T11_RemoveAt()
        {
            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.RemoveAt(2);
            Assert.AreEqual(3, list.Count, "Count should be reduced");

            Assert.AreEqual(pupil1, list.GetAt(0), "pupil1 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");

            list.RemoveAt(2);
            Assert.AreEqual(2, list.Count, "Count should be reduced");
            Assert.AreEqual(pupil1, list.GetAt(0), "pupil1 should be on first position");
            Assert.AreEqual(pupil2, list.GetAt(1), "pupil2 should be on second position");

            list.RemoveAt(0);
            Assert.AreEqual(1, list.Count, "Count should be reduced");
            Assert.AreEqual(pupil2, list.GetAt(0), "pupil2 should be on first position");

            list.RemoveAt(0);
            Assert.AreEqual(0, list.Count, "Count should be reduced");

            list.Add(pupil4);
            Assert.AreEqual(pupil4, list.GetAt(0), "pupil4 should be on first position");
        }
        public void T04_AddItems_TestGetAt()
        {
            Pupil     item1 = new Pupil();
            Pupil     item2 = new Pupil();
            Pupil     item3 = new Pupil();
            PupilList list  = new PupilList();

            list.Add(item1);
            Assert.AreEqual(1, list.Count, "Count should return 1 after first add");
            list.Add(item2);
            Assert.AreEqual(2, list.Count, "Count should return 2 after second add");
            list.Add(item3);
            Assert.AreEqual(3, list.Count, "Count should return 3 after thirs add");
            Assert.AreEqual(item1, list.GetAt(0), "GetAt(0) should return Item1");
        }
示例#10
0
 public Pupil AddPupil(string firstName, string lastName)
 {
     if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName) ||
         firstName.Length < 2 || lastName.Length < 2 ||
         PupilList.Exists(c => (c.FirstName == firstName) && (c.LastName == lastName)))
     {
         throw new ArgumentException();
     }
     else
     {
         Pupil pupil = new Pupil(firstName, lastName);
         pupil.Classroom = this;
         PupilList.Add(pupil);
         return(pupil);
     }
 }
示例#11
0
        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");
        }
        public void T01_CreateEmptyList_CountShouldReturn0()
        {
            PupilList list = new PupilList();

            Assert.AreEqual(0, list.Count);
        }