public void BuildRaceTrace_ShouldThrowException_WhenDriverLookupIsNull( RaceTraceFactory raceTraceFactory, DriverCodeGenerator driverCodeGenerator) { var driverRaceData = new DriverRaceData(driverCodeGenerator.Generate()); var raceData = new RaceData(driverRaceData); var timeSpan = TimeSpan.FromTicks(TimeSpan.TicksPerMinute); var referenceTime = new ReferenceTime(timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds); Assert.Throws <ArgumentNullException>(() => raceTraceFactory.Build(raceData, referenceTime, null)); }
private DriverRaceData BuildDriverRaceData(LapDataGenerator lapDataGenerator, string code, params TimeSpan[] timeSpans) { var driverRaceData = new DriverRaceData(new DriverCode(code)); var laps = lapDataGenerator.GenerateLaps(timeSpans); foreach (var(lapCount, lapData) in laps) { driverRaceData.AddLap(lapCount, lapData); } return(driverRaceData); }
private DriverRaceData DriverRaceData(DriverLapTimes driverLapTimes) { var driverRaceData = new DriverRaceData(MapDriverCode(driverLapTimes.DriverCode)); var laps = LapDataCollection(driverLapTimes.LapInformation); foreach (var lap in laps) { driverRaceData.AddLap(lap.Key, lap.Value); } return(driverRaceData); }
private TimeSpan AverageLapTime(DriverRaceData driverRaceData) { var totalLaps = driverRaceData.TotalLapCount; if (totalLaps < 1) { throw new ArgumentException("Driver race data contains no valid laps."); } var averageTicks = Convert.ToInt64(driverRaceData.GetAllLaps().Average(t => t.Time.TimeTaken.Ticks)); return(TimeSpan.FromTicks(averageTicks)); }
public void BuildRaceTrace_ShouldThrowException_WhenReferenceTimeIsNull( RaceTraceFactory raceTraceFactory, DriverCodeGenerator driverCodeGenerator, string driverName) { var driverRaceData = new DriverRaceData(driverCodeGenerator.Generate()); var raceData = new RaceData(driverRaceData); var diverLookup = new Dictionary <DriverCode, string> { { driverCodeGenerator.Generate(), driverName } }; Assert.Throws <ArgumentNullException>(() => raceTraceFactory.Build(raceData, null, diverLookup)); }
public void BuildRaceTrace_CalculatesTrace_ForSingleDriver( RaceTraceFactory raceTraceFactory, DriverCodeGenerator driverCodeGenerator, LapDataGenerator lapDataGenerator, string driverName) { var driverCode = driverCodeGenerator.Generate(); var driverRaceData = new DriverRaceData(driverCode); var laps = lapDataGenerator.GenerateLaps(4); foreach (var(lapTime, lapData) in laps) { driverRaceData.AddLap(lapTime, lapData); } var raceData = new RaceData(driverRaceData); var timeSpan = TimeSpan.FromTicks(TimeSpan.TicksPerMinute); var referenceTime = new ReferenceTime(timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds); var diverLookup = new Dictionary <DriverCode, string> { { driverCode, driverName } }; var raceTrace = raceTraceFactory.Build(raceData, referenceTime, diverLookup); Assert.NotNull(raceTrace); Assert.Equal(1, raceTrace.DriverCodes.Count); var traceData = raceTrace.GetDataForDriver(driverCode); Assert.NotNull(traceData); var traceLapDeltas = traceData.GetAllLaps(); Assert.Equal(4, traceLapDeltas.Count); }