Example #1
0
        /// <summary>
        /// Returns an exploration strategy which restricts the coverage of vectors from a wrapped strategy.
        /// </summary>
        /// <typeparam name="T">The type of values in the dimension.</typeparam>
        /// <param name="wrappedStrategy">The wrapped strategy.</param>
        /// <param name="targetDimension">The target dimension.</param>
        /// <param name="limitedCategory">The category to restrict the coverage of.</param>
        /// <param name="maxCount">The maximum number of times to include this category in a vector.</param>
        /// <returns></returns>
        /// <example><code><![CDATA[
        /// CombinatorialStrategy baseStrategy = TestMatrix.ExhaustiveCombinatorial(Constraints);
        /// IntegerRangeCategory hugeCategory = new IntegerRangeCategory("Huge", 100000, 120000);
        /// baseStrategy.PartitionDimension(_tableSizeDimension,
        ///     new PointCategory<int>("Zero", 0),
        ///     new IntegerRangeCategory("Medium", 100, 200),
        ///     hugeCategory);
        /// // Set other dimension strategies...
        /// // Shuffle the base strategy to get different vectors each time,
        /// // then limit it to only execute one test vector with a huge table (since it'll take a big amount of time)
        /// _fullStrategy = baseStrategy.Shuffle().RestrictCoverage(_typeDimension, hugeCategory, 1);
        /// ]]></code></example>
        public static LimitCoverageStrategy RestrictCoverage <T>(this ExplorationStrategy <Vector> wrappedStrategy,
                                                                 Dimension <T> targetDimension, Category <T> limitedCategory, int maxCount)
        {
            LimitCoverageStrategy ret = new LimitCoverageStrategy(wrappedStrategy);

            ret.RestrictCategoryCoverage(targetDimension, limitedCategory, maxCount);
            return(ret);
        }
