public CheckStateTransition <T> Transition(CheckStateContext <T> context)
            {
                var explorations = Instance.ExampleSpace.Explore(AnalyzeExplorationForCheck.Impl <T>());

                return(new CheckStateTransition <T>(
                           new InstanceExploration_HoldingNextExplorationStage <T>(Instance, explorations, null, true),
                           context));
            }
Пример #2
0
        protected override CheckStateTransition <T> Decorate(
            GenerationStates.Generation_End <T> generationEndState,
            GenerationStates.Generation_Begin <T> generationBeginState,
            CheckStateContext <T> nextContext)
        {
            var nextContextResized = Resize(_resizeStrategy, generationEndState, nextContext);

            return(new CheckStateTransition <T>(generationBeginState, nextContextResized));
        }
Пример #3
0
            public CheckStateTransition <T> Transition(CheckStateContext <T> context)
            {
                if (context.CompletedIterations >= context.RequestedIterations)
                {
                    return(new CheckStateTransition <T>(
                               new TerminationState <T>(TerminationReason.ReachedMaximumIterations),
                               context));
                }

                var iterations = context.Property.Advanced.Run(context.NextParameters);

                return(new CheckStateTransition <T>(
                           new Generation_HoldingNextIteration <T>(iterations),
                           context));
            }
Пример #4
0
        public static CheckResult <T> Check <T>(
            this IGen <Test <T> > property,
            int?iterations  = null,
            int?seed        = null,
            int?size        = null,
            int?shrinkLimit = null,
            string?replay   = null,
            bool deepCheck  = true)
        {
            var resolvedIterations = iterations ?? 100;

            var(initialSize, resizeStrategy) = SizingAspects <T> .Resolve(size == null?null : new Size(size.Value), resolvedIterations);

            var initialParameters = seed == null
                ? GenParameters.Create(initialSize)
                : GenParameters.Create(Rng.Create(seed.Value), initialSize);

            var initialContext = new CheckStateContext <T>(
                property,
                resolvedIterations,
                shrinkLimit ?? 500,
                initialParameters,
                deepCheck);

            CheckState <T> initialState = replay == null
                ? new GenerationStates.Generation_Begin <T>()
                : new ReplayState <T>(replay);

            var transitions = CheckStateEnumerator.Enumerate(
                initialState,
                initialContext,
                new[] { new ResizeCheckStateTransitionDecorator <T>(resizeStrategy) });

            var transitionAggregation = AggregateTransitions(transitions);

            return(new CheckResult <T>(
                       transitionAggregation.FinalContext.CompletedIterationsUntilCounterexample,
                       transitionAggregation.FinalContext.Discards,
                       transitionAggregation.FinalContext.Shrinks + transitionAggregation.FinalContext.CompletedIterationsAfterCounterexample,
                       transitionAggregation.FinalContext.Counterexample == null
                    ? null
                    : FromCounterexampleContext(transitionAggregation.FinalContext.Counterexample),
                       transitionAggregation.Checks,
                       initialParameters,
                       transitionAggregation.FinalContext.NextParameters,
                       transitionAggregation.TerminationReason));
        }
        public static IEnumerable <CheckStateTransition <T> > Enumerate <T>(
            CheckState <T> initialState,
            CheckStateContext <T> initialContext,
            IReadOnlyCollection <ICheckStateTransitionDecorator <T> > decorators) => EnumerableExtensions.Unfold(
            new CheckStateTransition <T>(initialState, initialContext),
            previousTransition =>
        {
            if (previousTransition.State is TerminationState <T> )
            {
                return(new Option.None <CheckStateTransition <T> >());
            }

            var transition = previousTransition.State.Transition(previousTransition.Context);

            var decoratedTransition = decorators
                                      .Scan(
                (previousState: previousTransition.State, nextTransition: transition),
Пример #6
0
        private static CheckStateContext <T> Resize(
            ResizeStrategy <T> resizeStrategy,
            GenerationStates.Generation_End <T> generationEndState,
            CheckStateContext <T> nextContext)
        {
            if (generationEndState.WasLateDiscard)
            {
                if (nextContext.ConsecutiveLateDiscards >= MaxConsecutiveDiscards)
                {
                    return(nextContext
                           .WithNextGenParameters(nextContext.NextParameters with
                    {
                        Size = nextContext.NextParameters.Size.BigIncrement()
                    })
                           .ResetConsecutiveDiscards());
                }
                else
                {
                    return(nextContext);
                }
            }
            else
            {
                var resizeStrategyInfo = new ResizeStrategyInformation <T>(
                    nextContext,
                    generationEndState.CounterexampleContext,
                    generationEndState.Instance);

                var nextSize = resizeStrategy(resizeStrategyInfo);

                return(nextContext
                       .WithNextGenParameters(nextContext.NextParameters with {
                    Size = nextSize
                }));
            }
        }
 protected abstract CheckStateTransition <T> Decorate(TFromState previousState, TToState nextState, CheckStateContext <T> nextContext);
Пример #8
0
 private record TransitionAggregation <T>(
     ImmutableList <CheckIteration <T> > Checks,
     CheckStateContext <T> FinalContext,
     TerminationReason TerminationReason);