internal void CalculateReferenceTime_AsSpecificDriver_FromRaceData(ReferenceTimeCalculator referenceTimeCalculator,
                                                                           DriverCodeGenerator driverCodeGenerator,
                                                                           LapDataGenerator lapDataGenerator,
                                                                           string team)
        {
            var(drivers, raceData) = BuildRaceData(driverCodeGenerator, lapDataGenerator, team);
            referenceTimeCalculator.SetStrategy(new SpecificDriverAverageReferenceTimeStrategy(drivers.ToArray()[2].DriverCode));
            var referenceTime = referenceTimeCalculator.Calculate(drivers, raceData);

            Assert.Equal(TimeSpan.FromSeconds(17), referenceTime.Time);
        }
        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);
        }
        internal void CalculateReferenceTime_AsWinnerAverage_FromRaceData(ReferenceTimeCalculator referenceTimeCalculator,
                                                                          RaceWinnerAverageReferenceTimeStrategy raceWinnerAverageReferenceTimeStrategy,
                                                                          DriverCodeGenerator driverCodeGenerator,
                                                                          LapDataGenerator lapDataGenerator,
                                                                          string team)
        {
            var(drivers, raceData) = BuildRaceData(driverCodeGenerator, lapDataGenerator, team);
            referenceTimeCalculator.SetStrategy(raceWinnerAverageReferenceTimeStrategy);
            var referenceTime = referenceTimeCalculator.Calculate(drivers, raceData);

            Assert.Equal(TimeSpan.FromSeconds(2), referenceTime.Time);
        }
Exemple #4
0
        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);
        }
        private (IReadOnlyCollection <Driver> Drivers, RaceData raceData) BuildRaceData(DriverCodeGenerator driverCodeGenerator,
                                                                                        LapDataGenerator lapDataGenerator,
                                                                                        string team)
        {
            var drivers = new List <Driver>
            {
                new Driver(new Name("DriverOne", "One"), driverCodeGenerator.Generate(), team,
                           new FinishStatus(new Position(1), "Finished")),
                new Driver(new Name("DriverTwo", "Two"), driverCodeGenerator.Generate(), team,
                           new FinishStatus(new Position(2), "Finished")),
                new Driver(new Name("DriverThree", "Three"), driverCodeGenerator.Generate(), team,
                           new FinishStatus(new Position(3), "Finished")),
            };

            var driverRaceData = new[]
            {
                BuildDriverRaceData(lapDataGenerator, drivers[0].DriverCode.Code,
                                    new [] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(3) }),
                BuildDriverRaceData(lapDataGenerator, drivers[1].DriverCode.Code,
                                    new [] { TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(11), TimeSpan.FromSeconds(12) }),
                BuildDriverRaceData(lapDataGenerator, drivers[2].DriverCode.Code,
                                    new [] { TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(17), TimeSpan.FromSeconds(19) }),
            };

            var raceData = new RaceData(driverRaceData);

            return(drivers, raceData);
        }
Exemple #6
0
        public void MapRaceData_MultipleDrivers_FromValidData(DriverLapTimesMapper mapper, DriverCodeGenerator driverCodeGenerator, LapDataGenerator lapDataGenerator)
        {
            var code1 = driverCodeGenerator.Generate();
            var code2 = driverCodeGenerator.Generate();
            var dict  = new Dictionary <string, IReadOnlyCollection <LapDto> >
            {
                { code1.Code, new List <LapDto>
                  {
                      new LapDto(lapDataGenerator.LapTimeSpan(), 1, 1),
                  } },
                { code2.Code, new List <LapDto>
                  {
                      new LapDto(lapDataGenerator.LapTimeSpan(), 1, 2),
                      new LapDto(lapDataGenerator.LapTimeSpan(), 2, 1),
                  } },
            };

            var driverLapTimes = mapper.DriverLapTimes(dict);
            var raceData       = mapper.ToRaceData(driverLapTimes);

            Assert.NotNull(raceData);
            Assert.Equal(2, raceData.DriverCodes.Count);
            Assert.Equal(2, raceData.AllDriverRaceData.Count);

            var allDriverData = raceData.AllDriverRaceData.ToArray();

            Assert.Equal(1, allDriverData[0].TotalLapCount);
            Assert.Equal(2, allDriverData[1].TotalLapCount);
        }
Exemple #7
0
        public void MapRaceData_SingularDriver_FromValidData(DriverLapTimesMapper mapper, DriverCodeGenerator driverCodeGenerator, LapDataGenerator lapDataGenerator)
        {
            var code = driverCodeGenerator.Generate();
            var dict = new Dictionary <string, IReadOnlyCollection <LapDto> >
            {
                { code.Code, new List <LapDto>
                  {
                      new LapDto(lapDataGenerator.LapTimeSpan(), 1, 1),
                      new LapDto(lapDataGenerator.LapTimeSpan(), 2, 1),
                      new LapDto(lapDataGenerator.LapTimeSpan(), 3, 1),
                  } }
            };

            var driverLapTimes = mapper.DriverLapTimes(dict);
            var raceData       = mapper.ToRaceData(driverLapTimes);

            Assert.NotNull(raceData);
            Assert.Equal(1, raceData.DriverCodes.Count);
            Assert.Equal(code, raceData.DriverCodes.Single());
            Assert.Equal(1, raceData.AllDriverRaceData.Count);
            Assert.Equal(3, raceData.AllDriverRaceData.Single().TotalLapCount);
            Assert.Equal(code, raceData.AllDriverRaceData.Single().DriverCode);
        }
Exemple #8
0
        public void MapDriverLapTime_MultipleDrivers_FromValidData(DriverLapTimesMapper mapper, DriverCodeGenerator driverCodeGenerator, LapDataGenerator lapDataGenerator)
        {
            var code1 = driverCodeGenerator.Generate();
            var code2 = driverCodeGenerator.Generate();
            var dict  = new Dictionary <string, IReadOnlyCollection <LapDto> >
            {
                { code1.Code, new List <LapDto>
                  {
                      new LapDto(lapDataGenerator.LapTimeSpan(), 1, 1),
                  } },
                { code2.Code, new List <LapDto>
                  {
                      new LapDto(lapDataGenerator.LapTimeSpan(), 1, 2),
                  } },
            };

            var driverLapTimes = mapper.DriverLapTimes(dict);

            Assert.NotNull(driverLapTimes);
            Assert.Equal(2, driverLapTimes.Count);
            Assert.True(driverLapTimes.All(x => x.LapInformation.Count == 1));
        }
Exemple #9
0
        public void MapDriverLapTime_SingularDriver_FromValidData(DriverLapTimesMapper mapper, DriverCodeGenerator driverCodeGenerator, LapDataGenerator lapDataGenerator)
        {
            var code = driverCodeGenerator.Generate();
            var dict = new Dictionary <string, IReadOnlyCollection <LapDto> >
            {
                { code.Code, new List <LapDto>
                  {
                      new LapDto(lapDataGenerator.LapTimeSpan(), 1, 1),
                      new LapDto(lapDataGenerator.LapTimeSpan(), 2, 1),
                      new LapDto(lapDataGenerator.LapTimeSpan(), 3, 1),
                  } }
            };

            var driverLapTimes = mapper.DriverLapTimes(dict);

            Assert.NotNull(driverLapTimes);
            Assert.Equal(1, driverLapTimes.Count);
            Assert.Equal(3, driverLapTimes.First(x => x.DriverCode == code.Code).LapInformation.Count);
            Assert.Equal(code.Code, driverLapTimes.First().DriverCode);
        }