Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TwoDimensionalConstraint&lt;FirstDomainType, SecondDomainType&gt;"/> class.
 /// </summary>
 /// <param name="firstDimension">The first dimension.</param>
 /// <param name="secondDimension">The second dimension.</param>
 /// <param name="thirdDimension">The third dimension.</param>
 /// <param name="validator">The validator method to use.</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null.</exception>
 public ThreeDimensionalConstraint(QualifiedDimension <TFirstDomainType> firstDimension,
                                   QualifiedDimension <TSecondDomainType> secondDimension, QualifiedDimension <TThirdDomainType> thirdDimension,
                                   ThreeDimensionalValidator <TFirstDomainType, TSecondDomainType, TThirdDomainType> validator)
 {
     if (firstDimension == null)
     {
         throw new ArgumentNullException("firstDimension");
     }
     if (secondDimension == null)
     {
         throw new ArgumentNullException("secondDimension");
     }
     if (thirdDimension == null)
     {
         throw new ArgumentNullException("thirdDimension");
     }
     if (validator == null)
     {
         throw new ArgumentNullException("validator");
     }
     _firstDimension     = firstDimension;
     _secondDimension    = secondDimension;
     _thirdDimension     = thirdDimension;
     _validator          = validator;
     _requiredDimensions = new List <QualifiedDimension>()
     {
         _firstDimension, _secondDimension, _thirdDimension
     }.AsReadOnly();
 }
Esempio n. 2
0
 private void SetDefaultStrategies(IEnumerable <Matrix> path, Matrix targetMatrix)
 {
     foreach (Dimension dim in targetMatrix.Dimensions)
     {
         Matrix asMatrix;
         Type   underlyingType = Nullable.GetUnderlyingType(dim.Domain) ?? dim.Domain;
         if (underlyingType.IsEnum())
         {
             _explorationStrategies.Add(QualifiedDimension.Create(dim, path),
                                        (IExplorationStrategy)typeof(ExhaustiveEnumStrategy <>).MakeGenericType(dim.Domain).GetInstanceConstructor(true, new Type[0]).Invoke(null));
         }
         else if (typeof(bool).Equals(dim.Domain))
         {
             _explorationStrategies.Add(QualifiedDimension.Create(dim, path), new ExhaustiveIEnumerableStrategy <bool>(true, false));
         }
         else if (typeof(bool?).Equals(dim.Domain))
         {
             _explorationStrategies.Add(QualifiedDimension.Create(dim, path), new ExhaustiveIEnumerableStrategy <bool?>(true, false, null));
         }
         else if ((asMatrix = dim as Matrix) != null)
         {
             SetDefaultStrategies(path.Concat(Enumerable.Repeat(asMatrix, 1)), asMatrix);
         }
     }
 }
Esempio n. 3
0
        private void SetDimensionStrategyBase(QualifiedDimension dimension, IExplorationStrategy strategy)
        {
            Matrix        currentMatrix = _targetMatrix;
            List <Matrix> innerPath     = new List <Matrix>();

            foreach (Matrix innerMatrix in dimension.Path)
            {
                if (!currentMatrix.Dimensions.Contains(innerMatrix))
                {
                    throw new DimensionNotInMatrixException(innerMatrix);
                }
                if (strategy != null)
                {
                    _explorationStrategies.Remove(QualifiedDimension.Create(innerMatrix, innerPath));
                }
                currentMatrix = innerMatrix;
                innerPath.Add(innerMatrix);
            }
            if (strategy == null)
            {
                _explorationStrategies.Remove(dimension);
            }
            else if (_explorationStrategies.ContainsKey(dimension))
            {
                _explorationStrategies[dimension] = strategy;
            }
            else
            {
                _explorationStrategies.Add(dimension, strategy);
            }
        }
Esempio n. 4
0
 public void SetDimensionStrategy <T>(QualifiedDimension <T> dimension, ExplorationStrategy <T> strategy)
 {
     if (dimension == null)
     {
         throw new ArgumentNullException("dimension");
     }
     SetDimensionStrategyBase(dimension, strategy);
 }
