private static CompetitionRunResult CreateCompetitorFor([NotNull] 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;
        }
Пример #2
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);
        }