コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
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);
        }