public void Should_compare_finished_should_be_smaller_with_less_laps() { var p1 = RoundPosition.FromLaps("11", MakeLaps("11", 5), false); var p2 = RoundPosition.FromLaps("12", MakeLaps("11", 1), true); RoundPosition.LapsCountFinishedComparer.Compare(p2, p1).Should().BeNegative(); }
public static RoundPosition ParseRating(string line, DateTime roundStartTime) { var parts = line.Split(new[] { ' ', '\t', '[', ']', 'L', 'F' }, StringSplitOptions.RemoveEmptyEntries); var riderId = parts[0]; var finished = line.StartsWith('F'); if (parts.Length == 1) { return(RoundPosition.FromLaps(riderId, new Lap[0], false)); } var lapCount = int.Parse(parts[1]); if (parts.Length - lapCount < 2) { throw new FormatException( $"Input should be in format: <rider_number> <number_of_laps> [<lap_time1> ... <lap_time_number_of_laps]. Found lapCount={lapCount} but {parts.Length - 2} lap times"); } Lap prevLap = null; var laps = parts.Skip(2) .Select((x, i) => { var cp = new Checkpoint(riderId, roundStartTime + TimeSpanExt.Parse(x)); var l = prevLap?.CreateNext(cp) ?? new Lap(cp, roundStartTime); prevLap = l; return(l); }); return(RoundPosition.FromLaps(riderId, laps, finished)); }
public void Should_compare_finished() { var p1 = RoundPosition.FromLaps("11", MakeLaps("11", 3), true); var p2 = RoundPosition.FromLaps("12", MakeLaps("11", 4), true); RoundPosition.LapsCountFinishedComparer.Compare(p2, p1).Should().BeNegative(); }
private IEnumerable <RoundPosition> GetRating(int finishers, int starters) { for (var i = 0; i < finishers; i++) { yield return(RoundPosition.FromLaps($"{11 + i}", new List <Lap> { new(new Checkpoint($"{11 + i}", Constants.DefaultUtcDate), DateTime.UtcNow) }, true));