Example #2
0
 public void SetDimensionStrategy <T>(QualifiedDimension <T> dimension, ExplorationStrategy <T> strategy)
 {
     if (dimension == null)
     {
         throw new ArgumentNullException("dimension");
     }
     SetDimensionStrategyBase(dimension, strategy);
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RepeatStrategy&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="numberOfTimesToRepeat">The number of times to repeat.</param>
 public RepeatStrategy(ExplorationStrategy <T> wrappedStrategy, int numberOfTimesToRepeat)
     : base(wrappedStrategy)
 {
     if (numberOfTimesToRepeat <= 0)
     {
         throw new ArgumentOutOfRangeException("numberOfTimesToRepeat", "Must be a positive integer. Actual: " + numberOfTimesToRepeat);
     }
     _numberOfTimesToRepeat = numberOfTimesToRepeat;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilterStrategy&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="predicate">The predicate.</param>
 public FilterStrategy(ExplorationStrategy <T> wrappedStrategy, Func <T, bool> predicate)
     : base(wrappedStrategy)
 {
     if (predicate == null)
     {
         throw new ArgumentNullException("predicate");
     }
     _predicate = predicate;
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RestrictCombinationsStrategy"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="constraints">The constraints.</param>
 /// <param name="numberOfCombinationsAllowed">The number of combinations allowed.</param>
 /// <param name="targetDimensions">The target dimensions.</param>
 public RestrictCombinationsStrategy(ExplorationStrategy <Vector> wrappedStrategy, IEnumerable <IConstraint> constraints,
                                     int numberOfCombinationsAllowed, Func <int, int> nextInt, params Dimension[] targetDimensions)
     : base(wrappedStrategy)
 {
     _targetDimensions            = new List <Dimension>(targetDimensions).AsReadOnly();
     _numberOfCombinationsAllowed = numberOfCombinationsAllowed;
     _constraints = new List <IConstraint>(constraints).AsReadOnly();
     _nextInt     = nextInt;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirstNStrategy&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="numberToTake">The number to take.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="numberToTake"/> is less than or equal to 0.</exception>
 public FirstNStrategy(ExplorationStrategy <T> wrappedStrategy, int numberToTake)
     : base(wrappedStrategy)
 {
     if (numberToTake <= 0)
     {
         throw new ArgumentOutOfRangeException("numberToTake", "The number to take must be a strictly positive number");
     }
     _numberToTake = numberToTake;
 }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShuffleStrategy&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="wrappedStrategy">The wrapped strategy.</param>
        public ShuffleStrategy(ExplorationStrategy <T> wrappedStrategy, Func <int, int> nextInt)
            : base(wrappedStrategy)
        {
            if (nextInt == null)
            {
                throw new ArgumentNullException("nextInt");
            }

            _nextInt = nextInt;
        }
Example #8
0
 /// <summary>
 /// Sets the exploration strategy for the given dimension.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dimension">The dimension.</param>
 /// <param name="strategy">The strategy. Can be null which will clear out the strategy for <paramref name="dimension"/>.</param>
 /// <remarks>
 /// Strategies should be set for all the dimensions in the test matrix;
 /// except for enum and bool dimensions, which are exhaustive by default.
 /// </remarks>
 /// <exception cref="ArgumentNullException"><paramref name="dimension"/> is null.</exception>
 /// <exception cref="DimensionNotInMatrixException"><paramref name="dimension"/> is not in the target matrix.</exception>
 public void SetDimensionStrategy <T>(Dimension <T> dimension, ExplorationStrategy <T> strategy)
 {
     if (dimension == null)
     {
         throw new ArgumentNullException("dimension");
     }
     if (!_targetMatrix.Dimensions.Contains(dimension))
     {
         throw new DimensionNotInMatrixException(dimension);
     }
     SetDimensionStrategy((QualifiedDimension <T>)dimension, strategy);
 }
Example #9
0
 /// <summary>
 /// Returns an exploration strategy which groups vectors by a set of dimensions so that
 /// all vectors with the same values/categories are returned together.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="groupingDimensions">The grouping dimensions.</param>
 /// <returns></returns>
 public static ExplorationStrategy <Vector> GroupBy(this ExplorationStrategy <Vector> wrappedStrategy,
                                                    params Dimension[] groupingDimensions)
 {
     return(new GroupByStrategy(wrappedStrategy, groupingDimensions));
 }
Example #10
0
 /// <summary>
 /// Returns an exploration strategy that gives the union (with duplicate removal) of the two given strategies.
 /// </summary>
 /// <param name="firstStrategy">The first strategy.</param>
 /// <param name="secondStrategy">The second strategy.</param>
 /// <returns></returns>
 public static UnionStrategy <T> Union <T>(this ExplorationStrategy <T> firstStrategy,
                                           ExplorationStrategy <T> secondStrategy)
 {
     return(new UnionStrategy <T>(firstStrategy, secondStrategy));
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnionStrategy"/> class.
 /// </summary>
 /// <param name="firstSet">The first set.</param>
 /// <param name="secondSet">The second set.</param>
 /// <remarks>
 /// Returns an exploration strategy that always returns the UNION (with duplicate removal) of the output of two exploration strategies,
 /// where two values are considered equal if they are in the same category or if they are identical.
 /// </remarks>
 public UnionStrategy(ExplorationStrategy <Vector> firstSet, ExplorationStrategy <Vector> secondSet)
     : base(firstSet, secondSet)
 {
 }
Example #12
0
 /// <summary>
 /// Returns an exploration strategy which groups vectors by a set of dimensions so that
 /// all vectors with the same values/categories are returned together.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="groupingDimensions">The grouping dimensions.</param>
 /// <returns></returns>
 public static ExplorationStrategy <Vector> GroupBy(this ExplorationStrategy <Vector> wrappedStrategy,
                                                    IEnumerable <Dimension> groupingDimensions)
 {
     return(new GroupByStrategy(wrappedStrategy, groupingDimensions));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MakeDeterministicStrategy&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 public MakeDeterministicStrategy(ExplorationStrategy <T> wrappedStrategy)
     : base(wrappedStrategy)
 {
 }
Example #14
0
 /// <summary>
 /// Returns an exploration strategy that just repeats the values returned by the underlying strategy a set number of times.
 /// </summary>
 /// <typeparam name="T">The type of values in the dimension.</typeparam>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="numberOfTimesToRepeat">The number of times to repeat.</param>
 /// <returns></returns>
 public static RepeatStrategy <T> Repeat <T>(this ExplorationStrategy <T> wrappedStrategy, int numberOfTimesToRepeat)
 {
     return(new RepeatStrategy <T>(wrappedStrategy, numberOfTimesToRepeat));
 }
Example #15
0
 /// <summary>
 /// Returns an exploration strategy that shuffles the values returned by the underlying strategy.
 /// </summary>
 /// <typeparam name="T">The type of values in the dimension.</typeparam>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <returns></returns>
 public static ShuffleStrategy <T> Shuffle <T>(this ExplorationStrategy <T> wrappedStrategy, Func <int, int> nextInt)
 {
     return(new ShuffleStrategy <T>(wrappedStrategy, nextInt));
 }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupByStrategy"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="groupingDimensions">The grouping dimensions.</param>
 public GroupByStrategy(ExplorationStrategy <Vector> wrappedStrategy, IEnumerable <Dimension> groupingDimensions)
     : base(wrappedStrategy)
 {
     _groupingDimensions = new List <Dimension>(groupingDimensions);
 }
Example #17
0
 /// <summary>
 /// Returns an exploration strategy that gives the union (with duplicate removal) of the two given strategies.
 /// </summary>
 /// <param name="firstStrategy">The first strategy.</param>
 /// <param name="secondStrategy">The second strategy.</param>
 /// <returns></returns>
 public static UnionStrategy Union(this ExplorationStrategy <Vector> firstStrategy,
                                   ExplorationStrategy <Vector> secondStrategy)
 {
     return(new UnionStrategy(firstStrategy, secondStrategy));
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupByStrategy"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="groupingDimensions">The grouping dimensions.</param>
 public GroupByStrategy(ExplorationStrategy <Vector> wrappedStrategy, params Dimension[] groupingDimensions)
     : this(wrappedStrategy, (IEnumerable <Dimension>)groupingDimensions)
 {
 }
Example #19
0
 /// <summary>
 /// Returns an exploration strategy that gives the concatenation (no duplicate removal) of the two given strategies.
 /// </summary>
 /// <param name="firstStrategy">The first strategy.</param>
 /// <param name="secondStrategy">The second strategy.</param>
 /// <returns></returns>
 public static ConcatStrategy <T> Concat <T>(this ExplorationStrategy <T> firstStrategy,
                                             ExplorationStrategy <T> secondStrategy)
 {
     return(new ConcatStrategy <T>(firstStrategy, secondStrategy));
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConcatStrategy&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="firstStrategy">The first strategy.</param>
 /// <param name="secondStrategy">The second strategy.</param>
 public ConcatStrategy(ExplorationStrategy <T> firstStrategy, ExplorationStrategy <T> secondStrategy)
     : base(firstStrategy, secondStrategy)
 {
 }
Example #21
0
 /// <summary>
 /// Returns an exploration strategy that takes the first fixed number of elements from a wrapped strategy (or all the
 /// elements if there aren't enough to take) and just returns those.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="numberToTake">The number to take.</param>
 /// <returns></returns>
 public static FirstNStrategy <T> Take <T>(this ExplorationStrategy <T> wrappedStrategy, int numberToTake)
 {
     return(new FirstNStrategy <T>(wrappedStrategy, numberToTake));
 }
Example #22
0
 /// <summary>
 /// Returns an exploration strategy that filters values from a wrapped strategy using a given predicate.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 /// <param name="predicate">The predicate.</param>
 /// <returns></returns>
 public static FilterStrategy <T> Where <T>(this ExplorationStrategy <T> wrappedStrategy, Func <T, bool> predicate)
 {
     return(new FilterStrategy <T>(wrappedStrategy, predicate));
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LimitCoverageStrategy"/> class.
 /// </summary>
 /// <param name="wrappedStrategy">The wrapped strategy.</param>
 public LimitCoverageStrategy(ExplorationStrategy <Vector> wrappedStrategy)
     : base(wrappedStrategy)
 {
     _limitingInformation = new List <ILimitingInformation>();
 }