public void Test_AddStudents()
        {
            StudentCollection sc = new StudentCollection();

            sc.AddStudents(new Student());
            Console.WriteLine(sc.ToShortString());
        }
        public void Test_MaxAGP()
        {
            StudentCollection sc = new StudentCollection();

            Student[] st_add = new Student[5];
            //Random rand = new Random();

            for (int i = 0; i < 5; i++)
            {
                //int grade = rand.Next(1, 6); // 1 is inclusive, 6 is exclusive - grade [1,5]
                Student tmp_student = new Student(new Person("John " + i, "Smith " + i, new DateTime()), Education.Bachelor, 121);
                tmp_student.AddExams(new Exam("Some Exam", i, new DateTime()));
                st_add[i] = tmp_student;
                //st_add[i] = new Student(new Person("John", "Smith", new DateTime()), Education.Bachelor, 112);
            }

            sc.AddStudents(st_add);

            double test_max_agp = (5.0 + 5.0 + 4.0) / 3.0;

            Console.WriteLine(sc.ToShortString());
            Console.WriteLine(sc.MaxAGP);

            Assert.AreEqual(test_max_agp, sc.MaxAGP);
        }
        public void Test_SortByBirthDate()
        {
            StudentCollection sc = new StudentCollection();

            Student[] st_add = new Student[5];
            Random    rand   = new Random();

            for (int i = 0; i < 5; i++)
            {
                int day_int = rand.Next(1, 29); // 1 is inclusive, 29 is exclusive - days
                st_add[i] = new Student(new Person("John", "Smith", new DateTime(1998, 1, day_int)), Education.Bachelor, 112);
            }

            sc.AddStudents(st_add);
            Console.WriteLine(sc.ToShortString());

            sc.SortByBirthDate();
            Console.WriteLine(sc.ToShortString());
        }
示例#4
0
    static void Main(string[] args)
    {
        Person p1 = new Person("Fyodr", "Uncle", new DateTime(2000, 11, 4));
        Person p2 = new Person();

        Student s1 = new Student(p1, Education.Bachelor, 1);
        Student s2 = new Student();


        Person p3 = new Person();
        Person p4 = new Person();

        Student s3 = new Student(p3, Education.Bachelor, 1);
        Student s4 = new Student(p4, Education.Specialist, 2);


        StudentCollection <Student> stcl  = new StudentCollection <Student>();
        StudentCollection <Student> stcl2 = new StudentCollection <Student>();


        Journal j1 = new Journal();
        Journal j2 = new Journal();

        stcl.StudentChanged  += j1.handler;
        stcl2.StudentChanged += j2.handler;


        Student[] st = new Student[2];
        st[0] = s1;
        st[1] = s2;
        stcl.AddStudents(st);

        Student[] st2 = new Student[2];
        st2[0] = s3;
        st2[1] = s4;
        stcl2.AddStudents(st2);

        stcl.Remove(0);
        stcl.Replace(s2, s3);

        Console.WriteLine(j1);
        Console.WriteLine(j2);
    }
        public void Test_SortByAGP()
        {
            StudentCollection sc = new StudentCollection();

            Student[] st_add = new Student[5];
            Random    rand   = new Random();

            for (int i = 0; i < 5; i++)
            {
                int     grade       = rand.Next(1, 6); // 1 is inclusive, 6 is exclusive - grade [1,5]
                Student tmp_student = new Student();
                tmp_student.AddExams(new Exam("Some Exam", grade, new DateTime()));
                st_add[i] = tmp_student;
                //st_add[i] = new Student(new Person("John", "Smith", new DateTime()), Education.Bachelor, 112);
            }

            sc.AddStudents(st_add);
            Console.WriteLine(sc.ToShortString());

            sc.SortByAGP();
            Console.WriteLine(sc.ToShortString());
        }
        public void Test_SortByLastName()
        {
            StudentCollection sc = new StudentCollection();

            Student[] st_add = new Student[5];
            Random    rand   = new Random();

            for (int i = 0; i < 5; i++)
            {
                // generate a random integer :
                int symbol_int = rand.Next(65, 91); // 65 is inclusive, 91 is exclusive - [A - Z] ASCII table interval
                // get character from randompy generated integer :
                char   symbol    = (char)symbol_int;
                string last_name = "a" + symbol;
                st_add[i] = new Student(new Person("John", last_name, new DateTime()), Education.Bachelor, 112);
            }

            sc.AddStudents(st_add);
            Console.WriteLine(sc.ToShortString());
            sc.SortByLastName();
            Console.WriteLine(sc.ToShortString());
        }
        public void Test_Specialists()
        {
            StudentCollection sc = new StudentCollection();

            Student[] st_add = new Student[5];
            //Random rand = new Random();
            Student tmp_student = new Student(new Person("John 0", "Smith 0", new DateTime()), Education.Bachelor, 121);

            st_add[0] = tmp_student;

            Student tmp_student1 = new Student(new Person("John 1", "Smith 1", new DateTime()), Education.Specialist, 121);

            st_add[1] = tmp_student1;

            Student tmp_student2 = new Student(new Person("John 2", "Smith 2", new DateTime()), Education.Specialist, 121);

            st_add[2] = tmp_student2;

            Student tmp_student3 = new Student(new Person("John 3", "Smith 3", new DateTime()), Education.Bachelor, 121);

            st_add[3] = tmp_student3;

            Student tmp_student4 = new Student(new Person("John 4", "Smith 4", new DateTime()), Education.Bachelor, 121);

            st_add[4] = tmp_student4;

            sc.AddStudents(st_add);

            Console.WriteLine(sc.ToShortString());

            IEnumerable <Student> test_list = sc.Specialists;

            foreach (var item in test_list)
            {
                Console.WriteLine(item.ToShortString());
            }
        }
        public void Test_AverageMarkGroup()
        {
            StudentCollection sc = new StudentCollection();

            Student[] st_add = new Student[5];
            //Random rand = new Random();

            for (int i = 0; i < 5; i++)
            {
                //int grade = rand.Next(1, 6); // 1 is inclusive, 6 is exclusive - grade [1,5]
                Student tmp_student = new Student(new Person("John " + i, "Smith " + i, new DateTime()), Education.Bachelor, 121);
                tmp_student.AddExams(new Exam("Some Exam", i, new DateTime()));
                st_add[i] = tmp_student;
                //st_add[i] = new Student(new Person("John", "Smith", new DateTime()), Education.Bachelor, 112);
            }

            sc.AddStudents(st_add);
            Console.WriteLine(sc.ToShortString());

            /* Since we have populated StudentCollection with Students and added exams
             * to those students with grades == i, the only predictable AGP value is 4.
             * Thus we are creating a list of Students with AGP == 4.
             */
            List <Student> test_list = sc.AverageMarkGroup(4);

            if (test_list.Count != 0)
            {
                foreach (var item in test_list)
                {
                    Console.WriteLine(item.ToString());
                }
            }
            else
            {
                Console.WriteLine("Test List contains no Students.");
            }
        }
