Exemple #1
0
        /// <summary>
        ///   Creates a counter example from the <paramref name="path" />.
        /// </summary>
        /// <param name="createModel">The factory function that can be used to create new instances of this model.</param>
        /// <param name="path">
        ///   The path the counter example should be generated from. A value of <c>null</c> indicates that no
        ///   transitions could be generated for the model.
        /// </param>
        /// <param name="endsWithException">Indicates whether the counter example ends with an exception.</param>
        public CounterExample CreateCounterExample(CoupledExecutableModelCreator <TExecutableModel> createModel, byte[][] path, bool endsWithException)
        {
            Requires.NotNull(createModel, nameof(createModel));

            // We have to create new model instances to generate and initialize the counter example, otherwise hidden
            // state variables might prevent us from doing so if they somehow influence the state
            var replayModel    = createModel.Create(StateHeaderBytes);
            var choiceResolver = new NondeterministicChoiceResolver(true);

            replayModel.SetChoiceResolver(choiceResolver);

            CopyFaultActivationStates(replayModel);
            var faultActivations = Faults.Select(fault => fault.Activation).ToArray();

            // Prepend the construction state to the path; if the path is null, at least one further state must be added
            // to enable counter example debugging.
            // Also, get the replay information, i.e., the nondeterministic choices that were made on the path; if the path is null,
            // we still have to get the choices that caused the problem.

            if (path == null)
            {
                path = new[] { new byte[StateVectorSize] }
            }
            ;

            path = new[] { ConstructionState }.Concat(path).ToArray();
            var replayInfo = replayModel.GenerateReplayInformation(choiceResolver, path, endsWithException);

            return(new CounterExample(path, replayInfo, endsWithException, faultActivations));
        }