Пример #1
0
        static void Main(string[] args)
        {
            List<Person> students = new List<Person>();
            string fileFullPath = Path.GetFullPath(@"group.txt");

            if (!File.Exists(fileFullPath))
                throw new FileNotFoundException();

            string line;
            using (StreamReader file = new StreamReader(fileFullPath))
            {
                while ((line = file.ReadLine()) != null)
                {
                    Person student = new Person(line);
                    students.Add(student);
                }
            }

            students.Sort(PersonComparer.CompareByGroupNameSurname);

            foreach (Person student in students)
                Console.WriteLine(student);

            Console.ReadKey();
        }
Пример #2
0
        public static int CompareBySurname(Person leftPerson, Person rightPerson)
        {
            //TODO: Добавить реализацию сравнения по именам

            return String.Compare(leftPerson.Surname,rightPerson.Surname);

            //throw new NotImplementedException();
        }
Пример #3
0
        public static int CompareByGroupNameSurname(Person leftPerson, Person rightPerson)
        {
            if (leftPerson.Group.CompareTo(rightPerson.Group) == 0)
                {
                if (CompareByName(leftPerson, rightPerson) == 0)
                { return CompareBySurname(leftPerson, rightPerson); }
                else return CompareByName(leftPerson, rightPerson);

                }
            else
                return leftPerson.Group.CompareTo(rightPerson.Group);
        }
Пример #4
0
        public static int CompareByName(Person leftPerson, Person rightPerson)
        {
            if (rightPerson == null && leftPerson == null)
                {
                return 0;
                }
            if (leftPerson == null)
                {
                return -1;
                }
            if (rightPerson == null)
                {
                return 1;
                }

            return leftPerson.Name.CompareTo(rightPerson.Name);
        }
Пример #5
0
        public static int CompareByGroupNameSurname(Person leftPerson, Person rightPerson)
        {
            //TODO: Добавить реализацию сравнения по именам

            if (String.Compare(leftPerson.Group, rightPerson.Group) == 0)
            {
                if (CompareByName(leftPerson, rightPerson) == 0)
                {
                    return CompareBySurname(leftPerson, rightPerson);
                }
                else
                    return CompareByName(leftPerson, rightPerson);
            }
            else
                return String.Compare(leftPerson.Group,rightPerson.Group);

            //throw new NotImplementedException();
        }
Пример #6
0
 public static int CompareBySurname(Person leftPerson, Person rightPerson)
 {
     return leftPerson.Surname.CompareTo(rightPerson.Surname);
 }
Пример #7
0
 public static int CompareByName(Person leftPerson, Person rightPerson)
 {
     //TODO: Добавить реализацию сравнения по именам
     throw new NotImplementedException();
 }
Пример #8
0
 public void TestNameCompareNull()
 {
     Person personLeft = new Person();
     Person personRight = new Person(@"Бунин Иван РН-231");
     Assert.AreEqual(-1, PersonComparer.CompareByName(personLeft, personRight));
 }
Пример #9
0
 public void TestNameCompare()
 {
     Person personLeft = new Person(@"Мандельштам Осип РН-231");
     Person personRight = new Person(@"Бунин Иван РН-231");
     Assert.AreEqual(1, PersonComparer.CompareByName(personLeft, personRight));
 }
Пример #10
0
 public void TestGroupNameSurnameCompareSameGroupName()
 {
     Person personLeft = new Person(@"Некрасов Иван РН-231");
     Person personRight = new Person(@"Бунин Иван РН-231");
     Assert.AreEqual(1, PersonComparer.CompareByGroupNameSurname(personLeft, personRight));
 }
Пример #11
0
 public void TestGroupNameSurnameCompareDifferentGroup()
 {
     Person personLeft = new Person(@"Бунин Иван РН-231");
     Person personRight = new Person(@"Бунин Иван РН-131");
     Assert.AreEqual(1, PersonComparer.CompareByGroupNameSurname(personLeft, personRight));
 }