示例#9
0
    static void Main(string[] args)
    {
        Person p1 = new Person("Fyodr", "Uncle", new DateTime(2000, 11, 4));
        Person p2 = new Person();

        Student s1 = new Student(p1, Education.Bachelor, 1);

        Exam cs      = new Exam();
        Exam math    = new Exam("math", 4, new DateTime(2021 - 5 - 6));
        Exam physics = new Exam("physics", 4, new DateTime(2021 - 5 - 7));

        Exam[] exams = new Exam[3];
        exams[0] = cs;
        exams[1] = math;
        exams[2] = physics;
        List <Exam> examsList = new List <Exam>();

        examsList.AddRange(exams);
        s1.AddExams(examsList);

        Test t = new Test();

        Test[] tests = new Test[1];
        tests[0] = t;
        List <Test> testsList = new List <Test>();

        testsList.AddRange(tests);
        s1.AddTests(testsList);


        s1.SortBySubject();
        foreach (var e in s1.exams)
        {
            Console.WriteLine(e);
        }
        s1.SortByGrade();
        foreach (var e in s1.exams)
        {
            Console.WriteLine(e);
        }
        s1.SortByDate();
        foreach (var e in s1.exams)
        {
            Console.WriteLine(e);
        }



        Student s2  = new Student();
        Exam    ex1 = new Exam();

        Exam[] exams2 = new Exam[1];
        exams2[0] = ex1;
        List <Exam> examsList2 = new List <Exam>();

        examsList2.AddRange(exams);
        s1.AddExams(examsList2);


        StudentCollection <Student> stcl = new StudentCollection <Student>();

        Student[] st = new Student[2];
        st[0] = s1;
        st[1] = s2;
        stcl.AddStudents(st);


        Console.WriteLine(stcl.ToString());

        Console.WriteLine("max mean value: " + stcl.maxMean);
        Console.WriteLine("specialists: " + stcl.specialists.ToString());

        var grouped = stcl.AverageMarkGroup(4);

        Console.WriteLine("grouped: ", grouped.ToString());


        GenerateElement <Person, Student> generator = x =>

        {
            Person p = new Person("Yellow", "White", new DateTime(2000, 11, 4));

            Student s = new Student(p, Education.Bachelor, 1);

            return(new KeyValuePair <Person, Student>(p, s));
        };

        TestCollections <Person, Student> tc = new TestCollections <Person, Student>(3, generator);
    }
