diff --git a/Lab8/Green/Task1.cs b/Lab8/Green/Task1.cs index 15aaa21b..a3289b44 100644 --- a/Lab8/Green/Task1.cs +++ b/Lab8/Green/Task1.cs @@ -1,6 +1,98 @@ -namespace Lab8.Green -{ - public class Task1 +namespace Lab8.Green +{ + public class Task1 { + public abstract class Participant + { + private string _lastname; + private string _group; + private string _couchlm; + private double _result; + protected int _norm; + private static int _passed; + public static int PassedTheStandard => _passed; + public string Surname => _lastname; + public string Group => _group; + public string Trainer => _couchlm; + public double Result => _result; + static Participant() + { + + _passed = 0; + } + public bool HasPassed + { + get + { + if (_result <= _norm) + { + return true; + } + return false; + } + } + public Participant(string name, string group, string trainer) + { + _lastname = name; + _group = group; + _couchlm = trainer; + _result = 0; + } + + public static Participant[] GetTrainerParticipants(Participant[] participants, Type participantType, string trainer) + { + if (participants == null) + { + return new Participant[0]; + } + var a = new Participant[0]; + foreach(var f in participants) + { + if (f.GetType()==participantType && f.Trainer == trainer) + { + Array.Resize(ref a, a.Length + 1); + a[a.Length-1] = f; + } + } + return a; + } + public void Run(double result) + { + if (_result > 0) + { + return; + } + _result = result; + if (result <= _norm) + { + _passed++; + } + } + public void Print() + { + Console.WriteLine($"Фамилия: {_lastname}"); + Console.WriteLine($"Группа: {_group}"); + Console.WriteLine($"Тренер: {_couchlm}"); + Console.WriteLine($"Результат:{_result}"); + Console.WriteLine($"Норматив: {_norm} сек"); + + + } + } + public class Participant100M : Participant + { + public Participant100M(string surname, string group, string trainer) : base(surname, group, trainer) + { + _norm = 12; + } + } + + public class Participant500M : Participant + { + public Participant500M(string surname, string group, string trainer) : base(surname, group, trainer) + { + _norm = 90; + } + } } -} \ No newline at end of file +} diff --git a/Lab8/Green/Task2.cs b/Lab8/Green/Task2.cs index a5788447..47d4f861 100644 --- a/Lab8/Green/Task2.cs +++ b/Lab8/Green/Task2.cs @@ -1,6 +1,109 @@ -namespace Lab8.Green +using System.Xml.Linq; + +namespace Lab8.Green { public class Task2 { + 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 void Print() + { + Console.WriteLine($"Name:{_name}"); + Console.WriteLine($"Surename: {_surname}"); + + } + } + + public class Student: Human + { + + private int[] _marks; + private int _exam; + private static int _otlcount; + private bool _AAAA; + public int[] Marks => _marks.ToArray(); + public static int ExcellentAmount => _otlcount; + + public double AverageMark + { + get + { + if (_marks == null) { return 0; } + double sum = 0; + for (int i = 0; i < _marks.Length; i++) + { + sum += _marks[i]; + } + return sum / _marks.Length; + } + } + public bool IsExcellent + { + get + { + if (_marks == null) { return false; } + for (int i = 0; i < _marks.Length; i++) + { + if (_marks[i] < 4) + { + return false; + } + } + + return true; + } + } + + public Student(string name, string surname): base(name,surname) + { + + _marks = new int[4]; + _exam = 0; + _AAAA = true; + } + public void Exam(int mark) + { + if (mark < 2 || mark > 5) { return; } + if (_exam == 4) { return; } + + _marks[_exam] = mark; + _exam++; + if (_AAAA && IsExcellent) + { + _otlcount++; + _AAAA = false; + } + } + public static void SortByAverageMark(Student[] array) + { + if (array == null) { return; } + for (int i = 0; i < array.Length - 1; i++) + { + for (int j = 0; j < array.Length - 1 - i; j++) + { + if (array[j].AverageMark < array[j + 1].AverageMark) + { + (array[j], array[j + 1]) = (array[j + 1], array[j]); + } + } + } + } + public void Print() + { + Console.WriteLine($"Name:{base.Name}"); + Console.WriteLine($"Surename: {base.Surname}"); + Console.WriteLine($"AverageMark: {AverageMark}"); + Console.WriteLine($"Excellent: {IsExcellent}"); + } + } } -} \ No newline at end of file +} diff --git a/Lab8/Green/Task3.cs b/Lab8/Green/Task3.cs index 63a9a04d..25848bcc 100644 --- a/Lab8/Green/Task3.cs +++ b/Lab8/Green/Task3.cs @@ -2,5 +2,181 @@ namespace Lab8.Green { public class Task3 { + public class Student + { + private string _name; + private string _surname; + private int[] _marks; + private bool _isExpelled; + private int _examCount; + private int _id; + private static int _nextID; + + static Student() + { + _nextID = 1; + } + public Student(string name, string surname) + { + _name = name; + _surname = surname; + _marks = new int[3]; + _isExpelled = false; + _examCount = 0; + _id = _nextID++; + } + + public string Name => _name; + public string Surname => _surname; + public int ID => _id; + + + public int[] Marks + { + get + { + if (_marks == null) return new int[0]; + int[] copy = new int[_marks.Length]; + for (int i = 0; i < _marks.Length; i++) + copy[i] = _marks[i]; + return copy; + } + } + + public bool IsExpelled => _isExpelled; + + public double AverageMark + { + get + { + if (_marks == null) return 0; + double sum = 0; + int count = 0; + for (int i = 0; i < _marks.Length; i++) + { + if (_marks[i] > 0) + { + sum += _marks[i]; + count++; + } + } + if (count == 0) return 0; + return sum / count; + } + } + + public void Exam(int mark) + { + if (_examCount >= 3) return; + + _marks[_examCount] = mark; + _examCount++; + + if (mark == 2) + { + _isExpelled = true; + } + } + + public void Restore() + { + _isExpelled = false; + } + + public static void SortByAverageMark(Student[] array) + { + for (int i = 0; i < array.Length - 1; i++) + { + for (int j = 0; j < array.Length - 1 - i; j++) + { + if (array[j].AverageMark < array[j + 1].AverageMark) + { + (array[j], array[j + 1]) = (array[j + 1], array[j]); + } + } + } + } + + public void Print() + { + string marksStr = string.Join(", ", Marks); + string expelledText; + if (_isExpelled) + expelledText = "да"; + else + expelledText = "нет"; + Console.WriteLine($"Студент: {Name} {Surname}, оценки: {marksStr}, средний балл: {AverageMark:F2}, отчислен: {expelledText}"); + } + } + + public class Commission + { + public static void Sort(Student[] students) + { + if (students == null) return; + for (int i = 0; i < students.Length; i++) + { + for (int j = 0; j < students.Length - 1 - i; j++) + { + if (students[j].ID > students[j + 1].ID) + { + (students[j], students[j + 1]) = (students[j + 1], students[j]); + } + } + } + } + + public static Student[] Expel(ref Student[] students) + { + if (students == null) return new Student[0]; + + int exCoun = 0; + int actCount = 0; + + foreach (var s in students) + { + if (s == null) continue; + if (s.IsExpelled) exCoun++; + else actCount++; + } + + Student[] expelled = new Student[exCoun]; + Student[] active = new Student[actCount]; + + int indE = 0, indA = 0; + foreach (var s in students) + { + if (s == null) continue; + if (s.IsExpelled) expelled[indE++] = s; + else active[indA++] = s; + + } + students = active; + return expelled; + } + + public static void Restore(ref Student[] students, Student restored) + { + if (students == null || restored == null) return; + + foreach (var s in students) + { + if (s != null && s.ID == restored.ID) return; + } + + int insertPos = 0; + while (insertPos < students.Length && students[insertPos].ID < restored.ID) + insertPos++; + + Student[] newArray = new Student[students.Length + 1]; + for (int i = 0; i < insertPos; i++) { newArray[i] = students[i]; } + newArray[insertPos] = restored; + for (int i = insertPos; i < students.Length; i++) + { + newArray[i + 1] = students[i]; + } + students = newArray; + } + } } -} \ No newline at end of file +} diff --git a/Lab8/Green/Task4.cs b/Lab8/Green/Task4.cs index ada37c6b..3d06c5f5 100644 --- a/Lab8/Green/Task4.cs +++ b/Lab8/Green/Task4.cs @@ -1,6 +1,170 @@ -namespace Lab8.Green +namespace Lab8.Green { public class Task4 { + public struct Participant + { + private string _name; + private string _surname; + private double[] _jumps; + private int _countJump; + + public string Name => _name; + public string Surname => _surname; + + public double[] Jumps + { + get + { + if (_jumps == null) return new double[0]; + double[] copy = new double[_jumps.Length]; + for (int i = 0; i < _jumps.Length; i++) + { + copy[i] = _jumps[i]; + } + return copy; + } + } + + public double BestJump + { + get + { + if (_jumps == null || _jumps.Length == 0) return 0; + double best = _jumps[0]; + for (int i = 1; i < _jumps.Length; i++) + { + if (_jumps[i] > best) best = _jumps[i]; + } + return best; + } + } + + public Participant(string name, string surname) + { + _name = name; + _surname = surname; + _jumps = new double[3]; + _countJump = 0; + } + + public void Jump(double result) + { + if (_countJump >= 3) return; + _jumps[_countJump] = result; + _countJump++; + } + + public static void Sort(Participant[] array) + { + for (int i = 0; i < array.Length; i++) + { + for (int j = 0; j < array.Length - i - 1; j++) + { + if (array[j].BestJump < array[j + 1].BestJump) + { + (array[j], array[j + 1]) = (array[j + 1], array[j]); + } + } + } + } + public void Print() + { + string jumpsStr = string.Join(", ", Jumps); + Console.WriteLine($"Спортсмен: {Name} {Surname}, попытки: {jumpsStr}, лучший: {BestJump:F2}"); + } + } + + public abstract class Discipline + { + private string _name; + private Participant[] _participants; + + public string Name => _name; + public Participant[] Participants => _participants; + protected Participant[] ParticipantsArray => _participants; + + protected Discipline(string name) + { + _name = name; + _participants = new Participant[0]; + } + + public void Add(Participant participant) + { + Participant[] newArray = new Participant[_participants.Length + 1]; + for (int i = 0; i < _participants.Length; i++) + newArray[i] = _participants[i]; + newArray[_participants.Length] = participant; + _participants = newArray; + } + + public void Add(Participant[] participants) + { + if (participants == null) return; + Participant[] newArray = new Participant[_participants.Length + participants.Length]; + for (int i = 0; i < _participants.Length; i++) + { + newArray[i] = _participants[i]; + } + for (int i = 0; i < participants.Length; i++) + { + newArray[_participants.Length + i] = participants[i]; + } + _participants = newArray; + } + + public void Sort() + { + Participant.Sort(_participants); + } + + public abstract void Retry(int index); + + public void Print() + { + Console.WriteLine(Name); + Console.WriteLine(Participants); + } + } + + + public class LongJump : Discipline + { + public LongJump() : base("Long jump") { } + + public override void Retry(int index) + { + if (index < 0 || index >= ParticipantsArray.Length) return; + Participant p = ParticipantsArray[index]; + double best = p.BestJump; + if (best == 0 && p.Jumps.Length > 0 && p.Jumps[0] == 0) return; + + Participant newP = new Participant(p.Name, p.Surname); + newP.Jump(best); + ParticipantsArray[index] = newP; + } + } + + public class HighJump : Discipline + { + public HighJump() : base("High jump") { } + + public override void Retry(int index) + { + if (index < 0 || index >= ParticipantsArray.Length) return; + Participant p = ParticipantsArray[index]; + double[] jumps = p.Jumps; + int count = 0; + for (int i = 0; i < jumps.Length; i++) + if (jumps[i] != 0) count++; + if (count == 0) return; + + Participant newP = new Participant(p.Name, p.Surname); + for (int i = 0; i < count - 1; i++) + newP.Jump(jumps[i]); + ParticipantsArray[index] = newP; + } + } } -} \ No newline at end of file +} diff --git a/Lab8/Green/Task5.cs b/Lab8/Green/Task5.cs index 787d4118..cf65d3aa 100644 --- a/Lab8/Green/Task5.cs +++ b/Lab8/Green/Task5.cs @@ -1,6 +1,220 @@ -namespace Lab8.Green -{ - public class Task5 + +namespace Lab8.Green +{ + public class Task5 { + public struct Student + { + private string _name; + private string _surname; + private int[] _marks; + private int _examCount; + + public Student(string name, string surname) + { + _name = name; + _surname = surname; + _marks = new int[5]; + _examCount = 0; + } + public string Name => _name; + public string Surname => _surname; + public int[] Marks + { + get + { + if (_marks == null) return new int[0]; + int[] copy = new int[_marks.Length]; + for (int i = 0; i < copy.Length; i++) + { + copy[i] = _marks[i]; + } + return copy; + } + } + + public double AverageMark + { + get + { + if (_marks == null) return 0; + double sum = 0; + for (int i = 0; i < _marks.Length; i++) + { + sum += _marks[i]; + } + return sum / 5; + } + } + + public void Exam(int mark) + { + if (_examCount >= 5) return; + if (_marks == null) _marks = new int[5]; + _marks[_examCount] = mark; + _examCount++; + } + + public void Print() + { + Console.WriteLine($" Студент: {Name} {Surname}, оценки: {string.Join(", ", Marks)}, средний балл: {AverageMark:F2}"); + } + } + public class Group + { + private string _name; + protected Student[] _students; + + public Group(string name) + { + _name = name; + _students = new Student[0]; + } + + public string Name => _name; + public Student[] Students + { + get + { + if (_students == null) return new Student[0]; + Student[] copy = new Student[_students.Length]; + for (int i = 0; i < _students.Length; i++) + { + copy[i] = _students[i]; + } + return copy; + } + } + + public virtual double AverageMark + { + get + { + if (_students == null || _students.Length == 0) return 0; + double sum = 0; + for (int i = 0; i < _students.Length; i++) + { + sum += _students[i].AverageMark; + } + return sum / _students.Length; + } + } + + public void Add(Student student) + { + Array.Resize(ref _students, _students.Length + 1); + _students[_students.Length - 1] = student; + } + + public void Add(Student[] students) + { + foreach (Student s in students) + { + Add(s); + } + } + + public static void SortByAverageMark(Group[] array) + { + for (int i = 0; i < array.Length; i++) + { + for (int j = 0; j < array.Length - i - 1; j++) + { + if (array[j].AverageMark < array[j + 1].AverageMark) + { + (array[j], array[j + 1]) = (array[j + 1], array[j]); + } + } + } + } + + public void Print() + { + Console.WriteLine($"Группа: {Name}, средний балл группы: {AverageMark:F2}"); + Console.WriteLine("Список студентов:"); + for (int i = 0; i < Students.Length; i++) + { + Console.Write(" "); + Students[i].Print(); + } + } + } + + public class EliteGroup : Group + { + public EliteGroup(string name) : base(name) { } + + public override double AverageMark + { + get + { + if (_students == null || _students.Length == 0) return 0; + double ves = 0; + double ocenkaves = 0; + foreach (var s in _students) + { + int[] marks = s.Marks; + foreach (int mark in marks) + { + if (mark >= 2 && mark <= 5) + { + double w; + switch (mark) + { + case 5: w = 1.0; break; + case 4: w = 1.5; break; + case 3: w = 2.0; break; + case 2: w = 2.5; break; + default: w = 0.0; break; + } + ocenkaves += mark * w; + ves += w; + } + } + } + return ves == 0 ? 0 : ocenkaves / ves; + } + } + } + + public class SpecialGroup : Group + { + public SpecialGroup(string name) : base(name) { } + + public override double AverageMark + { + + get + { + if (_students == null || _students.Length == 0) return 0; + double ves = 0; + double ocenkaves = 0; + foreach (var s in _students) + { + int[] marks = s.Marks; + foreach (int mark in marks) + { + if (mark >= 2 && mark <= 5) + { + double w; + switch (mark) + { + case 5: w = 1.0; break; + case 4: w = 0.75; break; + case 3: w = 0.5; break; + case 2: w = 0.25; break; + default: w = 0.0; break; + } + ocenkaves += mark * w; + ves += w; + } + } + } + return ves == 0 ? 0 : ocenkaves / ves; + } + } + } } -} \ 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); +// } +// } +// } +// }