public void ShouldResolveWeekForDistances() { var progression = .1; var endDistance = 8; var startDistance = 2; var trainer = new Trainer(); var weeks = trainer.CalculateNumberOfProgressions(startDistance, endDistance, progression); Assert.AreEqual(1455, Math.Round(weeks * 100)); }
public void CreateRuns(TrainingPlan trainingPlan) { var existingPlan = _dataContext.GetExisting(trainingPlan); var existingAthlete = _dataContext.GetExisting(trainingPlan.Athlete); DeleteFuturePlannedRuns(existingPlan); var trainer = new Trainer(); var runs = trainer.CreateRuns(existingAthlete, existingPlan); foreach (var run in runs) { run.Athlete = existingAthlete; run.TrainingPlan = existingPlan; run.LastChanged = DateTime.Now; _dataContext.InsertOnSubmit(run); } _dataContext.Commit(); }
public void AssertAllRunsOccursOnMonday() { var builder = new AthleteBuilder(); var athlete = builder.Build(); const WeekdaySelectionEnumeration mondaySelected = WeekdaySelectionEnumeration.FirstDayOfWeek; var trainingPlan = CreatePlan(athlete, mondaySelected); var trainer = new Trainer {WeekStartsOnMonday = true}; var runs = trainer.CreateRuns(athlete, trainingPlan); var mondays = runs.ToList().ConvertAll(x => (x.Start).DayOfWeek); Assert.IsTrue(mondays.All(day => day == DayOfWeek.Monday)); }
public void AssertCreatePlannedRunsWhenOneDaysIsSelected() { var builder = new AthleteBuilder(); var athlete = builder.Build(); const WeekdaySelectionEnumeration oneSelectedDayForTraining = WeekdaySelectionEnumeration.FirstDayOfWeek; var trainingPlan = CreatePlan(athlete, oneSelectedDayForTraining); var trainer = new Trainer(); var runs = trainer.CreateRuns(athlete, trainingPlan); var distances = runs.ToList().ConvertAll(x => (x.Distance).ToString()); const string expected = "2000,2200,2420,2000,2662,2928,3221,2662,3543,3897,4287,3543,4716,5187,5706,4716,6277,6905,7595,6277,8354,9190,7000,10000"; var actual = string.Join(",", distances.ToArray()); Assert.AreEqual(expected, actual); }
partial void DeleteTrainer(Trainer instance);
partial void UpdateTrainer(Trainer instance);
partial void InsertTrainer(Trainer instance);
public void AssertRunsOccursOnSelectedWeekdays() { var builder = new AthleteBuilder(); var athlete = builder.Build(); const int expectedRunCount = 70; const WeekdaySelectionEnumeration threeDays = WeekdaySelectionEnumeration.FirstDayOfWeek | WeekdaySelectionEnumeration.ThirdDayOfWeek | WeekdaySelectionEnumeration.FifthDayOfWeek; var trainingPlan = CreatePlan(athlete, threeDays); var trainer = new Trainer {WeekStartsOnMonday = true}; var runs = trainer.CreateRuns(athlete, trainingPlan); Assert.AreEqual(expectedRunCount, runs.Count()); var days = runs.ToList().ConvertAll(x => x.Start.DayOfWeek); Assert.AreEqual(expectedRunCount, days.Count()); Func<DayOfWeek, bool> isValidDaySelection = day => day == DayOfWeek.Monday || day == DayOfWeek.Wednesday || day == DayOfWeek.Friday; Assert.IsTrue(days.All(isValidDaySelection)); trainer = new Trainer {WeekStartsOnMonday = false}; runs = trainer.CreateRuns(athlete, trainingPlan).ToList(); days = runs.ToList().ConvertAll(x => (x.Start).DayOfWeek); Assert.AreEqual(expectedRunCount, days.Count()); isValidDaySelection = day => day == DayOfWeek.Sunday || day == DayOfWeek.Tuesday || day == DayOfWeek.Thursday; Assert.IsTrue(days.All(isValidDaySelection)); }