示例#10
0
        static void Main(string[] args)
        {
            // Лабораторная работа №3

            //        1. Создать объект типа StudentCollection. Добавить в коллекцию несколько
            //        различных элементов типа Student и вывести объект StudentCollection.

            StudentCollection studentCollection = new StudentCollection();

            studentCollection.AddStudents(
                TestCollections.GetStudent(5),
                TestCollections.GetStudent(2),
                TestCollections.GetStudent(1),
                TestCollections.GetStudent(3),
                TestCollections.GetStudent(4)
                );



            /*  2. Для созданного объекта StudentCollection вызвать методы,
             *  выполняющие сортировку списка List<Student> по разным критериям, и
             *  после каждой сортировки вывести данные объекта.Выполнить
             *  сортировку:
             *  - по фамилии студента;
             *  - по дате рождения;
             *  - по среднему баллу
             *
             * 3. Вызвать методы класса StudentCollection, выполняющие операции со
             * списком List<Student>, и после каждой операции вывести результат
             * операции. Выполнить
             * - вычисление максимального значения среднего балла для элементов списка;
             * - фильтрацию списка для отбора студентов с формой обучения
             * Education.Specialist;
             * - группировку элементов списка по значению среднего балла;
             * вывести все группы элементов.
             *
             * 4. Создать объект типа TestCollections. Вызвать метод для поиска в
             * коллекциях первого, центрального, последнего и элемента, не
             * входящего в коллекции. Вывести значения времени поиска для всех
             * четырех случаев. Вывод должен содержать информацию о том, к какой
             * коллекции и к какому элементу относится данное значение.*/



            studentCollection.SortByName();
            Console.WriteLine("Sorted by Name: \n {0}\n", string.Join(" ; ", studentCollection.Students.Select(x => x.GetName()).ToArray()));
            studentCollection.SortByDate();
            Console.WriteLine("Sorted by Date: \n {0}\n", string.Join(" ; ", studentCollection.Students.Select(x => x.GetName()).ToArray()));
            studentCollection.GetMaxMiddleScore();
            Console.WriteLine("Sorted by miiddle : \n {0}\n", string.Join(" ; ", studentCollection.Students.Select(x => x.GetName()).ToArray()));
            Console.WriteLine("Maximum middle Score: {0}\n", studentCollection.GetMaxMiddleScore());
            Console.WriteLine("Person with Education = Master :\n {0}\n", string.Join(" ; ", studentCollection.GetMasterStudents().Select(x => x.GetName()).ToArray()));



            int value = 3;

            Console.WriteLine("Students with middle Score more then {0}:\n {1}\n", value,
                              string.Join(" ; ", studentCollection.AverageMarkGroup(value).Select(x => x.GetName()).ToArray()));

            TestCollections test = new TestCollections(1);

            Console.WriteLine("Searching time:");
            test.MeasureTime();
            Console.ReadKey();
        }
示例#11
0
    static void Main(string[] args)
    {
        Person p1 = new Person("Fyodr", "Uncle", new DateTime(2000, 11, 4));
        Person p2 = new Person();

        Student s1 = new Student(p1, Education.Bachelor, 1);

        Exam cs      = new Exam();
        Exam math    = new Exam("math", 4, new DateTime(2021 - 5 - 6));
        Exam physics = new Exam("physics", 4, new DateTime(2021 - 5 - 7));

        Exam[] exams = new Exam[3];
        exams[0] = cs;
        exams[1] = math;
        exams[2] = physics;
        List <Exam> examsList = new List <Exam>();

        examsList.AddRange(exams);
        s1.AddExams(examsList);

        Test t = new Test();

        Test[] tests = new Test[1];
        tests[0] = t;
        List <Test> testsList = new List <Test>();

        testsList.AddRange(tests);
        s1.AddTests(testsList);

        Student s2  = new Student();
        Exam    ex1 = new Exam();

        Exam[] exams2 = new Exam[1];
        exams2[0] = ex1;
        List <Exam> examsList2 = new List <Exam>();

        examsList2.AddRange(exams);
        s1.AddExams(examsList2);


        StudentCollection stcl = new StudentCollection();

        Student[] st = new Student[2];
        st[0] = s1;
        st[1] = s2;
        stcl.AddStudents(st);

        Console.WriteLine(stcl.ToString());
        stcl.compareByMeanValue();
        Console.WriteLine("compareByMeanValue " + stcl.ToShortString());
        stcl.compareByLastName();
        Console.WriteLine("compareByLastName " + stcl.ToShortString());
        stcl.compareByBirthdate();
        Console.WriteLine("compareByBirthdate " + stcl.ToShortString());

        Console.WriteLine("max mean value: " + stcl.maxMean);
        Console.WriteLine("specialists: " + stcl.specialists.ToString());

        // var grouped = stcl.AverageMarkGroup(4);
        // Console.WriteLine("grouped: ", grouped.ToString());

        TestCollections tc = new TestCollections(3);

        tc.findElementInList();
        tc.findElemetKeyDictionary();
        tc.findEdlemetValueDictionary();
    }
