diff --git a/Lab8/White/Task1.cs b/Lab8/White/Task1.cs index 5b45a594..62018f95 100644 --- a/Lab8/White/Task1.cs +++ b/Lab8/White/Task1.cs @@ -2,5 +2,199 @@ namespace Lab8.White { public class Task1 { + public class Participant + { + //Поля + private string _surname; + private string _club; + private double _firstjump; + private double _secondjump; + + //Статические поля + private static int _jumpers; + private static int _disqualified; + private static double _standard; + + //Свойства + public string Surname => _surname; + public string Club => _club; + public double FirstJump => _firstjump; + public double SecondJump => _secondjump; + public double JumpSum => _firstjump + _secondjump; + + //Статические свойства + public static int Jumpers => _jumpers; + public static int Disqualified => _disqualified; + + //Конструктор + public Participant(string surname, string club) + { + _surname = surname; + _club = club; + _firstjump = 0; + _secondjump = 0; + _jumpers++; + } + //Статический конструктор + static Participant() + { + _jumpers = 0; + _disqualified = 0; + _standard = 5; + } + //Методы + public void Jump(double result) + { + if (_firstjump == 0) _firstjump = result; //если первый прыжок ещё не задан + else if (_secondjump == 0) _secondjump = result; //иначе если второй ещё не задан + } + + public static void Disqualify(ref Participant[] participants) + { + if (participants == null || participants.Length == 0) return; + int count = 0; + for (int i = 0; i < participants.Length; i++) + { + if (participants[i].FirstJump >= _standard && participants[i].SecondJump >= _standard) count++; + else + { + _disqualified++; + _jumpers--; + } + } + //Создаём массив только для квалифицированных участников + Participant[] parti = new Participant[count]; + int s = 0; + + for (int i = 0; i < participants.Length; i++) + { + if (participants[i].FirstJump >= _standard && participants[i].SecondJump >= _standard) + { + parti[s] = participants[i]; + s++; + } + } + //Заменяем исходный массив новым + participants = parti; + } + + //Пузырьком сортируем массив участников по убыванию суммы двух прыжков + public static void Sort(Participant[] array) + { + if (array == null || array.Length == 0) return; + for (int i = 0; i < array.Length; i++) + { + for (int j = 1; j < array.Length; j++) + { + if (array[j - 1].JumpSum < array[j].JumpSum) + { + (array[j - 1], array[j]) = (array[j], array[j - 1]); + } + } + + } + } + public void Print() + { + return; + } + } } -} \ No newline at end of file + public class Participant + { + //Поля + private string _surname; + private string _club; + private double _firstjump; + private double _secondjump; + + //Статические поля + private static int _jumpers; + private static int _disqualified; + private static double _standard; + + //Свойства + public string Surname => _surname; + public string Club => _club; + public double FirstJump => _firstjump; + public double SecondJump => _secondjump; + public double JumpSum => _firstjump + _secondjump; + + //Статические свойства + public static int Jumpers => _jumpers; + public static int Disqualified => _disqualified; + + //Конструктор + public Participant(string surname, string club) + { + _surname = surname; + _club = club; + _firstjump = 0; + _secondjump = 0; + _jumpers++; + } + //Статический конструктор + static Participant() + { + _jumpers = 0; + _disqualified = 0; + _standard = 5; + } + //Методы + public void Jump(double result) + { + if (_firstjump == 0) _firstjump = result; //если первый прыжок ещё не задан + else if (_secondjump == 0) _secondjump = result; //иначе если второй ещё не задан + } + + public static void Disqualify(ref Participant[] participants) + { + if (participants == null || participants.Length == 0) return; + int count = 0; + for (int i = 0; i < participants.Length; i++) + { + if (participants[i].FirstJump >= _standard && participants[i].SecondJump >= _standard) count++; + else + { + _disqualified++; + _jumpers--; + } + } + //Создаём массив только для квалифицированных участников + Participant[] parti = new Participant[count]; + int s = 0; + + for (int i = 0; i < participants.Length; i++) + { + if (participants[i].FirstJump >= _standard && participants[i].SecondJump >= _standard) + { + parti[s] = participants[i]; + s++; + } + } + //Заменяем исходный массив новым + participants = parti; + } + + //Пузырьком сортируем массив участников по убыванию суммы двух прыжков + public static void Sort(Participant[] array) + { + if (array == null || array.Length == 0) return; + for (int i = 0; i < array.Length; i++) + { + for (int j = 1; j < array.Length; j++) + { + if (array[j - 1].JumpSum < array[j].JumpSum) + { + (array[j - 1], array[j]) = (array[j], array[j - 1]); + } + } + + } + } + public void Print() + { + return; + } + } +} diff --git a/Lab8/White/Task2.cs b/Lab8/White/Task2.cs index dd51888d..da8a2c96 100644 --- a/Lab8/White/Task2.cs +++ b/Lab8/White/Task2.cs @@ -2,5 +2,110 @@ namespace Lab8.White { public class Task2 { + public class Participant + { + //Поля + private string _name; + private string _surname; + private double _firstjump; + private double _secondjump; + + //Статическое поле, где значение задается один раз и не может быть изменено + private static readonly double _standard; + + //Свойства + public string Name => _name; + public string Surname => _surname; + public double FirstJump => _firstjump; + public double SecondJump => _secondjump; + + + public double BestJump + { + get + { + if (_firstjump == 0 && _secondjump == 0) return 0; //нет ни одного прыжка + else if (_firstjump != 0 && _secondjump == 0) return FirstJump; //только первый прыжок + else if (_secondjump != 0 && _firstjump == 0) return SecondJump; //только второй прыжок + else return Math.Max(_firstjump, _secondjump); //максимум, если есть оба + } + } + //Свойство, прошёл ли участник норматив + public bool IsPassed + { + get + { + return BestJump >= _standard; + } + } + //Статический конструктор + static Participant() + { + _standard = 3.0; //норматив + } + //Конструктор + public Participant(string name, string surname) + { + _name = name; + _surname = surname; + _firstjump = 0; + _secondjump = 0; + } + //Конструктор для результатов сразу двух прыжков + public Participant(string name, string surname, double firstjump, double secondjump) + { + _name = name; + _surname = surname; + _firstjump = firstjump; + _secondjump = secondjump; + } + //Методы + public static Participant[] GetPassed(Participant[] participants) + { + //Защита от null/пустого массива (возвращаем пустой массив) + if (participants == null || participants.Length == 0) return new Participant[0]; + // Подсчёт количества прошедших норматив + int s = 0; + for (int i = 0; i < participants.Length; i++) + { + if (participants[i].IsPassed) s++; + } + //Создаем новый массив нужного размера + Participant[] result = new Participant[s]; + int x = 0; + for (int i = 0; i < participants.Length; i++) + { + if (participants[i].IsPassed) + { + result[x++] = participants[i]; + } + } + return result; + } + public void Jump(double result) + { + if (_firstjump == 0) _firstjump = result; //если первый прыжок ещё не задан + else if (_secondjump == 0) _secondjump = result; //иначе если второй ещё не задан + } + //Сортируем массив участников по убыванию лучшего прыжка + public static void Sort(Participant[] array) + { + if (array == null || array.Length == 0) return; + for (int i = 0; i < array.Length; i++) + { + for (int j = 1; j < array.Length; j++) + { + if (array[j - 1].BestJump < array[j].BestJump) + { + (array[j - 1], array[j]) = (array[j], array[j - 1]); + } + } + } + } + public void Print() + { + return; + } + } } -} \ No newline at end of file +} diff --git a/Lab8/White/Task3.cs b/Lab8/White/Task3.cs index cefe2282..c5c53954 100644 --- a/Lab8/White/Task3.cs +++ b/Lab8/White/Task3.cs @@ -2,5 +2,114 @@ namespace Lab8.White { public class Task3 { + public class Student + { + //Приватные поля + private string _name; + private string _surname; + //Защищенные поля + protected int _skipped; + protected int[] _marks; + + //Свойства + public string Name => _name; + public string Surname => _surname; + public int Skipped => _skipped; + + //Средний балл + public double AverageMark + { + get + { + if (_marks == null || _marks.Length == 0) return 0; + double w = 0; + for (int i = 0; i < _marks.Length; i++) w += _marks[i]; + w /= _marks.Length; + return w; + } + } + //Конструктор + public Student(string name, string surname) + { + _name = name; + _surname = surname; + } + //Защищенный конструктор + protected Student(Student student) + { + _name = student._name; + _surname = student._surname; + _skipped = student._skipped; + _marks = student._marks; + } + //Методы + public void Lesson(int mark) + { + if (mark == 0) _skipped++; + else + { + if (_marks == null) _marks = new int[0]; + //увеличиваем размер массива и добавляем оценку в конец + Array.Resize(ref _marks, _marks.Length + 1); + _marks[_marks.Length - 1] = mark; + } + } + //Сортирует массив студентов по убыванию количества пропусков + public static void SortBySkipped(Student[] array) + { + if (array == null || array.Length == 0) return; + for (int i = 0; i < array.Length; i++) + { + for (int j = 1; j < array.Length; j++) + { + if (array[j - 1].Skipped < array[j].Skipped) + { + (array[j - 1], array[j]) = (array[j], array[j - 1]); + } + } + } + } + public void Print() + { + return; + } + } + public class Undergraduate : Student + { + + public Undergraduate(string name, string surname) : base(name, surname) + { + + } + public Undergraduate(Student student) : base(student) + { + + } + public void WorkOff(int mark) + { + //если есть пропуск, тогда отрабатываем один пропуск + if (_skipped > 0) + { + _skipped--; //уменьшаем количество пропусков + Lesson(mark); //добавляем новую оценку + } + else + { + //пропусков нет, тогда ищем двойку в массиве оценок и меняем её + for (int i = 0; i < _marks.Length; i++) + { + if (_marks[i] == 2) + { + _marks[i] = mark; //замена двойки на новую оценку + return; //выходим после первой замены + } + } + } + } + public new void Print() + { + return; + } + } } -} \ No newline at end of file +} diff --git a/Lab8/White/Task4.cs b/Lab8/White/Task4.cs index 1213a6a6..a7cf363a 100644 --- a/Lab8/White/Task4.cs +++ b/Lab8/White/Task4.cs @@ -2,5 +2,96 @@ namespace Lab8.White { public class Task4 { + public class Human + { + //Приватные поля + private string _name; + private string _surname; + + //Свойства + public string Name => _name; + public string Surname => _surname; + + //Конструктор + public Human(string name, string surname) + { + _name = name; + _surname = surname; + } + //Виртуальный метод + public virtual void Print() + { + return; + } + } + public class Participant : Human + { + //Поля + private double[] _scores; + private static int _count; + //Статические свойства + public static int Count => _count; + //Свойства + public double[] Scores + { + get + { + if (_scores == null || _scores.Length == 0) return new double[0]; + double[] copy = new double[_scores.Length]; + for (int i = 0; i < _scores.Length; i++) copy[i] = _scores[i]; + return copy; + } + } + public double TotalScore + { + get + { + if (_scores == null || _scores.Length == 0) return 0; + double s = 0; + for (int i = 0; i < _scores.Length; i++) s += _scores[i]; + return s; + } + } + //Статический конструктор + static Participant() + { + _count = 0; + } + public Participant(string name, string surname) : base(name, surname) + { + _scores = new double[0]; //пустой массив результатов + _count++; //увеличиваем общее количество участников + } + //Методы + public void PlayMatch(double result) + { + if (result == 0 || result == 0.5 || result == 1) + { + if (_scores == null) _scores = new double[0]; + Array.Resize(ref _scores, _scores.Length + 1); + _scores[_scores.Length - 1] = result; + } + } + //Статический метод сортировки массива участников по убыванию + public static void Sort(Participant[] array) + { + if (array == null || array.Length == 0) return; + for (int i = 0; i < array.Length; i++) + { + for (int j = 1; j < array.Length; j++) + { + if (array[j - 1].TotalScore < array[j].TotalScore) + { + (array[j - 1], array[j]) = (array[j], array[j - 1]); + } + } + } + } + //Переопределение виртуального метода + public override void Print() + { + return; + } + } } -} \ No newline at end of file +} diff --git a/Lab8/White/Task5.cs b/Lab8/White/Task5.cs index 0db85418..fcac3bc7 100644 --- a/Lab8/White/Task5.cs +++ b/Lab8/White/Task5.cs @@ -2,5 +2,174 @@ namespace Lab8.White { public class Task5 { + public struct Match + { + //Приватные поля + private int _goals; + private int _misses; + + //Свойства + public int Goals => _goals; + public int Misses => _misses; + public int Difference => _goals - _misses; + public int Score + { + get + { + if (_goals > _misses) return 3; + else if (_goals == _misses) return 1; + else return 0; + } + } + //Конструктор структуры + public Match(int goals, int misses) + { + _goals = goals; + _misses = misses; + } + //Методы + public void Print() + { + return; + } + } + //Абстрактный класс (общие поля и методы для всех команд) + public abstract class Team + { + //Поля + private string _name; + private Match[] _matches; + + //Свойства + public string Name => _name; + public Match[] Matches + { + get + { + return _matches; + } + } + //разница забитых и пропущенных голов за все матчи + public int TotalDifference + { + get + { + if (_matches == null || _matches.Length == 0) return 0; + int x = 0; + for (int i = 0; i < _matches.Length; i++) x += _matches[i].Difference; + return x; + } + } + //общее количество очков (набранных командой) + public int TotalScore + { + get + { + if (_matches == null || _matches.Length == 0) return 0; + int count1 = 0; + for (int i = 0; i < _matches.Length; i++) + { + int matchScore = _matches[i].Score; + count1 = count1 + matchScore; + } + return count1; + } + } + //Конструктор + public Team(string name) + { + _name = name; + _matches = new Match[0]; + } + //Виртуальный метод + public virtual void PlayMatch(int goals, int misses) + { + if (_matches == null) _matches = new Match[0]; + //увеличиваем размер массива и добавляем новый матч + Array.Resize(ref _matches, _matches.Length + 1); + _matches[_matches.Length - 1] = new Match(goals, misses); + } + //Статическая сортировка массива команд + public static void SortTeams(Team[] teams) + { + if (teams == null || teams.Length <= 1) return; + for (int i = 0; i < teams.Length; i++) + { + for (int j = 1; j < teams.Length; j++) + { + //сравниваем по очкам + if (teams[j - 1].TotalScore < teams[j].TotalScore) + { + (teams[j - 1], teams[j]) = (teams[j], teams[j - 1]); + } + //если очки равны, тогда сравниваем по разности голов + else if (teams[j - 1].TotalScore == teams[j].TotalScore) + { + if (teams[j - 1].TotalDifference < teams[j].TotalDifference) + { + (teams[j - 1], teams[j]) = (teams[j], teams[j - 1]); + } + } + } + } + } + public void Print() + { + return; + } + } + + public class ManTeam : Team + { + private ManTeam _derby; //ссылка на команду дерби + + public ManTeam Derby => _derby; //свойство (вернуть дерби) + + public ManTeam(string name, ManTeam derby = null) : base(name) + { + _derby = derby; + } + public void PlayMatch(int goals, int misses, ManTeam team = null) + { + if (team == _derby && team != null) goals++; + //вызов метода (сохранение матча) + base.PlayMatch(goals, misses); + } + } + public class WomanTeam : Team + { + private int[] _penalties; //массив штрафов + + public int[] Penalties => _penalties; //свойство + + //Общая сумма штрафов + public int TotalPenalties + { + get + { + if (_penalties == null || _penalties.Length == 0) return 0; + int s = 0; + for (int i = 0; i < _penalties.Length; i++) s += _penalties[i]; + return s; + } + } + public WomanTeam(string name) : base(name) + { + _penalties = new int[0]; + } + public override void PlayMatch(int goals, int misses) + { + //Проверяем, пропущенные голы больше забитых + if (misses > goals) + { + int penalti = misses - goals; //размер штрафа + //добавляем штраф в массив + Array.Resize(ref _penalties, _penalties.Length + 1); + _penalties[_penalties.Length - 1] = penalti; + } + //сохраняем матч в класс + base.PlayMatch(goals, misses); + } + } } -} \ No newline at end of file +} diff --git a/Lab8Test/Blue/Task5.cs b/Lab8Test/Blue/Task5.cs index 4170d806..dac0bc3c 100644 --- a/Lab8Test/Blue/Task5.cs +++ b/Lab8Test/Blue/Task5.cs @@ -1,482 +1,482 @@ -//using System; -//using System.IO; -//using System.Linq; -//using System.Reflection; -//using System.Text.Json; -//using Microsoft.VisualStudio.TestTools.UnitTesting; - -//namespace Lab8Test.Blue -//{ -// [TestClass] -// public sealed class Task5 -// { -// record InputSportsman(string Name, string Surname, int Place); -// record InputTeam(string Name, InputSportsman[] Sportsmen); -// record OutputTeam(string Name, int TotalScore, int TopPlace); - -// private InputTeam[] _inputManTeams; -// private InputTeam[] _inputWomanTeams; -// private OutputTeam[] _outputManTeams; -// private OutputTeam[] _outputWomanTeams; - -// private Lab8.Blue.Task5.Sportsman[] _manSportsmen; -// private Lab8.Blue.Task5.Sportsman[] _womanSportsmen; -// private Lab8.Blue.Task5.Team[] _manTeams; -// private Lab8.Blue.Task5.Team[] _womanTeams; - -// [TestInitialize] -// public void LoadData() -// { -// var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName; -// folder = Path.Combine(folder, "Lab8Test", "Blue"); - -// var input = JsonSerializer.Deserialize( -// File.ReadAllText(Path.Combine(folder, "input.json")))!; -// var output = JsonSerializer.Deserialize( -// File.ReadAllText(Path.Combine(folder, "output.json")))!; - -// _inputManTeams = input.GetProperty("Task5Man").Deserialize()!; -// _inputWomanTeams = input.GetProperty("Task5Woman").Deserialize()!; - -// _outputManTeams = output.GetProperty("Task5Man").Deserialize()!; -// _outputWomanTeams = output.GetProperty("Task5Woman").Deserialize()!; - -// _manSportsmen = _inputManTeams.SelectMany(t => t.Sportsmen) -// .Select(s => new Lab8.Blue.Task5.Sportsman(s.Name, s.Surname)) -// .ToArray(); - -// _womanSportsmen = _inputWomanTeams.SelectMany(t => t.Sportsmen) -// .Select(s => new Lab8.Blue.Task5.Sportsman(s.Name, s.Surname)) -// .ToArray(); -// } - -// [TestMethod] -// public void Test_00_OOP() -// { -// var type = typeof(Lab8.Blue.Task5.Sportsman); -// Assert.IsFalse(type.IsValueType, "Sportsman должен быть классом"); -// Assert.IsTrue(type.IsClass); -// Assert.AreEqual(0, type.GetFields(BindingFlags.Public | BindingFlags.Instance).Length); -// Assert.IsTrue(type.GetProperty("Name")?.CanRead ?? false, "Нет свойства Name"); -// Assert.IsTrue(type.GetProperty("Surname")?.CanRead ?? false, "Нет свойства Surname"); -// Assert.IsTrue(type.GetProperty("Place")?.CanRead ?? false, "Нет свойства Place"); -// Assert.IsFalse(type.GetProperty("Name")?.CanWrite ?? false, "Свойство Name должно быть только для чтения"); -// Assert.IsFalse(type.GetProperty("Surname")?.CanWrite ?? false, "Свойство Surname должно быть только для чтения"); -// Assert.IsFalse(type.GetProperty("Place")?.CanWrite ?? false, "Свойство Place должно быть только для чтения"); -// Assert.IsNotNull(type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(string), typeof(string) }, null), "Нет публичного конструктора Sportsman(string name, string surname)"); -// Assert.IsNotNull(type.GetMethod("SetPlace", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(int) }, null), "Нет публичного метода SetPlace(int place)"); -// Assert.IsNotNull(type.GetMethod("Print", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null), "Нет публичного метода Print()"); -// Assert.AreEqual(0, type.GetFields().Count(f => f.IsPublic)); -// Assert.AreEqual(3, type.GetProperties().Count(f => f.PropertyType.IsPublic)); -// Assert.AreEqual(1, type.GetConstructors().Count(f => f.IsPublic)); -// Assert.AreEqual(9, type.GetMethods().Count(f => f.IsPublic)); - -// type = typeof(Lab8.Blue.Task5.Team); -// Assert.IsTrue(type.IsAbstract, "Team должен быть абстрактным классом"); -// Assert.IsTrue(type.IsClass); -// Assert.AreEqual(0, type.GetFields(BindingFlags.Public | BindingFlags.Instance).Length); -// Assert.IsTrue(type.GetProperty("Name")?.CanRead ?? false, "Нет свойства Name"); -// Assert.IsTrue(type.GetProperty("Sportsmen")?.CanRead ?? false, "Нет свойства Sportsmen"); -// Assert.IsTrue(type.GetProperty("SummaryScore")?.CanRead ?? false, "Нет свойства SummaryScore"); -// Assert.IsTrue(type.GetProperty("TopPlace")?.CanRead ?? false, "Нет свойства TopPlace"); -// Assert.IsFalse(type.GetProperty("Name")?.CanWrite ?? false, "Свойство Name должно быть только для чтения"); -// Assert.IsFalse(type.GetProperty("Sportsmen")?.CanWrite ?? false, "Свойство Sportsmen должно быть только для чтения"); -// Assert.IsFalse(type.GetProperty("SummaryScore")?.CanWrite ?? false, "Свойство SummaryScore должно быть только для чтения"); -// Assert.IsFalse(type.GetProperty("TopPlace")?.CanWrite ?? false, "Свойство TopPlace должно быть только для чтения"); -// Assert.IsNotNull(type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Sportsman) }, null), "Нет публичного метода Add(Sportsman sportsman)"); -// Assert.IsNotNull(type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Sportsman[]) }, null), "Нет публичного метода Add(Sportsman[] sportsmen)"); -// Assert.IsNotNull(type.GetMethod("Sort", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Team[]) }, null), "Нет публичного статического метода Sort(Team[] array)"); -// Assert.IsNotNull(type.GetMethod("GetChampion", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Team[]) }, null), "Нет публичного статического метода GetChampion(Team[] teams)"); -// Assert.IsNotNull(type.GetMethod("Print", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null), "Нет публичного метода Print()"); -// var strengthMethod = type.GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); -// Assert.IsNotNull(strengthMethod, "Нет метода GetTeamStrength()"); -// Assert.IsTrue(strengthMethod.IsFamily || strengthMethod.IsFamilyOrAssembly, "Метод GetTeamStrength должен быть protected"); -// Assert.IsTrue(strengthMethod.IsAbstract, "Метод GetTeamStrength должен быть abstract"); -// Assert.AreEqual(0, type.GetFields().Count(f => f.IsPublic)); -// Assert.AreEqual(4, type.GetProperties().Count(f => f.PropertyType.IsPublic)); -// Assert.AreEqual(13, type.GetMethods().Count(f => f.IsPublic)); - -// var manType = typeof(Lab8.Blue.Task5.ManTeam); -// Assert.IsTrue(manType.IsClass); -// Assert.AreEqual(type, manType.BaseType); -// Assert.IsNotNull(manType.GetConstructor(new[] { typeof(string) })); -// var manStrength = manType.GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic); -// Assert.AreEqual(manType, manStrength.DeclaringType); -// Assert.AreEqual(0, manType.GetFields().Count(f => f.IsPublic)); -// Assert.AreEqual(4, manType.GetProperties().Count(f => f.PropertyType.IsPublic)); -// Assert.AreEqual(1, manType.GetConstructors().Count(f => f.IsPublic)); -// Assert.AreEqual(11, manType.GetMethods().Count(f => f.IsPublic)); - -// var womanType = typeof(Lab8.Blue.Task5.WomanTeam); -// Assert.IsTrue(womanType.IsClass); -// Assert.AreEqual(type, womanType.BaseType); -// Assert.IsNotNull(womanType.GetConstructor(new[] { typeof(string) })); -// var womanStrength = womanType.GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic); -// Assert.AreEqual(womanType, womanStrength.DeclaringType); -// Assert.AreEqual(0, womanType.GetFields().Count(f => f.IsPublic)); -// Assert.AreEqual(4, womanType.GetProperties().Count(f => f.PropertyType.IsPublic)); -// Assert.AreEqual(1, womanType.GetConstructors().Count(f => f.IsPublic)); -// Assert.AreEqual(11, womanType.GetMethods().Count(f => f.IsPublic)); -// } - -// [TestMethod] -// public void Test_01_CreateManSportsmen() -// { -// Assert.AreEqual(_manSportsmen.Length, _inputManTeams.Sum(t => t.Sportsmen.Length)); -// } - -// [TestMethod] -// public void Test_01_CreateWomanSportsmen() -// { -// Assert.AreEqual(_womanSportsmen.Length, _inputWomanTeams.Sum(t => t.Sportsmen.Length)); -// } - -// [TestMethod] -// public void Test_02_InitManSportsmen() -// { -// CheckManSportsmen(placeExpected: false); -// } - -// [TestMethod] -// public void Test_02_InitWomanSportsmen() -// { -// CheckWomanSportsmen(placeExpected: false); -// } - -// [TestMethod] -// public void Test_03_SetManPlaces() -// { -// SetManPlaces(); -// CheckManSportsmen(placeExpected: true); -// } - -// [TestMethod] -// public void Test_03_SetWomanPlaces() -// { -// SetWomanPlaces(); -// CheckWomanSportsmen(placeExpected: true); -// } - -// [TestMethod] -// public void Test_04_CreateManTeams() -// { -// InitManTeams(); -// CheckManTeams(filled: false); -// } - -// [TestMethod] -// public void Test_04_CreateWomanTeams() -// { -// InitWomanTeams(); -// CheckWomanTeams(filled: false); -// } - -// [TestMethod] -// public void Test_05_FillManTeams() -// { -// SetManPlaces(); -// InitManTeams(); -// FillManTeams(); -// CheckManTeams(filled: true); -// } - -// [TestMethod] -// public void Test_05_FillWomanTeams() -// { -// SetWomanPlaces(); -// InitWomanTeams(); -// FillWomanTeams(); -// CheckWomanTeams(filled: true); -// } - -// [TestMethod] -// public void Test_06_FillManyManTeams() -// { -// SetManPlaces(); -// InitManTeams(); -// FillManyManTeams(); -// CheckManTeams(filled: true); -// } - -// [TestMethod] -// public void Test_06_FillManyWomanTeams() -// { -// SetWomanPlaces(); -// InitWomanTeams(); -// FillManyWomanTeams(); -// CheckWomanTeams(filled: true); -// } - -// [TestMethod] -// public void Test_07_SortMan() -// { -// SetManPlaces(); -// InitManTeams(); -// FillManTeams(); -// Lab8.Blue.Task5.Team.Sort(_manTeams); -// CheckManTeamsSorted(); -// } - -// [TestMethod] -// public void Test_07_SortWoman() -// { -// SetWomanPlaces(); -// InitWomanTeams(); -// FillWomanTeams(); -// Lab8.Blue.Task5.Team.Sort(_womanTeams); -// CheckWomanTeamsSorted(); -// } - -// [TestMethod] -// public void Test_08_GetTeamStrength() -// { -// SetManPlaces(); -// InitManTeams(); -// FillManTeams(); - -// SetWomanPlaces(); -// InitWomanTeams(); -// FillWomanTeams(); - -// double delta = 0.0001; - -// // ManTeam 0 -// var strength0 = (double)_manTeams[0].GetType().GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_manTeams[0], null); -// Assert.AreEqual(11.32075, strength0, delta); - -// // WomanTeam 0 -// var strengthWoman = (double)_womanTeams[0].GetType().GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_womanTeams[0], null); -// Assert.AreEqual(1.160714, strengthWoman, delta); - -// // ManTeam 1 -// var strength1 = (double)_manTeams[1].GetType().GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_manTeams[1], null); -// Assert.AreEqual(7.594937, strength1, delta); -// } - -// [TestMethod] -// public void Test_09_GetManChampion() -// { -// SetManPlaces(); -// InitManTeams(); -// FillManTeams(); - -// var champion = Lab8.Blue.Task5.Team.GetChampion(_manTeams); -// Assert.AreEqual("Локомотив", champion.Name); -// } - -// [TestMethod] -// public void Test_09_GetWomanChampion() -// { -// SetWomanPlaces(); -// InitWomanTeams(); -// FillWomanTeams(); - -// var champion = Lab8.Blue.Task5.Team.GetChampion(_womanTeams); -// Assert.AreEqual("Динамо", champion.Name); -// } - -// private void SetManPlaces() -// { -// int idx = 0; -// foreach (var t in _inputManTeams) -// { -// foreach (var s in t.Sportsmen) -// { -// _manSportsmen[idx].SetPlace(s.Place); -// idx++; -// } -// } -// } - -// private void SetWomanPlaces() -// { -// int idx = 0; -// foreach (var t in _inputWomanTeams) -// { -// foreach (var s in t.Sportsmen) -// { -// _womanSportsmen[idx].SetPlace(s.Place); -// idx++; -// } -// } -// } - -// private void InitManTeams() -// { -// _manTeams = _inputManTeams.Select(t => (Lab8.Blue.Task5.Team)new Lab8.Blue.Task5.ManTeam(t.Name)).ToArray(); -// } - -// private void InitWomanTeams() -// { -// _womanTeams = _inputWomanTeams.Select(t => (Lab8.Blue.Task5.Team)new Lab8.Blue.Task5.WomanTeam(t.Name)).ToArray(); -// } - -// private void FillManTeams() -// { -// int idx = 0; -// for (int i = 0; i < _manTeams.Length; i++) -// { -// foreach (var s in _inputManTeams[i].Sportsmen) -// { -// _manTeams[i].Add(_manSportsmen[idx]); -// idx++; -// } -// } -// } - -// private void FillWomanTeams() -// { -// int idx = 0; -// for (int i = 0; i < _womanTeams.Length; i++) -// { -// foreach (var s in _inputWomanTeams[i].Sportsmen) -// { -// _womanTeams[i].Add(_womanSportsmen[idx]); -// idx++; -// } -// } -// } - -// private void FillManyManTeams() -// { -// int idx = 0; -// for (int i = 0; i < _manTeams.Length; i++) -// { -// var sportsmenToAdd = _manSportsmen.Skip(idx).Take(_inputManTeams[i].Sportsmen.Length).ToArray(); -// _manTeams[i].Add(sportsmenToAdd); -// idx += _inputManTeams[i].Sportsmen.Length; -// } -// } - -// private void FillManyWomanTeams() -// { -// int idx = 0; -// for (int i = 0; i < _womanTeams.Length; i++) -// { -// var sportsmenToAdd = _womanSportsmen.Skip(idx).Take(_inputWomanTeams[i].Sportsmen.Length).ToArray(); -// _womanTeams[i].Add(sportsmenToAdd); -// idx += _inputWomanTeams[i].Sportsmen.Length; -// } -// } - -// private void CheckManSportsmen(bool placeExpected) -// { -// int idx = 0; -// foreach (var t in _inputManTeams) -// { -// foreach (var s in t.Sportsmen) -// { -// var sp = _manSportsmen[idx]; -// Assert.AreEqual(s.Name, sp.Name); -// Assert.AreEqual(s.Surname, sp.Surname); -// if (placeExpected) -// Assert.AreEqual(s.Place, sp.Place); -// else -// Assert.AreEqual(0, sp.Place); -// idx++; -// } -// } -// } - -// private void CheckWomanSportsmen(bool placeExpected) -// { -// int idx = 0; -// foreach (var t in _inputWomanTeams) -// { -// foreach (var s in t.Sportsmen) -// { -// var sp = _womanSportsmen[idx]; -// Assert.AreEqual(s.Name, sp.Name); -// Assert.AreEqual(s.Surname, sp.Surname); -// if (placeExpected) -// Assert.AreEqual(s.Place, sp.Place); -// else -// Assert.AreEqual(0, sp.Place); -// idx++; -// } -// } -// } - -// private void CheckManTeams(bool filled) -// { -// for (int i = 0; i < _manTeams.Length; i++) -// { -// var team = _manTeams[i]; -// Assert.AreEqual(_inputManTeams[i].Name, team.Name); -// if (filled) -// { -// Assert.AreEqual(6, team.Sportsmen.Length); -// int startIdx = _inputManTeams.Take(i).Sum(x => x.Sportsmen.Length); -// for (int j = 0; j < 6; j++) -// { -// var exp = _inputManTeams[i].Sportsmen[j]; -// var act = team.Sportsmen[j]; -// Assert.AreEqual(exp.Name, act.Name); -// Assert.AreEqual(exp.Surname, act.Surname); -// Assert.AreEqual(exp.Place, act.Place); -// } -// int expSum = team.Sportsmen.Sum(s => s.Place > 0 && s.Place <= 5 ? 6 - s.Place : 0); -// Assert.AreEqual(expSum, team.SummaryScore); -// int expTop = team.Sportsmen.Where(s => s.Place > 0).Select(s => s.Place).DefaultIfEmpty(int.MaxValue).Min(); -// Assert.AreEqual(expTop == int.MaxValue ? 0 : expTop, team.TopPlace); -// } -// else -// { -// Assert.AreEqual(0, team.SummaryScore); -// Assert.AreEqual(18, team.TopPlace); -// } -// } -// } - -// private void CheckWomanTeams(bool filled) -// { -// for (int i = 0; i < _womanTeams.Length; i++) -// { -// var team = _womanTeams[i]; -// Assert.AreEqual(_inputWomanTeams[i].Name, team.Name); -// if (filled) -// { -// Assert.AreEqual(6, team.Sportsmen.Length); -// int startIdx = _inputWomanTeams.Take(i).Sum(x => x.Sportsmen.Length); -// for (int j = 0; j < 6; j++) -// { -// var exp = _inputWomanTeams[i].Sportsmen[j]; -// var act = team.Sportsmen[j]; -// Assert.AreEqual(exp.Name, act.Name); -// Assert.AreEqual(exp.Surname, act.Surname); -// Assert.AreEqual(exp.Place, act.Place); -// } -// int expSum = team.Sportsmen.Sum(s => s.Place > 0 && s.Place <= 5 ? 6 - s.Place : 0); -// Assert.AreEqual(expSum, team.SummaryScore); -// int expTop = team.Sportsmen.Where(s => s.Place > 0).Select(s => s.Place).DefaultIfEmpty(int.MaxValue).Min(); -// Assert.AreEqual(expTop == int.MaxValue ? 0 : expTop, team.TopPlace); -// } -// else -// { -// Assert.AreEqual(0, team.SummaryScore); -// Assert.AreEqual(18, team.TopPlace); -// } -// } -// } - -// private void CheckManTeamsSorted() -// { -// for (int i = 0; i < _manTeams.Length; i++) -// { -// Assert.AreEqual(_outputManTeams[i].Name, _manTeams[i].Name); -// Assert.AreEqual(_outputManTeams[i].TotalScore, _manTeams[i].SummaryScore); -// Assert.AreEqual(_outputManTeams[i].TopPlace, _manTeams[i].TopPlace); -// } -// } - -// private void CheckWomanTeamsSorted() -// { -// for (int i = 0; i < _womanTeams.Length; i++) -// { -// Assert.AreEqual(_outputWomanTeams[i].Name, _womanTeams[i].Name); -// Assert.AreEqual(_outputWomanTeams[i].TotalScore, _womanTeams[i].SummaryScore); -// Assert.AreEqual(_outputWomanTeams[i].TopPlace, _womanTeams[i].TopPlace); -// } -// } -// } -//} \ No newline at end of file +// using System; +// using System.IO; +// using System.Linq; +// using System.Reflection; +// using System.Text.Json; +// using Microsoft.VisualStudio.TestTools.UnitTesting; + +// namespace Lab8Test.Blue +// { +// [TestClass] +// public sealed class Task5 +// { +// record InputSportsman(string Name, string Surname, int Place); +// record InputTeam(string Name, InputSportsman[] Sportsmen); +// record OutputTeam(string Name, int TotalScore, int TopPlace); + +// private InputTeam[] _inputManTeams; +// private InputTeam[] _inputWomanTeams; +// private OutputTeam[] _outputManTeams; +// private OutputTeam[] _outputWomanTeams; + +// private Lab8.Blue.Task5.Sportsman[] _manSportsmen; +// private Lab8.Blue.Task5.Sportsman[] _womanSportsmen; +// private Lab8.Blue.Task5.Team[] _manTeams; +// private Lab8.Blue.Task5.Team[] _womanTeams; + +// [TestInitialize] +// public void LoadData() +// { +// var folder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName; +// folder = Path.Combine(folder, "Lab8Test", "Blue"); + +// var input = JsonSerializer.Deserialize( +// File.ReadAllText(Path.Combine(folder, "input.json")))!; +// var output = JsonSerializer.Deserialize( +// File.ReadAllText(Path.Combine(folder, "output.json")))!; + +// _inputManTeams = input.GetProperty("Task5Man").Deserialize()!; +// _inputWomanTeams = input.GetProperty("Task5Woman").Deserialize()!; + +// _outputManTeams = output.GetProperty("Task5Man").Deserialize()!; +// _outputWomanTeams = output.GetProperty("Task5Woman").Deserialize()!; + +// _manSportsmen = _inputManTeams.SelectMany(t => t.Sportsmen) +// .Select(s => new Lab8.Blue.Task5.Sportsman(s.Name, s.Surname)) +// .ToArray(); + +// _womanSportsmen = _inputWomanTeams.SelectMany(t => t.Sportsmen) +// .Select(s => new Lab8.Blue.Task5.Sportsman(s.Name, s.Surname)) +// .ToArray(); +// } + +// [TestMethod] +// public void Test_00_OOP() +// { +// var type = typeof(Lab8.Blue.Task5.Sportsman); +// Assert.IsFalse(type.IsValueType, "Sportsman должен быть классом"); +// Assert.IsTrue(type.IsClass); +// Assert.AreEqual(0, type.GetFields(BindingFlags.Public | BindingFlags.Instance).Length); +// Assert.IsTrue(type.GetProperty("Name")?.CanRead ?? false, "Нет свойства Name"); +// Assert.IsTrue(type.GetProperty("Surname")?.CanRead ?? false, "Нет свойства Surname"); +// Assert.IsTrue(type.GetProperty("Place")?.CanRead ?? false, "Нет свойства Place"); +// Assert.IsFalse(type.GetProperty("Name")?.CanWrite ?? false, "Свойство Name должно быть только для чтения"); +// Assert.IsFalse(type.GetProperty("Surname")?.CanWrite ?? false, "Свойство Surname должно быть только для чтения"); +// Assert.IsFalse(type.GetProperty("Place")?.CanWrite ?? false, "Свойство Place должно быть только для чтения"); +// Assert.IsNotNull(type.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(string), typeof(string) }, null), "Нет публичного конструктора Sportsman(string name, string surname)"); +// Assert.IsNotNull(type.GetMethod("SetPlace", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(int) }, null), "Нет публичного метода SetPlace(int place)"); +// Assert.IsNotNull(type.GetMethod("Print", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null), "Нет публичного метода Print()"); +// Assert.AreEqual(0, type.GetFields().Count(f => f.IsPublic)); +// Assert.AreEqual(3, type.GetProperties().Count(f => f.PropertyType.IsPublic)); +// Assert.AreEqual(1, type.GetConstructors().Count(f => f.IsPublic)); +// Assert.AreEqual(9, type.GetMethods().Count(f => f.IsPublic)); + +// type = typeof(Lab8.Blue.Task5.Team); +// Assert.IsTrue(type.IsAbstract, "Team должен быть абстрактным классом"); +// Assert.IsTrue(type.IsClass); +// Assert.AreEqual(0, type.GetFields(BindingFlags.Public | BindingFlags.Instance).Length); +// Assert.IsTrue(type.GetProperty("Name")?.CanRead ?? false, "Нет свойства Name"); +// Assert.IsTrue(type.GetProperty("Sportsmen")?.CanRead ?? false, "Нет свойства Sportsmen"); +// Assert.IsTrue(type.GetProperty("TotalScore")?.CanRead ?? false, "Нет свойства TotalScore"); +// Assert.IsTrue(type.GetProperty("TopPlace")?.CanRead ?? false, "Нет свойства TopPlace"); +// Assert.IsFalse(type.GetProperty("Name")?.CanWrite ?? false, "Свойство Name должно быть только для чтения"); +// Assert.IsFalse(type.GetProperty("Sportsmen")?.CanWrite ?? false, "Свойство Sportsmen должно быть только для чтения"); +// Assert.IsFalse(type.GetProperty("TotalScore")?.CanWrite ?? false, "Свойство TotalScore должно быть только для чтения"); +// Assert.IsFalse(type.GetProperty("TopPlace")?.CanWrite ?? false, "Свойство TopPlace должно быть только для чтения"); +// Assert.IsNotNull(type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Sportsman) }, null), "Нет публичного метода Add(Sportsman sportsman)"); +// Assert.IsNotNull(type.GetMethod("Add", BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Sportsman[]) }, null), "Нет публичного метода Add(Sportsman[] sportsmen)"); +// Assert.IsNotNull(type.GetMethod("Sort", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Team[]) }, null), "Нет публичного статического метода Sort(Team[] array)"); +// Assert.IsNotNull(type.GetMethod("GetChampion", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(Lab8.Blue.Task5.Team[]) }, null), "Нет публичного статического метода GetChampion(Team[] teams)"); +// Assert.IsNotNull(type.GetMethod("Print", BindingFlags.Instance | BindingFlags.Public, null, Type.EmptyTypes, null), "Нет публичного метода Print()"); +// var strengthMethod = type.GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); +// Assert.IsNotNull(strengthMethod, "Нет метода GetTeamStrength()"); +// Assert.IsTrue(strengthMethod.IsFamily || strengthMethod.IsFamilyOrAssembly, "Метод GetTeamStrength должен быть protected"); +// Assert.IsTrue(strengthMethod.IsAbstract, "Метод GetTeamStrength должен быть abstract"); +// Assert.AreEqual(0, type.GetFields().Count(f => f.IsPublic)); +// Assert.AreEqual(4, type.GetProperties().Count(f => f.PropertyType.IsPublic)); +// Assert.AreEqual(13, type.GetMethods().Count(f => f.IsPublic)); + +// var manType = typeof(Lab8.Blue.Task5.ManTeam); +// Assert.IsTrue(manType.IsClass); +// Assert.AreEqual(type, manType.BaseType); +// Assert.IsNotNull(manType.GetConstructor(new[] { typeof(string) })); +// var manStrength = manType.GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic); +// Assert.AreEqual(manType, manStrength.DeclaringType); +// Assert.AreEqual(0, manType.GetFields().Count(f => f.IsPublic)); +// Assert.AreEqual(4, manType.GetProperties().Count(f => f.PropertyType.IsPublic)); +// Assert.AreEqual(1, manType.GetConstructors().Count(f => f.IsPublic)); +// Assert.AreEqual(11, manType.GetMethods().Count(f => f.IsPublic)); + +// var womanType = typeof(Lab8.Blue.Task5.WomanTeam); +// Assert.IsTrue(womanType.IsClass); +// Assert.AreEqual(type, womanType.BaseType); +// Assert.IsNotNull(womanType.GetConstructor(new[] { typeof(string) })); +// var womanStrength = womanType.GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic); +// Assert.AreEqual(womanType, womanStrength.DeclaringType); +// Assert.AreEqual(0, womanType.GetFields().Count(f => f.IsPublic)); +// Assert.AreEqual(4, womanType.GetProperties().Count(f => f.PropertyType.IsPublic)); +// Assert.AreEqual(1, womanType.GetConstructors().Count(f => f.IsPublic)); +// Assert.AreEqual(11, womanType.GetMethods().Count(f => f.IsPublic)); +// } + +// [TestMethod] +// public void Test_01_CreateManSportsmen() +// { +// Assert.AreEqual(_manSportsmen.Length, _inputManTeams.Sum(t => t.Sportsmen.Length)); +// } + +// [TestMethod] +// public void Test_01_CreateWomanSportsmen() +// { +// Assert.AreEqual(_womanSportsmen.Length, _inputWomanTeams.Sum(t => t.Sportsmen.Length)); +// } + +// [TestMethod] +// public void Test_02_InitManSportsmen() +// { +// CheckManSportsmen(placeExpected: false); +// } + +// [TestMethod] +// public void Test_02_InitWomanSportsmen() +// { +// CheckWomanSportsmen(placeExpected: false); +// } + +// [TestMethod] +// public void Test_03_SetManPlaces() +// { +// SetManPlaces(); +// CheckManSportsmen(placeExpected: true); +// } + +// [TestMethod] +// public void Test_03_SetWomanPlaces() +// { +// SetWomanPlaces(); +// CheckWomanSportsmen(placeExpected: true); +// } + +// [TestMethod] +// public void Test_04_CreateManTeams() +// { +// InitManTeams(); +// CheckManTeams(filled: false); +// } + +// [TestMethod] +// public void Test_04_CreateWomanTeams() +// { +// InitWomanTeams(); +// CheckWomanTeams(filled: false); +// } + +// [TestMethod] +// public void Test_05_FillManTeams() +// { +// SetManPlaces(); +// InitManTeams(); +// FillManTeams(); +// CheckManTeams(filled: true); +// } + +// [TestMethod] +// public void Test_05_FillWomanTeams() +// { +// SetWomanPlaces(); +// InitWomanTeams(); +// FillWomanTeams(); +// CheckWomanTeams(filled: true); +// } + +// [TestMethod] +// public void Test_06_FillManyManTeams() +// { +// SetManPlaces(); +// InitManTeams(); +// FillManyManTeams(); +// CheckManTeams(filled: true); +// } + +// [TestMethod] +// public void Test_06_FillManyWomanTeams() +// { +// SetWomanPlaces(); +// InitWomanTeams(); +// FillManyWomanTeams(); +// CheckWomanTeams(filled: true); +// } + +// [TestMethod] +// public void Test_07_SortMan() +// { +// SetManPlaces(); +// InitManTeams(); +// FillManTeams(); +// Lab8.Blue.Task5.Team.Sort(_manTeams); +// CheckManTeamsSorted(); +// } + +// [TestMethod] +// public void Test_07_SortWoman() +// { +// SetWomanPlaces(); +// InitWomanTeams(); +// FillWomanTeams(); +// Lab8.Blue.Task5.Team.Sort(_womanTeams); +// CheckWomanTeamsSorted(); +// } + +// [TestMethod] +// public void Test_08_GetTeamStrength() +// { +// SetManPlaces(); +// InitManTeams(); +// FillManTeams(); + +// SetWomanPlaces(); +// InitWomanTeams(); +// FillWomanTeams(); + +// double delta = 0.0001; + +// // ManTeam 0 +// var strength0 = (double)_manTeams[0].GetType().GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_manTeams[0], null); +// Assert.AreEqual(11.32075, strength0, delta); + +// // WomanTeam 0 +// var strengthWoman = (double)_womanTeams[0].GetType().GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_womanTeams[0], null); +// Assert.AreEqual(1.160714, strengthWoman, delta); + +// // ManTeam 1 +// var strength1 = (double)_manTeams[1].GetType().GetMethod("GetTeamStrength", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_manTeams[1], null); +// Assert.AreEqual(7.594937, strength1, delta); +// } + +// [TestMethod] +// public void Test_09_GetManChampion() +// { +// SetManPlaces(); +// InitManTeams(); +// FillManTeams(); + +// var champion = Lab8.Blue.Task5.Team.GetChampion(_manTeams); +// Assert.AreEqual("Локомотив", champion.Name); +// } + +// [TestMethod] +// public void Test_09_GetWomanChampion() +// { +// SetWomanPlaces(); +// InitWomanTeams(); +// FillWomanTeams(); + +// var champion = Lab8.Blue.Task5.Team.GetChampion(_womanTeams); +// Assert.AreEqual("Динамо", champion.Name); +// } + +// private void SetManPlaces() +// { +// int idx = 0; +// foreach (var t in _inputManTeams) +// { +// foreach (var s in t.Sportsmen) +// { +// _manSportsmen[idx].SetPlace(s.Place); +// idx++; +// } +// } +// } + +// private void SetWomanPlaces() +// { +// int idx = 0; +// foreach (var t in _inputWomanTeams) +// { +// foreach (var s in t.Sportsmen) +// { +// _womanSportsmen[idx].SetPlace(s.Place); +// idx++; +// } +// } +// } + +// private void InitManTeams() +// { +// _manTeams = _inputManTeams.Select(t => (Lab8.Blue.Task5.Team)new Lab8.Blue.Task5.ManTeam(t.Name)).ToArray(); +// } + +// private void InitWomanTeams() +// { +// _womanTeams = _inputWomanTeams.Select(t => (Lab8.Blue.Task5.Team)new Lab8.Blue.Task5.WomanTeam(t.Name)).ToArray(); +// } + +// private void FillManTeams() +// { +// int idx = 0; +// for (int i = 0; i < _manTeams.Length; i++) +// { +// foreach (var s in _inputManTeams[i].Sportsmen) +// { +// _manTeams[i].Add(_manSportsmen[idx]); +// idx++; +// } +// } +// } + +// private void FillWomanTeams() +// { +// int idx = 0; +// for (int i = 0; i < _womanTeams.Length; i++) +// { +// foreach (var s in _inputWomanTeams[i].Sportsmen) +// { +// _womanTeams[i].Add(_womanSportsmen[idx]); +// idx++; +// } +// } +// } + +// private void FillManyManTeams() +// { +// int idx = 0; +// for (int i = 0; i < _manTeams.Length; i++) +// { +// var sportsmenToAdd = _manSportsmen.Skip(idx).Take(_inputManTeams[i].Sportsmen.Length).ToArray(); +// _manTeams[i].Add(sportsmenToAdd); +// idx += _inputManTeams[i].Sportsmen.Length; +// } +// } + +// private void FillManyWomanTeams() +// { +// int idx = 0; +// for (int i = 0; i < _womanTeams.Length; i++) +// { +// var sportsmenToAdd = _womanSportsmen.Skip(idx).Take(_inputWomanTeams[i].Sportsmen.Length).ToArray(); +// _womanTeams[i].Add(sportsmenToAdd); +// idx += _inputWomanTeams[i].Sportsmen.Length; +// } +// } + +// private void CheckManSportsmen(bool placeExpected) +// { +// int idx = 0; +// foreach (var t in _inputManTeams) +// { +// foreach (var s in t.Sportsmen) +// { +// var sp = _manSportsmen[idx]; +// Assert.AreEqual(s.Name, sp.Name); +// Assert.AreEqual(s.Surname, sp.Surname); +// if (placeExpected) +// Assert.AreEqual(s.Place, sp.Place); +// else +// Assert.AreEqual(0, sp.Place); +// idx++; +// } +// } +// } + +// private void CheckWomanSportsmen(bool placeExpected) +// { +// int idx = 0; +// foreach (var t in _inputWomanTeams) +// { +// foreach (var s in t.Sportsmen) +// { +// var sp = _womanSportsmen[idx]; +// Assert.AreEqual(s.Name, sp.Name); +// Assert.AreEqual(s.Surname, sp.Surname); +// if (placeExpected) +// Assert.AreEqual(s.Place, sp.Place); +// else +// Assert.AreEqual(0, sp.Place); +// idx++; +// } +// } +// } + +// private void CheckManTeams(bool filled) +// { +// for (int i = 0; i < _manTeams.Length; i++) +// { +// var team = _manTeams[i]; +// Assert.AreEqual(_inputManTeams[i].Name, team.Name); +// if (filled) +// { +// Assert.AreEqual(6, team.Sportsmen.Length); +// int startIdx = _inputManTeams.Take(i).Sum(x => x.Sportsmen.Length); +// for (int j = 0; j < 6; j++) +// { +// var exp = _inputManTeams[i].Sportsmen[j]; +// var act = team.Sportsmen[j]; +// Assert.AreEqual(exp.Name, act.Name); +// Assert.AreEqual(exp.Surname, act.Surname); +// Assert.AreEqual(exp.Place, act.Place); +// } +// int expSum = team.Sportsmen.Sum(s => s.Place > 0 && s.Place <= 5 ? 6 - s.Place : 0); +// Assert.AreEqual(expSum, team.TotalScore); +// int expTop = team.Sportsmen.Where(s => s.Place > 0).Select(s => s.Place).DefaultIfEmpty(int.MaxValue).Min(); +// Assert.AreEqual(expTop == int.MaxValue ? 0 : expTop, team.TopPlace); +// } +// else +// { +// Assert.AreEqual(0, team.TotalScore); +// Assert.AreEqual(18, team.TopPlace); +// } +// } +// } + +// private void CheckWomanTeams(bool filled) +// { +// for (int i = 0; i < _womanTeams.Length; i++) +// { +// var team = _womanTeams[i]; +// Assert.AreEqual(_inputWomanTeams[i].Name, team.Name); +// if (filled) +// { +// Assert.AreEqual(6, team.Sportsmen.Length); +// int startIdx = _inputWomanTeams.Take(i).Sum(x => x.Sportsmen.Length); +// for (int j = 0; j < 6; j++) +// { +// var exp = _inputWomanTeams[i].Sportsmen[j]; +// var act = team.Sportsmen[j]; +// Assert.AreEqual(exp.Name, act.Name); +// Assert.AreEqual(exp.Surname, act.Surname); +// Assert.AreEqual(exp.Place, act.Place); +// } +// int expSum = team.Sportsmen.Sum(s => s.Place > 0 && s.Place <= 5 ? 6 - s.Place : 0); +// Assert.AreEqual(expSum, team.TotalScore); +// int expTop = team.Sportsmen.Where(s => s.Place > 0).Select(s => s.Place).DefaultIfEmpty(int.MaxValue).Min(); +// Assert.AreEqual(expTop == int.MaxValue ? 0 : expTop, team.TopPlace); +// } +// else +// { +// Assert.AreEqual(0, team.TotalScore); +// Assert.AreEqual(18, team.TopPlace); +// } +// } +// } + +// private void CheckManTeamsSorted() +// { +// for (int i = 0; i < _manTeams.Length; i++) +// { +// Assert.AreEqual(_outputManTeams[i].Name, _manTeams[i].Name); +// Assert.AreEqual(_outputManTeams[i].TotalScore, _manTeams[i].TotalScore); +// Assert.AreEqual(_outputManTeams[i].TopPlace, _manTeams[i].TopPlace); +// } +// } + +// private void CheckWomanTeamsSorted() +// { +// for (int i = 0; i < _womanTeams.Length; i++) +// { +// Assert.AreEqual(_outputWomanTeams[i].Name, _womanTeams[i].Name); +// Assert.AreEqual(_outputWomanTeams[i].TotalScore, _womanTeams[i].TotalScore); +// Assert.AreEqual(_outputWomanTeams[i].TopPlace, _womanTeams[i].TopPlace); +// } +// } +// } +// } diff --git a/Lab8Test/Green/Task3.cs b/Lab8Test/Green/Task3.cs index cd03bdd4..a264a01c 100644 --- a/Lab8Test/Green/Task3.cs +++ b/Lab8Test/Green/Task3.cs @@ -138,7 +138,8 @@ // InitStudents(); // ApplyExams(); // int startId = _students[0].ID; -// var shuffled = _students.Reverse().ToArray(); +// var shuffled = _students.ToArray(); +// Array.Reverse(shuffled); // Lab8.Green.Task3.Commission.Sort(shuffled); // for (int i = 0; i < shuffled.Length; i++)