Esempio n. 5
0
 /// <summary>
 /// (Internal usage) Gets the current exploration strategy for the given dimension.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <returns>
 /// The strategy set for the dimension, or null if none found.
 /// </returns>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null.</exception>
 public IExplorationStrategy GetBaseDimensionStrategy(Dimension dimension)
 {
     if (dimension == null)
     {
         throw new ArgumentNullException("dimension");
     }
     return(GetBaseDimensionStrategy(QualifiedDimension.Create(dimension)));
 }
Esempio n. 6
0
 /// <summary>
 /// (Internal use) Gets the value of the given dimension in a non-generic way.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
 /// <exception cref="KeyNotFoundException">No value was ever set for this dimension.</exception>
 internal object GetBaseValue(QualifiedDimension dimension)
 {
     if (dimension.Path.Any())
     {
         return(GetValue(dimension.Path[0]).GetBaseValue(QualifiedDimension.Create(dimension.BaseDimension, dimension.Path.Skip(1))));
     }
     else
     {
         return(GetBaseValue(dimension.BaseDimension));
     }
 }
 /// <summary>
 /// Special constructors for sub-classes that just want to override <see cref="IsValidValue"/> instead of providing a delegate.
 /// </summary>
 /// <param name="targetDimension"></param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null.</exception>
 protected OneDimensionalConstraint(QualifiedDimension <T> targetDimension)
 {
     if (targetDimension == null)
     {
         throw new ArgumentNullException("targetDimension");
     }
     _targetDimension    = targetDimension;
     _validator          = null;
     _requiredDimensions = new List <QualifiedDimension>()
     {
         _targetDimension
     }.AsReadOnly();
 }
Esempio n. 8
0
 /// <summary>
 /// (Internal use) Gets the category from which the value of the given dimension was chosen (can be null if it wasn't from a categorical exploration).
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <returns></returns>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
 internal Category GetBaseCategory(QualifiedDimension dimension)
 {
     if (dimension == null)
     {
         throw new ArgumentNullException("dimension");
     }
     if (dimension.Path.Any())
     {
         return(GetValue(dimension.Path[0]).GetBaseCategory(QualifiedDimension.Create(dimension.BaseDimension, dimension.Path.Skip(1))));
     }
     else
     {
         return(GetBaseCategory(dimension.BaseDimension));
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OneDimensionalConstraint&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="targetDimension">The target dimension.</param>
 /// <param name="validator">The validator.</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null.</exception>
 public OneDimensionalConstraint(QualifiedDimension <T> targetDimension, OneDimensionalValidator <T> validator)
 {
     if (targetDimension == null)
     {
         throw new ArgumentNullException("targetDimension");
     }
     if (validator == null)
     {
         throw new ArgumentNullException("validator");
     }
     _targetDimension    = targetDimension;
     _validator          = validator;
     _requiredDimensions = new List <QualifiedDimension>()
     {
         _targetDimension
     }.AsReadOnly();
 }
Esempio n. 10
0
        private static int GetIndexOfDimension(QualifiedDimension targetDimension, ReadOnlyCollection <DimensionWithValues> dimensionValues,
                                               string origin)
        {
            int ret = 0;

            foreach (DimensionWithValues dv in dimensionValues)
            {
                if (targetDimension.Equals(dv.Dimension))
                {
                    return(ret);
                }
                ret++;
            }
            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                              "Dimension {0} from {1} was not found in the explored matrix (all dimensions: {2}).",
                                                              targetDimension.FullyQualifiedName, origin, string.Join(",", dimensionValues.Select(dv => dv.Dimension.FullyQualifiedName))));
        }
