예제 #1
0
        /// <summary>
        /// Produces the target state that results from invoking <paramref name="action"/>
        /// in the context of <paramref name="startState"/>.
        /// </summary>
        /// <param name="startState">The state in which the action is invoked</param>
        /// <param name="action">The action to be invoked</param>
        /// <param name="transitionPropertyNames">The names of meta-properties to be collected
        /// during the calculation of the step.</param>
        /// <param name="transitionProperties">Output parameter that will contain a
        /// map of property names to property values. Each property value multiset of
        /// terms. For example, the property value might be the value of a Boolean function
        /// that controls state filtering. Or, it might correspond to the "coverage" of the model that results from this
        /// step. In this case, the value might denote the line numbers or blocks of the
        /// model program that were exercised in this step, or a projection of the state
        /// space or a reference to section numbers of a requirements document to indicate
        /// that the functionality defined by that section was exercised.</param>
        /// <returns>The state that results from the invocation of <paramref name="action"/>
        /// in <paramref name="startState"/>.</returns>
        /// <seealso cref="GetTransitionPropertyNames"/>
        public override IState GetTargetState(IState startState, CompoundTerm action, Set <string> transitionPropertyNames,
                                              out TransitionProperties transitionProperties)
        {
            // it is assumed that the action is enabled in the given state

            PairState ps = startState as PairState;

            if (ps == null)
            {
                throw new ArgumentException("Unexpected type-- expected PairState");
            }

            Symbol actionSymbol = action.Symbol;

            if (!this.signature.Contains(actionSymbol))
            {
                throw new ArgumentException("Invalid argument-- action symbol " + actionSymbol.ToString() + " not in signature.");
            }

            bool doM1 = this.signature.IsShared(actionSymbol) || this.signature.IsOnlyInM1(actionSymbol);
            bool doM2 = this.signature.IsShared(actionSymbol) || this.signature.IsOnlyInM2(actionSymbol);

            TransitionProperties m1TransitionProperties = new TransitionProperties();
            TransitionProperties m2TransitionProperties = new TransitionProperties();
            IState targetState1 = doM1 ? m1.GetTargetState(M1Reduct(ps), action, transitionPropertyNames, out m1TransitionProperties) : M1Reduct(ps);
            IState targetState2 = doM2 ? m2.GetTargetState(M2Reduct(ps), action, transitionPropertyNames, out m2TransitionProperties) : M2Reduct(ps);

            transitionProperties = m1TransitionProperties.Union(m2TransitionProperties);
            return(PairState.CreateState(targetState1, targetState2));
        }
예제 #2
0
        /// <summary>
        /// Produces the target state that results from invoking <paramref name="action"/>
        /// in the context of <paramref name="startState"/>.
        /// </summary>
        /// <param name="startState">The state in which the action is invoked</param>
        /// <param name="action">The action to be invoked</param>
        /// <param name="transitionPropertyNames">The names of meta-properties to be collected
        /// during the calculation of the step.</param>
        /// <param name="transitionProperties">Output parameter that will contain a
        /// map of property names to property values. Each property value multiset of
        /// terms. For example, the property value might be the value of a Boolean function
        /// that controls state filtering. Or, it might correspond to the "coverage" of the model that results from this
        /// step. In this case, the value might denote the line numbers or blocks of the
        /// model program that were exercised in this step, or a projection of the state
        /// space or a reference to section numbers of a requirements document to indicate
        /// that the functionality defined by that section was exercised.</param>
        /// <returns>The state that results from the invocation of <paramref name="action"/>
        /// in <paramref name="startState"/>.</returns>
        /// <seealso cref="GetTransitionPropertyNames"/>
        public override IState GetTargetState(IState startState, CompoundTerm action, Set <string> transitionPropertyNames,
                                              out TransitionProperties transitionProperties)
        {
            transitionProperties = new TransitionProperties();
            FsmState fs = startState as FsmState;

            if (fs == null)
            {
                throw new ArgumentException("Invalid state");
            }

            Set <Term> targetAutomatonStates = Set <Term> .EmptySet;

            foreach (Term automatonState in fs.AutomatonStates)
            {
                Set <Transition> outgoing = this.automaton.OutgoingTransitions(automatonState);
                foreach (Transition t in outgoing)
                {
                    CompoundTerm ct = t.Second as CompoundTerm;
                    if (ct == null)
                    {
                        throw new InvalidOperationException("Internal error");
                    }
                    if (IsCompatibleTerm(action, ct)) //(Object.Equals(ct, action))
                    {
                        targetAutomatonStates = targetAutomatonStates.Add(t.Third);
                    }
                }
            }

            if (targetAutomatonStates.Equals(Set <Term> .EmptySet))
            {
                throw new ArgumentException("Action not enabled: " + action.ToString());
            }

            return(new FsmState(targetAutomatonStates));
        }
