예제 #1
0
        internal override ConstraintSatisfaction SatisfiesContraint(Model <T> model, ValueCombination combination)
        {
            if (CachedInteraction == null)
            {
                GetExcludedCombinations(model);
            }

            if (CachedInteraction.Parameters.Any((index) => combination.ParameterToValueMap.ContainsKey(index)))
            {
                // supplied combination is a superset
                if (CachedInteraction.Parameters.All((index) => combination.ParameterToValueMap.ContainsKey(index)))
                {
                    var combo = CachedInteraction.Combinations.First((c) => ParameterInteractionTable <T> .MatchCombination(c, combination));
                    return(combo.State == ValueCombinationState.Excluded ? ConstraintSatisfaction.Unsatisfied : ConstraintSatisfaction.Satisfied);
                }
                else
                {
                    return(new ConstraintSatisfactionExpressionVisitor(mapExpressionsToRequiredParams).SatisfiesConstraint(Condition, model, combination));
                }
            }
            else
            {
                // supplied combination is disjoint
                return(ConstraintSatisfaction.InsufficientData);
            }
        }
예제 #2
0
        static ParameterInteraction CreateInteraction(Model <T> model, Expression expression, IList <ParameterBase> parameters, ParameterExpression parameterExpr)
        {
            Func <T, bool> filter = expression is Expression <Func <T, bool> >?
                                    ((Expression <Func <T, bool> >)expression).Compile() :
                                        Expression.Lambda <Func <T, bool> >(expression, parameterExpr).Compile();


            var parameterIndices = (from parameter in parameters
                                    select model.Parameters.IndexOf(parameter)).ToList();

            parameterIndices.Sort();

            ParameterInteraction interaction = new ParameterInteraction(parameterIndices);
            List <int[]>         valueTable  = ParameterInteractionTable <T> .GenerateValueTable(model.Parameters, interaction);

            foreach (var valueIndices in valueTable)
            {
                ValueCombinationState comboState = filter(BuildVariation(model, parameterIndices, valueIndices)) ? ValueCombinationState.Covered : ValueCombinationState.Excluded;
                interaction.Combinations.Add(new ValueCombination(valueIndices, interaction)
                {
                    State = comboState
                });
            }

            return(interaction);
        }
        internal override ParameterInteraction GetExcludedCombinations(Model <T> model)
        {
            if (CachedInteraction == null)
            {
                var taggedValues = GetParametersWithTaggedValues(model);
                CachedInteraction = new ParameterInteraction(taggedValues.Select((p) => p.ParameterIndex));
                var combinationIndices = ParameterInteractionTable <T> .GenerateValueTable(model.Parameters, CachedInteraction);

                foreach (var combinationIndex in combinationIndices)
                {
                    int tagCount = 0;
                    ValueCombination combination = new ValueCombination(combinationIndex, CachedInteraction);
                    combination.State = ValueCombinationState.Covered;

                    for (int i = 0; i < taggedValues.Count; i++)
                    {
                        if (taggedValues[i].ValueIndices.BinarySearch(combinationIndex[i]) >= 0)
                        {
                            tagCount++;
                        }

                        if (tagCount > 1)
                        {
                            break;
                        }
                    }

                    if (tagCount > 1)
                    {
                        combination.State = ValueCombinationState.Excluded;
                    }

                    CachedInteraction.Combinations.Add(combination);
                }
            }

            return(new ParameterInteraction(CachedInteraction));
        }