예제 #1
0
        public void Forced_finish_duration()
        {
            var def = RoundDef.Parse(@"Track 30
11[5]  12[10] 13[15]
11[20] 
11[25]
12[32] 13[33]
Rating
11 3 [5  20 25]
12 2 [10 32]
13 2 [15 33]");
            var fc  = FinishCriteria.FromDuration(TimeSpan.FromSeconds(30));

            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeFalse();
            fc.HasFinished(def.Rating[1], def.Rating, false).Should().BeFalse();
            fc.HasFinished(def.Rating[2], def.Rating, false).Should().BeFalse();

            // With forced finish, the leader is one who has completed round time
            // that is #12
            fc.HasFinished(def.Rating[0], def.Rating, true).Should().BeFalse();
            // #12 finished == true, but we don't store this value
            fc.HasFinished(def.Rating[1], def.Rating, true).Should().BeTrue();
            // Leader was not marker as finished, so #13 is also not finished
            fc.HasFinished(def.Rating[2], def.Rating, true).Should().BeFalse();

            def.Rating[1].Finish();
            fc.HasFinished(def.Rating[2], def.Rating, true).Should().BeTrue();
        }
예제 #2
0
        public void Known_results(string name, string defFile, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(File.ReadAllText(Path.Combine(KnownDefsDirectory, defFile)));
            var track = def.CreateTrack(factory, FinishCriteria.FromDuration(def.Duration));

            track.ForceFinish();
            track.ToRoundDefString().Should().Be(def.ToString(), name);
        }
예제 #3
0
        public static ITrackOfCheckpoints CreateTrack(this RoundDef def, FinishCriteria fc)
        {
            var track = TrackOfCheckpointsFactory.Create(def.RoundStartTime, fc);

            foreach (var checkpoint in def.Checkpoints)
            {
                track.Append(checkpoint);
            }
            return(track);
        }
예제 #4
0
        public void Normal_finish_duration_with_additional_laps()
        {
            var def = RoundDef.Parse(@"Track 30
11[5]
11[30]
Rating
11 2 [5 31]");
            var fc  = FinishCriteria.FromDuration(TimeSpan.FromSeconds(30), 1);

            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeFalse();
            def.Rating[0].Append(new Checkpoint("11", DateTime.MinValue + TimeSpan.FromSeconds(40)));
            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeTrue();
        }
예제 #5
0
        public void Simple_start_and_finish(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track 30
11[5]  12[10] 13[15]
11[30] 12[32] 13[33]
Rating
F11 2 [5  30]
F12 2 [10 32]
F13 2 [15 33]");
            var track = def.CreateTrack(factory, FinishCriteria.FromDuration(def.Duration));

            def.VerifyTrack(track, name);
            track.ToRoundDefString().Should().Be(def.ToString());
        }
예제 #6
0
        public void Serialize_track_of_checkpoints(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var str   = @"Track 30
11[5]  12[10] 13[15]
11[30] 12[32] 13[33]
Rating
F11 2 [5  30]
F12 2 [10 32]
F13 2 [15 33]";
            var def   = RoundDef.Parse(str);
            var track = def.CreateTrack(factory, FinishCriteria.FromDuration(def.Duration));

            track.ToRoundDefString().Should().Be(def.ToString(), name);
        }
예제 #7
0
        public void Checkpoints_after_finish_should_be_ignored(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track 30
11[5]  12[10]
11[30] 12[32]
11[35] 12[37]
Rating
F11 2 [5  30]
F12 2 [10 32]");
            var track = def.CreateTrack(factory, FinishCriteria.FromDuration(def.Duration));

            track.ForceFinish();
            def.VerifyTrack(track, name);
        }
예제 #8
0
        public void Sequence_of_checkpoints_should_prevail_over_timestamps(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track 30
11[10] 12[8]
11[40] 12[32]
Rating
F11 2 [10 40]
F12 2 [8 32]");
            var fc    = FinishCriteria.FromDuration(def.Duration);
            var track = def.CreateTrack(factory, fc);

            def.VerifyTrack(track, name);
            track.ToRoundDefString().Should().Be(def.ToString());
        }
예제 #9
0
        public void Force_finish_when_lap_leader_is_down(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track 30
11[1] 11[2] 11[3] 12[4]
12[34]
Rating
F12 2 [4 34]
11 3 [1 2 3]");
            var fc    = FinishCriteria.FromDuration(def.Duration);
            var track = def.CreateTrack(factory, fc);

            track.ForceFinish();
            def.VerifyTrack(track, name);
            track.ToRoundDefString().Should().Be(def.ToString());
        }
예제 #10
0
        public void Force_finish_should_not_affect_rating_with_normal_finish(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track 30
11[5]  12[10] 13[15]
11[30] 12[32]
Rating
F11 2 [5  30]
F12 2 [10 32]
 13 1 [15]");
            var track = def.CreateTrack(factory, FinishCriteria.FromDuration(def.Duration));

            track.ForceFinish();
            def.VerifyTrack(track, name);
            track.ToRoundDefString().Should().Be(def.ToString());
        }
예제 #11
0
        public void Dnf_should_be_last_in_the_rating_2(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track 30
11[1] 12[2] 11[3] 12[4] 11[5] 12[6]
13[7]
11[31] 13[32] 
Rating
F11 4 [1 3 5 31]
F13 2 [7 32]
 12 3 [2 4 6]");
            var track = def.CreateTrack(factory, FinishCriteria.FromDuration(def.Duration));

            def.VerifyTrack(track, name);
            track.ToRoundDefString().Should().Be(def.ToString());
        }
예제 #12
0
        public void In_lack_of_timestamps_should_set_finish_to_leader(string name, Func <DateTime?, IFinishCriteria, ITrackOfCheckpoints> factory)
        {
            var def   = RoundDef.Parse(@"Track
11 12 13
12 11
Rating
F12 2 [0 0]
F11 2 [0 0]
 13 1 [0]");
            var fc    = FinishCriteria.FromForcedFinish();
            var track = def.CreateTrack(factory, fc);

            track.ForceFinish();
            def.VerifyTrack(track, name, false);
            track.ToRoundDefString().Should().Be(def.ToString());
        }
예제 #13
0
        public void Get_leader_with_forced_finish()
        {
            var def = RoundDef.Parse(@"Track 30
11[5]  12[10] 13[15]
11[20] 
11[25]
12[32] 13[33]
Rating
11 3 [5  20 25]
12 2 [10 32]
13 2 [15 33]");
            var fc  = FinishCriteria.FromDuration(TimeSpan.FromSeconds(30));

            fc.GetLeader(def.Rating, false).RiderId.Should().Be("11");
            fc.GetLeader(def.Rating, true).RiderId.Should().Be("12");
        }
예제 #14
0
        public void Finish_by_lap_count()
        {
            var def = RoundDef.Parse(@"Track 30
11[5] 12[6]
11[30]
Rating
11 2 [5 31]
12 1 [6]");
            var fc  = FinishCriteria.FromTotalLaps(3, TimeSpan.FromSeconds(50));

            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeFalse();
            def.Rating[0].Append(new Checkpoint("11", DateTime.MinValue + TimeSpan.FromSeconds(40)));
            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeTrue();

            def.Rating[0].Finish();
            fc.HasFinished(def.Rating[1], def.Rating, false).Should().BeFalse();
            def.Rating[1].Append(new Checkpoint("12", DateTime.MinValue + TimeSpan.FromSeconds(60)));
            fc.HasFinished(def.Rating[1], def.Rating, false).Should().BeTrue();
        }
예제 #15
0
        public void Normal_finish_duration()
        {
            var def = RoundDef.Parse(@"Track 30
11[5]  12[10] 13[15]
11[30] 12[32] 13[33]
Rating
11 2 [5  30]
12 2 [10 32]
13 2 [15 33]");
            var fc  = FinishCriteria.FromDuration(TimeSpan.FromSeconds(30));

            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeTrue();
            fc.HasFinished(def.Rating[1], def.Rating, false).Should().BeFalse();
            fc.HasFinished(def.Rating[2], def.Rating, false).Should().BeFalse();
            def.Rating[0].Finish();

            fc.HasFinished(def.Rating[0], def.Rating, false).Should().BeTrue();
            fc.HasFinished(def.Rating[1], def.Rating, false).Should().BeTrue();
            fc.HasFinished(def.Rating[2], def.Rating, false).Should().BeTrue();
        }
예제 #16
0
        static void Track(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("TrackOfCheckpoints benchmark. Supply number of checkpoints in one cycle and number of cycles");
                Console.WriteLine("Example: benchmark.exe track 1000 100");
                return;
            }
            var cps    = int.Parse(args[0]);
            var cycles = int.Parse(args[1]);

            Console.WriteLine($"TrackOfCheckpoints benchmark. Append {cps} checkpoints {cycles} iterations");
            var  incrementalWithCustomSortRunner = new InstanceRunner(() => new TrackOfCheckpoints(new DateTime(1), FinishCriteria.FromForcedFinish()));
            var  cyclicRunner = new InstanceRunner(() => new TrackOfCheckpointsCyclic(new DateTime(1), FinishCriteria.FromForcedFinish()));
            var  runners      = new[] { ("Incremental custom sort", incrementalWithCustomSortRunner), ("cyclic", cyclicRunner) };