Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        public static int CompareBySurname(Person leftPerson, Person rightPerson)
        {
            //TODO: Добавить реализацию сравнения по именам

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

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