Esempio n. 11
0
        /// <summary>
        /// (Internal usage) Gets the current exploration strategy for the given dimension.
        /// </summary>
        /// <param name="dimension">The dimension.</param>
        /// <returns>
        /// The strategy set for the dimension, or null if none found.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null.</exception>
        public IExplorationStrategy GetBaseDimensionStrategy(QualifiedDimension dimension)
        {
            if (dimension == null)
            {
                throw new ArgumentNullException("dimension");
            }
            IExplorationStrategy ret;

            if (_explorationStrategies.TryGetValue(dimension, out ret))
            {
                return(ret);
            }
            else
            {
                return(null);
            }
        }
        private static int GetIndexOfConstraintDimension(IConstraint constraint, ReadOnlyCollection <DimensionWithValues> dimensionValues,
                                                         QualifiedDimension dimension)
        {
            int ret = 0;

            foreach (DimensionWithValues dv in dimensionValues)
            {
                if (IsSubset(dimension, dv.Dimension))
                {
                    return(ret);
                }
                ret++;
            }
            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                              "Dimension {0} from constraint {1} was not found in the matrix (all dimensions: {2}).",
                                                              dimension.FullyQualifiedName, constraint.GetType().Name, string.Join(",", dimensionValues.Select(dv => dv.Dimension.FullyQualifiedName))));
        }
Esempio n. 13
0
        /// <summary>
        /// Determines whether this vector has a value for the specified dimension.
        /// </summary>
        /// <param name="dimension">The dimension.</param>
        /// <returns>
        ///     <c>true</c> if the vector has a value for the dimension; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
        public bool HasValue(QualifiedDimension dimension)
        {
            if (dimension == null)
            {
                throw new ArgumentNullException("dimension");
            }
            Vector innerVector = this;

            foreach (Matrix innerMatrix in dimension.Path)
            {
                if (!innerVector.HasValue(innerMatrix))
                {
                    return(false);
                }
                innerVector = innerVector.GetValue(innerMatrix);
            }
            return(innerVector._dimensionValues.ContainsKey(dimension.BaseDimension));
        }
Esempio n. 14
0
 /// <summary>
 /// Checks that all dimensions have exploration strategies.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="targetMatrix">The target matrix.</param>
 /// <exception cref="DimensionStrategyNotSetException">Any dimension found with no corresponding strategy.</exception>
 private void CheckAllDimensionsHaveExplorationStrategies(IEnumerable <Matrix> path, Matrix targetMatrix)
 {
     foreach (Dimension dimension in targetMatrix.Dimensions)
     {
         if (!_explorationStrategies.ContainsKey(QualifiedDimension.Create(dimension, path)))
         {
             Matrix asMatrix;
             if ((asMatrix = dimension as Matrix) != null)
             {
                 CheckAllDimensionsHaveExplorationStrategies(path.Concat(Enumerable.Repeat(asMatrix, 1)), asMatrix);
             }
             else
             {
                 throw new DimensionStrategyNotSetException(dimension);
             }
         }
     }
 }
Esempio n. 15
0
 /// <summary>
 /// Special constructors for sub-classes that just want to override <see cref="IsValidValue"/> instead of providing a delegate.
 /// </summary>
 /// <param name="firstDimension">The first dimension.</param>
 /// <param name="secondDimension">The second dimension.</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null.</exception>
 protected TwoDimensionalConstraint(QualifiedDimension <TFirstDomainType> firstDimension,
                                    QualifiedDimension <TSecondDomainType> secondDimension)
 {
     if (firstDimension == null)
     {
         throw new ArgumentNullException("firstDimension");
     }
     if (secondDimension == null)
     {
         throw new ArgumentNullException("secondDimension");
     }
     _firstDimension     = firstDimension;
     _secondDimension    = secondDimension;
     _validator          = null;
     _requiredDimensions = new List <QualifiedDimension>()
     {
         _firstDimension, _secondDimension
     }.AsReadOnly();
 }
