public void Minimum_Tracks_Required_Calculation_Returns_Valid_Track_Count_Required_To_Fill_All_Talks() { var lowerBound = 2; var trackDuration = TimeSpan.FromHours(7); // 7 is he valid presentation duration minus the breaks var totalTalkTime = 840; // the total talk presentation time var minimumTracks = trackManager.CalculateMinimumTracksRequired(trackDuration, totalTalkTime); Assert.AreEqual(lowerBound, minimumTracks); }
public List <Track> ScheduleTalks(string [] talkInputs) { var talks = talkManager.GenerateTalksFromInput(talkInputs); var totalTalkDuration = talks.Sum(x => x.Duration); var minimumNoOfTracksRequired = trackManager.CalculateMinimumTracksRequired(totalTrackDuration, totalTalkDuration); var tracks = trackManager.GenerateTracks(minimumNoOfTracksRequired); foreach (var track in tracks) { bool morningSessionFullyAllocated = false; int morningSessionDurationInMinutes = (int)track.MorningSession.Duration.TotalMinutes; for (int talkCounter = talks.Count - 1; talkCounter >= 0; talkCounter--) { int talkDuration = talks[talkCounter].Duration; if (morningSessionDurationInMinutes >= talkDuration && !morningSessionFullyAllocated) { track.MorningSession.Talks.Add(talks[talkCounter]); morningSessionDurationInMinutes = morningSessionDurationInMinutes - talkDuration; talks.RemoveAt(talkCounter); if (morningSessionDurationInMinutes == 0) { morningSessionFullyAllocated = true; track.MorningSession.FullyAllocated = morningSessionFullyAllocated; break; } } } bool afternoonSessionFullyAllocated = false; int afternoonSessionDurationInMinutes = (int)track.AfternoonSession.Duration.TotalMinutes; for (int talkCounter = talks.Count - 1; talkCounter >= 0; talkCounter--) { int talkDuration = talks[talkCounter].Duration; if (afternoonSessionDurationInMinutes >= talkDuration && !afternoonSessionFullyAllocated) { track.AfternoonSession.Talks.Add(talks[talkCounter]); afternoonSessionDurationInMinutes = afternoonSessionDurationInMinutes - talkDuration; talks.RemoveAt(talkCounter); if (afternoonSessionDurationInMinutes == 0 || talks.Count == 0) { afternoonSessionFullyAllocated = true; track.AfternoonSession.FullyAllocated = afternoonSessionFullyAllocated; break; } } } } return(tracks); }