public void GeneratesValidSchedulesToCoverAllWorkingDaysInMonth() { var monthlyScheduleGenerator = new NaiveMonthlyScheduleGenerator(People); var schedules = monthlyScheduleGenerator.Generate(); Assert.Equal(WorkdaysInMonth.Count() * 2, schedules.Count()); }
public IEnumerable <Schedule> Generate() { var selectedWorkPatterns = _validWorkPatternsToChooseFrom .Where(workPattern => workPattern.Count(flag => flag == 1) == 1) .Select(workPattern => new WorkPatternRepresentation(workPattern)) .ToList(); var monthlyPatterns = CombineWeeklyPatternsIntoMonthlyOnes(selectedWorkPatterns); var schedulePatternGenerator = new SchedulePatternGenerator(monthlyPatterns, _shifts); var schedulePatterns = schedulePatternGenerator.GenerateAll(); var schedules = new List <Schedule>(); for (var personIndex = 0; personIndex < _people.Count(); personIndex += 1) { for (var workdayIndex = 0; workdayIndex < WorkdaysInMonth.Count(); workdayIndex += 1) { var currentDaySchedule = schedulePatterns.ElementAt(personIndex).ElementAt(workdayIndex); if (currentDaySchedule.StartsWith("1")) { var workday = WorkdaysInMonth.ElementAt(workdayIndex); var shift = (WorkShift)Enum.Parse(typeof(WorkShift), currentDaySchedule.Split(",").Skip(1).First()); var schedule = new Schedule { Employee = _people.ElementAt(personIndex), StartTime = new DateTime(workday.Year, workday.Month, workday.Day), EndTime = new DateTime(workday.Year, workday.Month, workday.Day) }; if (WorkShift.Morning == shift) { schedule.StartTime = schedule.StartTime.AddHours(9); } else { schedule.StartTime = schedule.StartTime.AddHours(13); } schedule.EndTime = schedule.StartTime.AddHours(4); schedules.Add(schedule); } } } // NOT GOOD: I'm not making sure the resulting schedules don't include duplicates // (e.g. more than 2 schedules on one and the same day) return(schedules); }