public StudentAggregate CalculateStudentsStatistics(IEnumerable <Student> students) { var attendanceDictionary = new Dictionary <int, int>(); var annualGpaDictionary = new Dictionary <int, IList <float> >(); var bestStudents = new SortedDictionary <float, IList <Student> >(new GpaComparer()); Student mostInconsistentStudent = null; float maxInconsistency = -1; foreach (var student in students) { AttendanceHelper.AddStudentAttendance(student, attendanceDictionary); GpaHelper.AddStudentToBestStudents(student, bestStudents); GpaHelper.AddStudentGradesToAnnualGpa(student, annualGpaDictionary); float inconsistency = student.CalculateGradesInconsistency(); if (maxInconsistency < inconsistency) { maxInconsistency = inconsistency; mostInconsistentStudent = student; } } var statistics = new StudentAggregate(); statistics.YearWithHighestAttendance = AttendanceHelper.FindMostAttendedYear(attendanceDictionary); statistics.StudentIdMostInconsistent = (mostInconsistentStudent?.Id).GetValueOrDefault(); statistics.YearWithHighestOverallGpa = GpaHelper.GetHighestsAnnualGpaYear(annualGpaDictionary); statistics.Top10StudentIdsWithHighestGpa = GpaHelper.GetBestStudents(bestStudents, Constants.TopStudentsToSubmit).Select(x => x.Id).ToArray(); return(statistics); }
public void MustIncludeSeveralYears() { var student = _fixture.Build <Student>().With(x => x.StartYear, 2010).With(x => x.EndYear, 2012).Create(); var dictionary = new Dictionary <int, int>(); AttendanceHelper.AddStudentAttendance(student, dictionary); Assert.Equal(3, dictionary.Count); }
public void MustIncludeOneYear() { var student = _fixture.Build <Student>().With(x => x.StartYear, 2010).With(x => x.EndYear, 2010).Create(); var dictionary = new Dictionary <int, int>(); AttendanceHelper.AddStudentAttendance(student, dictionary); Assert.Single(dictionary); Assert.Equal(1, dictionary.Values.First()); }
public void MustThrowWhenIncorrectStartEndDates() { var student = _fixture.Build <Student>().With(x => x.StartYear, 2010).With(x => x.EndYear, 2000).Create(); Assert.Throws <ArgumentException>(() => AttendanceHelper.AddStudentAttendance(student, new Dictionary <int, int>())); }
public void MustThrowWhenStudentIsNull() { Assert.Throws <ArgumentNullException>(() => AttendanceHelper.AddStudentAttendance(null, new Dictionary <int, int>())); }