예제 #3
0
        /// <summary>
        /// Merges two property sets by multiset-union of corresponding entries.
        /// </summary>
        /// <param name="other">The property set to be merged</param>
        /// <returns>The union of this property set and <paramref name="other"/></returns>
        public TransitionProperties Union(TransitionProperties other)
        {
            if (null == other)
            {
                throw new ArgumentNullException("other");
            }

            Map <string, Bag <Term> > result  = this.properties.Count > other.properties.Count ? this.properties : other.properties;
            Map <string, Bag <Term> > smaller = this.properties.Count > other.properties.Count ? other.properties : this.properties;

            foreach (Pair <string, Bag <Term> > kv in smaller)
            {
                Bag <Term> propVal;
                if (result.TryGetValue(kv.First, out propVal))
                {
                    result = result.Override(kv.First, propVal.Union(kv.Second));
                }
                else
                {
                    result = result.Add(kv);
                }
            }
            return(new TransitionProperties(result));
        }
예제 #4
0
 public abstract IState GetTargetState(IState startState, CompoundTerm action, Set <string> transitionPropertyNames,
                                       out TransitionProperties transitionProperties);
예제 #5
0
        /// <summary>
        /// Produces the target state that results from invoking <paramref name="action"/>
        /// in the context of <paramref name="startState"/>.
        /// </summary>
        /// <param name="startState">The state in which the action is invoked</param>
        /// <param name="action">The action to be invoked</param>
        /// <param name="transitionPropertyNames">The names of meta-properties to be collected
        /// during the calculation of the step.</param>
        /// <param name="transitionProperties">Output parameter that will contain a 
        /// map of property names to property values. Each property value multiset of
        /// terms. For example, the property value might be the value of a Boolean function
        /// that controls state filtering. Or, it might correspond to the "coverage" of the model that results from this
        /// step. In this case, the value might denote the line numbers or blocks of the 
        /// model program that were exercised in this step, or a projection of the state 
        /// space or a reference to section numbers of a requirements document to indicate
        /// that the functionality defined by that section was exercised.</param>
        /// <returns>The state that results from the invocation of <paramref name="action"/>
        /// in <paramref name="startState"/>.</returns>
        /// <seealso cref="GetTransitionPropertyNames"/>
        public override IState GetTargetState(IState startState, CompoundTerm action, Set<string> transitionPropertyNames,
            out TransitionProperties transitionProperties)
        {
            transitionProperties = new TransitionProperties();
            FsmState fs = startState as FsmState;
            if (fs == null)
                throw new ArgumentException("Invalid state");

            Set<Term> targetAutomatonStates = Set<Term>.EmptySet;
            foreach (Term automatonState in fs.AutomatonStates)
            {
                Set<Transition> outgoing = this.automaton.OutgoingTransitions(automatonState);
                foreach (Transition t in outgoing)
                {
                    CompoundTerm ct = t.Second as CompoundTerm;
                    if (ct == null) throw new InvalidOperationException("Internal error, invalid transition. FSM transition action symbol is null in "+t.ToString());
                    if (IsCompatibleTerm(action, ct)) //(Object.Equals(ct, action))
                    {
                        targetAutomatonStates = targetAutomatonStates.Add(t.Third);
                    }
                }
            }

            if (targetAutomatonStates.Equals(Set<Term>.EmptySet))
                throw new ArgumentException("Action not enabled: " + action.ToString());

            return new FsmState(targetAutomatonStates);
        }
예제 #6
0
        /// <summary>
        /// Merges two property sets by multiset-union of corresponding entries.
        /// </summary>
        /// <param name="other">The property set to be merged</param>
        /// <returns>The union of this property set and <paramref name="other"/></returns>
        public TransitionProperties Union(TransitionProperties other)
        {
            if (null == other)
                throw new ArgumentNullException("other");

            Map<string, Bag<Term>> result = this.properties.Count > other.properties.Count ? this.properties : other.properties;
            Map<string, Bag<Term>> smaller = this.properties.Count > other.properties.Count ? other.properties : this.properties;
            foreach (Pair<string, Bag<Term>> kv in smaller)
            {
                Bag<Term> propVal;
                if (result.TryGetValue(kv.First, out propVal))
                    result = result.Override(kv.First, propVal.Union(kv.Second));
                else
                    result = result.Add(kv);
            }
            return new TransitionProperties(result);
        }
