private static CompetitionRunResult CreateCompetitorForFinishWithNumber(bool finishTimeIsGreater, bool competitorNumberIsGreater)
        {
            int      competitorNumber = competitorNumberIsGreater ? HighCompetitorNumber : LowCompetitorNumber;
            TimeSpan finishTime       = TimeSpan.FromSeconds(finishTimeIsGreater ? 50 : 25);

            var result = new CompetitionRunResult(new Competitor(competitorNumber, "A", "A"));

            TimeSpan startTime = TimeSpan.FromSeconds(10);

            result = result
                     .ChangeTimings(new CompetitionRunTimings(new RecordedTimeBuilder()
                                                              .At(startTime).Build())
                                    .ChangeFinishTime(new RecordedTimeBuilder()
                                                      .At(startTime + finishTime).Build()));

            return(result);
        }
        private static CompetitionRunResult CreateCompetitorForCompletion(bool hasFinished, bool isEliminated)
        {
            var result = new CompetitionRunResult(new Competitor(1, "A", "A"));

            if (isEliminated)
            {
                result = result.ChangeIsEliminated(true);
            }

            if (hasFinished)
            {
                result = result
                         .ChangeTimings(new CompetitionRunTimings(new RecordedTimeBuilder()
                                                                  .At(TimeSpan.FromSeconds(10)).Build())
                                        .ChangeFinishTime(new RecordedTimeBuilder()
                                                          .At(TimeSpan.FromSeconds(25)).Build()));
            }

            return(result);
        }
        private static CompetitionRunResult CreateCompetitorForPenaltyOverrun(bool penaltyTimeIsGreater, bool overrunTimeIsGreater)
        {
            TimeSpan overrunTime = overrunTimeIsGreater ? HighOverrunTime : LowOverrunTime;
            TimeSpan penaltyTime = penaltyTimeIsGreater ? HighPenaltyTime : LowPenaltyTime;

            var result = new CompetitionRunResult(new Competitor(1, "A", "A"));

            TimeSpan startTime = TimeSpan.FromSeconds(10);

            result = result
                     .ChangeTimings(new CompetitionRunTimings(new RecordedTimeBuilder()
                                                              .At(startTime).Build())
                                    .ChangeFinishTime(new RecordedTimeBuilder()
                                                      .At(startTime + overrunTime + StandardCourseTime).Build()));

            int fr = (int)(penaltyTime - overrunTime).TotalSeconds;

            result = result.ChangeFaultCount(fr);

            return(result);
        }
Beispiel #4
0
        private static CompetitionRunResult CreateCompetitorFor(string name, bool hasFinished, bool isEliminated, bool otherHasFinished,
                                                                bool penaltyTimeIsGreater, bool overrunTimeIsGreater, bool otherPenaltyTimeIsGreater, bool otherOverrunTimeIsGreater, bool finishTimeIsGreater,
                                                                bool competitorNumberIsGreater, bool otherFinishTimeIsGreater, bool otherCompetitorNumberIsGreater)
        {
            int competitorNumber = !competitorNumberIsGreater && !otherCompetitorNumberIsGreater
                ? LowOrSameCompetitorNumber
                : competitorNumberIsGreater
                    ? HighCompetitorNumber
                    : LowOrSameCompetitorNumber;

            var result = new CompetitionRunResult(new Competitor(competitorNumber, name, name));

            if (isEliminated)
            {
                result = result.ChangeIsEliminated(true);
            }

            if (hasFinished)
            {
                bool requireSameOverrunTime = !overrunTimeIsGreater && !otherOverrunTimeIsGreater;

                TimeSpan overrunTime = requireSameOverrunTime
                    ? !otherHasFinished ? TimeSpan.Zero : LowOrSameOverrunTime
                    : overrunTimeIsGreater
                        ? HighOverrunTime
                        : LowOrSameOverrunTime;

                bool requireSamePenaltyTime = !penaltyTimeIsGreater && !otherPenaltyTimeIsGreater;

                TimeSpan penaltyTime = requireSamePenaltyTime
                    ? !otherHasFinished ? TimeSpan.Zero : LowOrSamePenaltyTime
                    : penaltyTimeIsGreater
                        ? HighPenaltyTime
                        : LowOrSamePenaltyTime;

                bool requireSameFinishTime = !finishTimeIsGreater && !otherFinishTimeIsGreater;

                TimeSpan extraFinishTime = requireSameFinishTime
                    ? !otherHasFinished ? TimeSpan.Zero : LowOrSameExtraFinishTime
                    : finishTimeIsGreater
                        ? HighExtraFinishTime
                        : LowOrSameExtraFinishTime;

                TimeSpan startTime = TimeSpan.FromSeconds(10);

                TimeSpan finishTimeAbsolute = startTime + overrunTime + extraFinishTime;

                if (!otherHasFinished && (requireSameFinishTime || requireSameOverrunTime) && !overrunTimeIsGreater)
                {
                    // Other has not finished, but finish times must be the same.
                }
                else if (otherHasFinished && (finishTimeIsGreater || otherFinishTimeIsGreater) && requireSameOverrunTime)
                {
                    // Both finished, but overrun times must be the same.
                }
                else
                {
                    finishTimeAbsolute += StandardCourseTime;
                }

                result = result
                         .ChangeTimings(new CompetitionRunTimings(new RecordedTimeBuilder()
                                                                  .At(startTime).Build())
                                        .ChangeFinishTime(new RecordedTimeBuilder()
                                                          .At(finishTimeAbsolute).Build()));

                TimeSpan finishTimeElapsed = finishTimeAbsolute - startTime;

                TimeSpan actualOverrunTime = finishTimeElapsed > StandardCourseTime ? finishTimeElapsed - StandardCourseTime : TimeSpan.Zero;

                int fr       = (int)(penaltyTime - actualOverrunTime).TotalSeconds;
                int refusals = GetRefusalsFor(fr, isEliminated);
                result = result.ChangeRefusalCount(refusals);

                int faults = fr - refusals;
                result = new FakeCompetitionRunResult(result, faults);
            }

            return(result);
        }