Esempio n. 16
0
        /// <summary>
        /// Gets all individual dimension values.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="targetMatrix">The target matrix.</param>
        /// <returns></returns>
        /// <exception cref="DimensionStrategyNotSetException">Any dimension found with no corresponding strategy.</exception>
        private ReadOnlyCollection <DimensionWithValues> GetAllDimensionValues(IEnumerable <Matrix> path, Matrix targetMatrix)
        {
            CheckAllDimensionsHaveExplorationStrategies();
            List <DimensionWithValues> ret = new List <DimensionWithValues>(targetMatrix.Dimensions.Count);

            foreach (Dimension dimension in targetMatrix.Dimensions)
            {
                QualifiedDimension QualifiedDimension = QualifiedDimension.Create(dimension, path);
                if (_explorationStrategies.ContainsKey(QualifiedDimension))
                {
                    ret.Add(new DimensionWithValues(QualifiedDimension, GetValues(GetBaseDimensionStrategy(QualifiedDimension))));
                }
                else
                {
                    Matrix asMatrix = (Matrix)dimension;
                    ret.AddRange(GetAllDimensionValues(path.Concat(Enumerable.Repeat(asMatrix, 1)), asMatrix));
                }
            }
            return(ret.AsReadOnly());
        }
Esempio n. 17
0
        /// <summary>
        /// Imports the dimension exploration strategies for the given innner matrix found with the given source combinatorial strategy.
        /// </summary>
        /// <param name="innerMatrixPath">The inner matrix path.</param>
        /// <param name="sourceStrategy">The source strategy.</param>
        /// <remarks>
        /// This is useful for exploring dimensions from a sub-matrix in the same strategy, which is useful e.g. for doing pairwise coverage
        /// across sub-matrix boundaries.
        /// </remarks>
        /// <returns>The number of strategies imported.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="sourceStrategy"/> is null.</exception>
        public int ImportSubMatrixStrategies(IEnumerable <Matrix> innerMatrixPath, CombinatorialStrategy sourceStrategy)
        {
            if (sourceStrategy == null)
            {
                throw new ArgumentNullException("sourceStrategy");
            }
            if (innerMatrixPath == null || innerMatrixPath.Any(m => m == null))
            {
                throw new ArgumentNullException("innerMatrixPath");
            }
            int ret = 0;

            foreach (KeyValuePair <QualifiedDimension, IExplorationStrategy> dimStrategy in sourceStrategy._explorationStrategies)
            {
                SetDimensionStrategyBase(QualifiedDimension.Create(dimStrategy.Key.BaseDimension,
                                                                   innerMatrixPath.Concat(dimStrategy.Key.Path)), dimStrategy.Value);
                ret++;
            }
            _constraints.AddRange(sourceStrategy._constraints.Select <IConstraint, IConstraint>(c => new InnerSubMatrixWrapperConstraint(c, innerMatrixPath)));
            return(ret);
        }