示例#12
0
        static void Main()
        {
            var student = new Student
            {
                Birthday = DateTime.Parse("01.03.1994"),
                Exams = new List<Exam>
                {
                    new Exam {DisciplineName = "English", Mark = 6, Date = DateTime.Parse("03.12.2015")},
                    new Exam {DisciplineName = "Math", Mark = 3, Date = DateTime.Parse("03.05.2015")},
                    new Exam {DisciplineName = "Physics", Mark = 7, Date = DateTime.Parse("03.21.2015")},
                    new Exam {DisciplineName = "Biology", Mark = 5, Date = DateTime.Parse("03.17.2015")}
                },
                Education = Education.Bachelor
            };

            Console.WriteLine($"Source student:\n{student}\n");

            Console.WriteLine("Sorted exams by discipline name:\n");
            student.SortExamsByDisciplineName();
            Console.WriteLine(student);
            Console.WriteLine();

            Console.WriteLine("Sorted exams by mark:\n");
            student.SortExamsByMark();
            Console.WriteLine(student);
            Console.WriteLine();

            Console.WriteLine("Sorted exams by date:\n");
            student.SortExamsByDate();
            Console.WriteLine(student);
            Console.WriteLine();

            var students = new StudentCollection<string>(s => s.PersonId.ToString());
            students.AddDefaults(2);

            var student2 = new Student
            {
                Education = Education.Bachelor,
                Exams = new List<Exam>
                {
                    new Exam {DisciplineName = "English", Mark = 4, Date = DateTime.Parse("03.12.2015")},
                    new Exam {DisciplineName = "Math", Mark = 7, Date = DateTime.Parse("03.05.2015")},
                    new Exam {DisciplineName = "Physics", Mark = 9, Date = DateTime.Parse("03.21.2015")},
                    new Exam {DisciplineName = "Biology", Mark = 10, Date = DateTime.Parse("03.17.2015")}
                }
            };

            var student3 = new Student
            {
                Education = Education.Bachelor,
                Exams = new List<Exam>
                {
                    new Exam {DisciplineName = "English", Mark = 7, Date = DateTime.Parse("03.12.2015")},
                    new Exam {DisciplineName = "Math", Mark = 4, Date = DateTime.Parse("03.05.2015")},
                    new Exam {DisciplineName = "Physics", Mark = 8, Date = DateTime.Parse("03.21.2015")},
                    new Exam {DisciplineName = "Biology", Mark = 6, Date = DateTime.Parse("03.17.2015")}
                }
            };

            students.AddStudents(student, student2, student3);
            Console.WriteLine($"StudentCollection<string>:\n{students}");
            Console.WriteLine();
            Console.WriteLine($"StudentCollection<string>(short):\n{students.ToShortString()}");
            Console.WriteLine();

            Console.WriteLine($"Max average mark: {students.MaxAverageMark}\n");

            Console.WriteLine("The list of Bachelors:");
            var bachelors = students.GetWithEducationForm(Education.Bachelor);
            foreach (var bachelor in bachelors)
            {
                Console.WriteLine(bachelor.Value);
            }
            Console.WriteLine();

            Console.WriteLine("Grouping by education:");
            var grouped = students.GroupByEducation;
            foreach (var group in grouped)
            {
                Console.WriteLine($"{group.Key}:");
                foreach (var item in group)
                {
                    Console.WriteLine(item.Value);
                }
                Console.WriteLine();
            }


            var testCollections = new TestCollections<Person, Student>(5, count =>
            {
                var tempStudent = new Student();
                return new KeyValuePair<Person, Student>(tempStudent.Key, tempStudent);
            });
            for (var att = 0; att < TestAttemptsCount; att++)
            {
                Console.WriteLine($"************************ TEST {att} ************************");
                testCollections.PerformSearch(testCollections.Value,
                    tuple => Console.WriteLine($"{tuple.Item1} : {tuple.Item2}"));
                Console.WriteLine();
            }
        }