GetRandomizer() public static method

Get a randomizer for a particular member, returning one that has already been created if it exists. This ensures that the same values are generated each time the tests are reloaded.
public static GetRandomizer ( MemberInfo member ) : Randomizer
member System.Reflection.MemberInfo
return Randomizer
Beispiel #1
0
            public override IEnumerable GetData(IParameterInfo parameter)
            {
                Guard.ArgumentValid(parameter.ParameterType.GetTypeInfo().IsEnum, "EnumDataSource requires an enum parameter", "parameter");

                Randomizer randomizer = Randomizer.GetRandomizer(parameter.ParameterInfo);

                DataType = parameter.ParameterType;

                int valueCount = Enum.GetValues(DataType).Cast <int>().Distinct().Count();

                Guard.OperationValid(!(Distinct && _count > valueCount), $"The enum \"{DataType.Name}\" has {valueCount} values and the random value count is {_count} so the values cannot be distinct.");

                for (int i = 0; i < _count; i++)
                {
                    if (Distinct)
                    {
                        object next;

                        do
                        {
                            next = randomizer.NextEnum(parameter.ParameterType);
                        } while (previousValues.Contains(next));

                        previousValues.Add(next);

                        yield return(next);
                    }
                    else
                    {
                        yield return(randomizer.NextEnum(parameter.ParameterType));
                    }
                }
            }
        /// <summary>
        /// Get the collection of values to be used as arguments
        /// </summary>
        public override IEnumerable GetData(ParameterInfo parameter)
        {
            Randomizer r = Randomizer.GetRandomizer(parameter);
            IList      values;

            switch (sampleType)
            {
            default:
            case SampleType.Raw:
                values = r.GetDoubles(count);
                break;

            case SampleType.IntRange:
                values = r.GetInts(min, max, count);
                break;

            case SampleType.DoubleRange:
                values = r.GetDoubles(dmin, dmax, count);
                break;
            }

            // Copy the random values into the data array
            // and call the base class which may need to
            // convert them to another type.
            this.data = new object[values.Count];
            for (int i = 0; i < values.Count; i++)
            {
                this.data[i] = values[i];
            }

            return(base.GetData(parameter));
        }
Beispiel #3
0
            public override IEnumerable GetData(IParameterInfo parameter)
            {
                //Guard.ArgumentValid(parameter.ParameterType == typeof(T), "Parameter type must be " + typeof(T).Name, "parameter");

                var randomizer = Randomizer.GetRandomizer(parameter.ParameterInfo);

                Guard.OperationValid(CanUseRange() || !_inRange, $"The value type {parameter.ParameterType} does not support range of values.");
                Guard.OperationValid(!(Distinct && _inRange && !CanBeDistinct(_min !, _max !, _count)), $"The range of values is [{_min}, {_max}[ and the random value count is {_count} so the values cannot be distinct.");


                for (int i = 0; i < _count; i++)
                {
                    if (Distinct)
                    {
                        T next;

                        do
                        {
                            next = _inRange
                                ? GetNext(randomizer, _min !, _max !)
                                : GetNext(randomizer);
                        } while (previousValues.Contains(next));

                        previousValues.Add(next);

                        yield return(next);
                    }
                    else
                    {
                        yield return(_inRange
                            ? GetNext(randomizer, _min !, _max !)
                            : GetNext(randomizer));
                    }
                }
            }
        public new IEnumerable GetData(ParameterInfo parameter)
        {
            Randomizer randomizer = Randomizer.GetRandomizer(parameter);
            IList      list;

            switch (sampleType)
            {
            default:
                list = randomizer.GetDoubles(count);
                break;

            case SampleType.IntRange:
                list = randomizer.GetInts(min, max, count);
                break;

            case SampleType.DoubleRange:
                list = randomizer.GetDoubles(dmin, dmax, count);
                break;
            }
            data = new object[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                data[i] = list[i];
            }
            return(base.GetData(parameter));
        }
Beispiel #5
0
            public override IEnumerable GetData(IParameterInfo parameter)
            {
                Guard.ArgumentValid(parameter.ParameterType.GetTypeInfo().IsEnum, "EnumDataSource requires an enum parameter", "parameter");

                Randomizer randomizer = Randomizer.GetRandomizer(parameter.ParameterInfo);

                DataType = parameter.ParameterType;

                for (int i = 0; i < _count; i++)
                {
                    yield return(randomizer.NextEnum(parameter.ParameterType));
                }
            }
        /// <summary>
        /// Get the collection of values to be used as arguments
        /// </summary>
        public override IEnumerable GetData(ParameterInfo parameter)
        {
            Randomizer r = Randomizer.GetRandomizer(parameter);

            switch (sampleType)
            {
            default:
            case SampleType.Raw:
                return(r.GetDoubles(count));

            case SampleType.IntRange:
                return(r.GetInts(min, max, count));

            case SampleType.DoubleRange:
                return(r.GetDoubles(dmin, dmax, count));
            }
        }