Esempio n. 18
0
 /// <summary>
 /// (Internal use/required for VectorInfo) Sets the value for the given dimension.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <param name="value">The value.</param>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
 internal void SetBaseValue(QualifiedDimension dimension, ValueFactoryWithOptionalConcreteValue value)
 {
     if (dimension.Path.Any())
     {
         Vector innerVector;
         ValueFactoryWithOptionalConcreteValue valueFactory;
         if (_dimensionValues.TryGetValue(dimension.Path[0], out valueFactory))
         {
             innerVector = (Vector)valueFactory.MakeConcrete().GetConcreteValue();
         }
         else
         {
             innerVector = new Vector();
             SetBaseValue(dimension.Path[0], innerVector);
         }
         innerVector.SetBaseValue(QualifiedDimension.Create(dimension.BaseDimension, dimension.Path.Skip(1)), value);
     }
     else
     {
         _dimensionValues[dimension.BaseDimension] = value;
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Gets the value of the given dimension.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <returns>The value of the dimension.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
 /// <exception cref="KeyNotFoundException">No value was ever set for this dimension.</exception>
 public object GetValue(QualifiedDimension dimension)
 {
     return(GetBaseValue(dimension));
 }
Esempio n. 20
0
            public bool IsValid(Vector target)
            {
                Vector innerVector = target.GetValue(QualifiedDimension.Create(_path.Last(), _path.Take(_path.Count - 1)));

                return(_innerConstraint.IsValid(innerVector));
            }
 private static bool IsSubset(QualifiedDimension superset, QualifiedDimension subset)
 {
     return(superset.Path.Count >= subset.Path.Count &&
            superset.FullPath.Take(subset.FullPath.Count()).SequenceEqual(subset.FullPath));
 }
Esempio n. 22
0
 public ExplorationStrategy <T> GetDimensionStrategy <T>(QualifiedDimension <T> dimension)
 {
     return((ExplorationStrategy <T>)(GetBaseDimensionStrategy(dimension)));
 }
Esempio n. 23
0
 public Category <T> GetCategory <T>(QualifiedDimension <T> dimension)
 {
     return((Category <T>)GetBaseCategory(dimension));
 }
Esempio n. 24
0
 public void SetValue <T>(QualifiedDimension <T> dimension, T value)
 {
     SetBaseValue(dimension, value);
 }
Esempio n. 25
0
 public void SetValue <T>(QualifiedDimension <T> dimension, T value, Category <T> category)
 {
     SetBaseValue(dimension, value, category);
 }
Esempio n. 26
0
 /// <summary>
 /// (Internal use/required for VectorInfo) Sets the value for the given dimension, associating it with a category.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <param name="value">The value.</param>
 /// <param name="category">The category. Can be null.</param>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
 internal void SetBaseValue(QualifiedDimension dimension, object value, Category category)
 {
     SetBaseValue(dimension, new ValueFactoryWithOptionalConcreteValue(
                      category == null ? new SingleValueFactory(value) : (IValueFactory)category,
                      value));
 }
        private static IEnumerable <QualifiedDimension> ExpandOuterMatrixDimensionIfNeeded(QualifiedDimension toExpand, ReadOnlyCollection <DimensionWithValues> dimensionValues)
        {
            IEnumerable <QualifiedDimension> ret = dimensionValues.Select(dv => dv.Dimension).Where(d => IsSubset(d, toExpand));

            if (toExpand.BaseDimension is Matrix && ret.Any())
            {
                return(ret);
            }
            else
            {
                return(Enumerable.Repeat(toExpand, 1));
            }
        }
Esempio n. 28
0
 /// <summary>
 /// (Internal use/required for VectorInfo) Sets the value for the given dimension.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <param name="value">The value.</param>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null</exception>
 internal void SetBaseValue(QualifiedDimension dimension, object value)
 {
     SetBaseValue(dimension, new ValueFactoryWithOptionalConcreteValue(new SingleValueFactory(value), value));
 }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DimensionWithValues"/> struct.
 /// </summary>
 /// <param name="dimension">The dimension.</param>
 /// <param name="values">The values.</param>
 public DimensionWithValues(QualifiedDimension dimension, IEnumerable <ValueFactoryWithOptionalConcreteValue> values)
 {
     _dimension = dimension;
     _values    = new List <ValueFactoryWithOptionalConcreteValue>(values);
 }
Esempio n. 30
0
 /// <summary>
 /// Sets the exploration strategy for the given dimension to a categorical strategy with the given categories defined.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dimension"></param>
 /// <param name="allCategories"></param>
 /// <exception cref="ArgumentNullException">Any of the parameters is null.</exception>
 /// <exception cref="DimensionNotInMatrixException"><paramref name="dimension"/> is not in the target matrix.</exception>
 /// <example><code><![CDATA[
 /// _fullStrategy.PartitionDimension(_dataTypeDimension,
 ///	new PointCategory<PimodType>("String", PimodType.VarChar(20), PimodType.NVarChar(10), PimodType.Char(5), PimodType.NChar(50)),
 ///	new PointCategory<PimodType>("Integer", PimodType.TinyInt(), PimodType.SmallInt(), PimodType.Int(), PimodType.BigInt()));
 ///_fullStrategy.PartitionDimension(_tableSizeDimension,
 ///	new PointCategory<int>("OneRow", 1),
 ///	new IntegerRangeCategory("Small", 10, 20),
 ///	new IntegerRangeCategory("Large", 10000, 15000));
 /// ]]></code></example>
 public void PartitionDimension <T>(QualifiedDimension <T> dimension, params Category <T>[] allCategories)
 {
     SetDimensionStrategy(dimension, new CategoricalStrategy <T>(allCategories));
 }