예제 #7
0
        /// <summary>
        /// Produces the target state that results from invoking <paramref name="action"/>
        /// in the context of <paramref name="startState"/>.
        /// </summary>
        /// <param name="startState">The state in which the action is invoked</param>
        /// <param name="action">The action to be invoked</param>
        /// <param name="transitionPropertyNames">The names of meta-properties to be collected
        /// during the calculation of the step.</param>
        /// <param name="transitionProperties">Output parameter that will contain a 
        /// map of property names to property values. Each property value multiset of
        /// terms. For example, the property value might be the value of a Boolean function
        /// that controls state filtering. Or, it might correspond to the "coverage" of the model that results from this
        /// step. In this case, the value might denote the line numbers or blocks of the 
        /// model program that were exercised in this step, or a projection of the state 
        /// space or a reference to section numbers of a requirements document to indicate
        /// that the functionality defined by that section was exercised.</param>
        /// <returns>The state that results from the invocation of <paramref name="action"/>
        /// in <paramref name="startState"/>.</returns>
        /// <seealso cref="GetTransitionPropertyNames"/>
        public override IState GetTargetState(IState startState, CompoundTerm action, Set<string> transitionPropertyNames,
            out TransitionProperties transitionProperties)
        {
            // to do: implement coverage points by callback and add them to transitionProperties
            transitionProperties = new TransitionProperties();
            //Bag<Term> coveragePoints = Bag<Term>.EmptyBag;
            // to do: for all values in action args, call AbstractValue.FinalizeImport()
            if (startState.ControlMode.Equals(readyControlMode))
            {
                ActionKind kind = ActionSymbolKind(action.Symbol);
                SimpleState startState1 = startState as SimpleState;
                if (null == startState1) throw new InvalidOperationException("Unexpected type");
                if ((kind == ActionKind.Start) &&
                    actionInfoMap.ContainsKey(action.Symbol))
                {
                    // to do: add invocPoint to state
                    // throw new Exception("Not Implemented");

                    // Refactor: action invocation point becomes just a state.
                    //ActionInvocationPoint invocPoint =
                    //    new ActionInvocationPoint(this, action, startState);

                    SimpleState midState = startState1.ReplaceControlMode(PushStackFrame(startState.ControlMode, action));
                    MachineStep step = DoStep(midState);

                    this.AddContinuation(midState, step.Action, step.TargetState);
                    transitionProperties.AddProperty("CoveragePoints", this.context.GetCoveragePoints());
                    return midState;
                }
                else if (kind == ActionKind.Atomic)
                {
                    // to do: push action onto stack
                    // throw new NotImplementedException();

                    SimpleState intermediateState = startState1.ReplaceControlMode(PushStackFrame(startState.ControlMode, action));
                    MachineStep step = DoStep(intermediateState);
                    transitionProperties.AddProperty("CoveragePoints", this.context.GetCoveragePoints());
                    return step.TargetState;
                }
                else
                {
                    throw new ArgumentException("Invalid action");
                }
            }
            // Case 2: intermediate step
            else
            {
                return GetContinuationTargetState(startState, action);
            }
        }
예제 #8
0
        /// <summary>
        /// Produces the target state that results from invoking <paramref name="action"/>
        /// in the context of <paramref name="startState"/>.
        /// </summary>
        /// <param name="startState">The state in which the action is invoked</param>
        /// <param name="action">The action to be invoked</param>
        /// <param name="transitionPropertyNames">The names of meta-properties to be collected
        /// during the calculation of the step.</param>
        /// <param name="transitionProperties">Output parameter that will contain a 
        /// map of property names to property values. Each property value multiset of
        /// terms. For example, the property value might be the value of a Boolean function
        /// that controls state filtering. Or, it might correspond to the "coverage" of the model that results from this
        /// step. In this case, the value might denote the line numbers or blocks of the 
        /// model program that were exercised in this step, or a projection of the state 
        /// space or a reference to section numbers of a requirements document to indicate
        /// that the functionality defined by that section was exercised.</param>
        /// <returns>The state that results from the invocation of <paramref name="action"/>
        /// in <paramref name="startState"/>.</returns>
        /// <seealso cref="GetTransitionPropertyNames"/>
        public override IState GetTargetState(IState startState, CompoundTerm action, Set<string> transitionPropertyNames,
            out TransitionProperties transitionProperties)
        {
            // it is assumed that the action is enabled in the given state

            PairState ps = startState as PairState;
            if (ps == null)
                throw new ArgumentException("Unexpected type-- expected PairState");

            Symbol actionSymbol = action.Symbol;
            if (!this.signature.Contains(actionSymbol))
                throw new ArgumentException("Invalid argument-- action symbol " + actionSymbol.ToString() + " not in signature.");

            bool doM1 = this.signature.IsShared(actionSymbol) || this.signature.IsOnlyInM1(actionSymbol);
            bool doM2 = this.signature.IsShared(actionSymbol) || this.signature.IsOnlyInM2(actionSymbol);

            TransitionProperties m1TransitionProperties = new TransitionProperties();
            TransitionProperties m2TransitionProperties = new TransitionProperties();
            IState targetState1 = doM1 ? m1.GetTargetState(M1Reduct(ps), action, transitionPropertyNames, out m1TransitionProperties) : M1Reduct(ps);
            IState targetState2 = doM2 ? m2.GetTargetState(M2Reduct(ps), action, transitionPropertyNames, out m2TransitionProperties) : M2Reduct(ps);

            transitionProperties = m1TransitionProperties.Union(m2TransitionProperties);
            return PairState.CreateState(targetState1, targetState2);
        }
예제 #9
0
 public abstract IState GetTargetState(IState startState, CompoundTerm action, Set<string> transitionPropertyNames,
     out TransitionProperties transitionProperties);