private bool CheckCompetitionLimitsCore(
            Benchmark benchmark,
            Summary summary,
            CompetitionLimit competitionLimit,
            CompetitionState competitionState,
            List <IWarning> warnings)
        {
            var actualValues = CompetitionLimitProvider.TryGetActualValues(benchmark, summary);

            if (actualValues == null)
            {
                competitionState.AddAnalyserWarning(
                    warnings, MessageSeverity.ExecutionError,
                    $"Could not obtain competition limits for {benchmark.ShortInfo}.",
                    summary.TryGetBenchmarkReport(benchmark));

                return(true);
            }

            if (competitionLimit.CheckLimitsFor(actualValues))
            {
                return(true);
            }

            var targetMethodTitle = benchmark.Target.MethodTitle;
            var message           = competitionLimit.IsEmpty
                                ? $"Method {targetMethodTitle} {actualValues} has empty limit. Please fill it."
                                : $"Method {targetMethodTitle} {actualValues} does not fit into limits {competitionLimit}.";

            competitionState.AddAnalyserWarning(
                warnings, MessageSeverity.TestError, message, summary.TryGetBenchmarkReport(benchmark));

            return(false);
        }
예제 #2
0
 /// <summary>Initializes a new instance of the <see cref="CompetitionTarget"/> class.</summary>
 /// <param name="target">The target.</param>
 /// <param name="limitsForTarget">Competition limits for the target.</param>
 /// <param name="doesNotCompete">Exclude the benchmark from the competition.</param>
 public CompetitionTarget(
     [NotNull] Target target,
     [NotNull] CompetitionLimit limitsForTarget,
     bool doesNotCompete) :
     this(target, limitsForTarget, doesNotCompete, null)
 {
 }
예제 #3
0
        /// <summary>Adjusts competition limits with specified values.</summary>
        /// <param name="limitsForTarget">Competition limits for the target.</param>
        /// <returns><c>true</c> if any of the limits were updated.</returns>
        public bool UnionWith([NotNull] CompetitionLimit limitsForTarget)
        {
            Code.NotNull(limitsForTarget, nameof(limitsForTarget));

            var result = false;

            result |= UnionWithMinRatio(limitsForTarget.MinRatioRounded);
            result |= UnionWithMaxRatio(limitsForTarget.MaxRatioRounded);
            return(result);
        }
예제 #4
0
 /// <summary>Initializes a new instance of the <see cref="CompetitionTarget"/> class.</summary>
 /// <param name="target">The target.</param>
 /// <param name="limitsForTarget">Competition limits for the target.</param>
 /// <param name="doesNotCompete">Exclude the benchmark from the competition.</param>
 /// <param name="competitionMetadata">Description of embedded resource containing xml document with competition limits.</param>
 public CompetitionTarget(
     [NotNull] Target target,
     [NotNull] CompetitionLimit limitsForTarget,
     bool doesNotCompete,
     [CanBeNull] CompetitionMetadata competitionMetadata) :
     base(limitsForTarget.MinRatio, limitsForTarget.MaxRatio)
 {
     Target = target;
     CompetitionMetadata = competitionMetadata;
     DoesNotCompete      = doesNotCompete;
 }
        private CompetitionLimit TryParseCompetitionLimit(
            Target target,
            CompetitionMetadata competitionMetadata,
            CompetitionState competitionState)
        {
            CompetitionLimit result = null;

            // DONTTOUCH: the doc should be loaded for validation even if IgnoreExistingAnnotations = true
            var resourceKey = new ResourceKey(
                target.Type.Assembly,
                competitionMetadata.MetadataResourceName,
                competitionMetadata.UseFullTypeName);

            var xmlAnnotationDoc = _xmlAnnotationsCache.GetOrAdd(
                resourceKey,
                r => XmlAnnotations.TryParseXmlAnnotationDoc(r.Item1, r.Item2, r.Item3, competitionState));

            if (!IgnoreExistingAnnotations && xmlAnnotationDoc != null)
            {
                var parsedLimit = XmlAnnotations.TryParseCompetitionLimit(
                    target,
                    xmlAnnotationDoc,
                    competitionState);

                if (parsedLimit == null)
                {
                    competitionState.WriteMessage(
                        MessageSource.Analyser, MessageSeverity.Warning,
                        $"No XML annotation for {target.MethodTitle} found. Check if the method was renamed.");
                }
                else
                {
                    result = parsedLimit;
                }
            }

            return(result);
        }