示例#1
0
        public void DeleteFirst_Add3Delete1_Count2()
        {
            // Arrange
            LinkList <Person> list     = new LinkList <Person>();
            Student           student1 = new Student("ИмяСтудента1", 25, 2);
            Student           student2 = new Student("ИмяСтудента2", 26, 3);
            Student           student3 = new Student("ИмяСтудента3", 27, 4);

            // Act
            list.InsertFirst(student1);
            list.Add(student2);
            list.Insert(1, student3);
            list.DeleteFirst();

            int expectedCount = 2;
            int actualCount   = list.Count;

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
            Assert.AreEqual(list[0], student3);
            Assert.AreEqual(list[1], student2);
        }
示例#2
0
        public static void LinkListTest() //test
        {
            LinkList <int> myList = new LinkList <int>();

            Console.WriteLine("LinkList test:");
            for (int i = 0; i < N; i++)
            {
                myList.Add(i);
            }
            Console.Write("List: "); ListWrite(myList);

            myList.Reverse();
            Console.Write("Reverse(): "); ListWrite(myList);

            myList.Reverse();
            Console.Write("Reverse(): "); ListWrite(myList);

            int pos = 6, data = 21;

            myList.Insert(pos, data);
            Console.Write("Insert(pos(" + pos + "), data(" + data + ")): "); ListWrite(myList);

            pos = 4;
            myList.Remove(pos);
            Console.Write("Remove(pos(" + pos + ")): "); ListWrite(myList);

            myList.RemoveFirst();
            Console.Write("RemoveFirst(): "); ListWrite(myList);

            myList.RemoveLast();
            Console.Write("RemoveLast(): "); ListWrite(myList);

            data = 277;
            myList.AddFirst(data);
            Console.Write("AddFirst(" + data + "): "); ListWrite(myList);
        }
示例#3
0
        public void Find_ListWith6Items_Count3()
        {
            // Arrange
            LinkList <Person> list    = new LinkList <Person>();
            Student           student = new Student("ИмяСтудента1", 25, 2);

            list.Add(Student.GeneratePupil());
            list.Add(student);
            list.Add(student);
            list.Add(Student.GeneratePupil());
            list.Add(student);
            list.Add(Student.GeneratePupil());

            // Act
            Person expectedStudent = list.Find(student);

            // Assert
            Assert.AreEqual(expectedStudent, student);
        }
示例#4
0
        public void DeleteAll_ListWith6Items_Count3()
        {
            // Arrange
            LinkList <Person> list    = new LinkList <Person>();
            Student           student = new Student("ИмяСтудента1", 25, 2);

            list.Add(Student.GeneratePupil());
            list.Add(student);
            list.Add(student);
            list.Add(Student.GeneratePupil());
            list.Add(student);
            list.Add(Student.GeneratePupil());

            // Act
            list.DeleteAll(student);

            int expectedCount = 3;
            int actualCount   = list.Count;

            // Assert
            Assert.AreEqual(expectedCount, actualCount);
        }