Пример #1
0
        /// <summary>
        /// Sets the minimum item count used when creating collections.
        /// </summary>
        /// <param name="anon">The anon.</param>
        /// <param name="value">The value.</param>
        public static void SetMinimumItemCount(this IRegisterAnonymousData anon, int value)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(value, 0, int.MaxValue, nameof(value));

            anon.SetValue(MinItemCountKey, value);
        }
Пример #2
0
        /// <summary>
        /// Creates an anonymous <see langword="char"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="char"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static char AnyChar(this IAnonymousData anon, char minimum, char maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, char.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((char)anon.AnyInt64(minimum, maximum, distribution));
        }
Пример #3
0
        /// <summary>
        /// Creates a random <see langword="float"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="float"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static float AnySingle(this IAnonymousData anon, float minimum, float maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, float.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnySingle(minimum, maximum, Distribution.Uniform));
        }
Пример #4
0
        /// <summary>
        /// Creates a random <see langword="string"/> value with a length within the specified range using
        /// a uniform distribution algorithm for generating alpha characters.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimumLength">The minimum length.</param>
        /// <param name="maximumLength">The maximum length.</param>
        /// <returns>A random <see langword="string"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static string AnyString(this IAnonymousData anon, int minimumLength, int maximumLength)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            return(anon.AnyString(minimumLength, maximumLength, Distribution.Uniform));
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Range"/> class.
        /// </summary>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        public Range(long minimum, long maximum)
        {
            Argument.InRange(maximum, minimum, double.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            Minimum = minimum;
            Maximum = maximum;
        }
Пример #6
0
        /// <summary>
        /// Creates a random <see langword="long"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="long"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static long AnyInt64(this IAnonymousData anon, long minimum, long maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, long.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnyInt64(minimum, maximum, Distribution.Uniform));
        }
Пример #7
0
        /// <summary>
        /// Creates a random <see langword="int"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="int"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static int AnyInt32(this IAnonymousData anon, int minimum, int maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, int.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((int)anon.AnyInt64(minimum, maximum, distribution));
        }
Пример #8
0
        /// <summary>
        /// Creates a random <see langword="IEnumerable{T}"/> sequence of objects of the specified type.
        /// </summary>
        /// <typeparam name="T">The type of objects to create.</typeparam>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimumLength">The minimum length of the sequence.</param>
        /// <param name="maximumLength">The maximum length of the sequence.</param>
        /// <returns>A random <see langword="IEnumerable{T}"/> sequence of the specified type of objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static IEnumerable <T> AnyEnumerable <T>(this IAnonymousData anon, int minimumLength, int maximumLength)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            return(anon.AnyEnumerable(typeof(T), minimumLength, maximumLength).Cast <T>());
        }
Пример #9
0
        /// <summary>
        /// Creates a random <see langword="decimal"/> value using a uniform distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="decimal"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static decimal AnyDecimal(this IAnonymousData anon, decimal minimum, decimal maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, decimal.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((decimal)anon.AnyDouble((double)minimum, (double)maximum, distribution));
        }
Пример #10
0
        /// <summary>
        /// Creates a random <see langword="TimeSpan"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="TimeSpan"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static TimeSpan AnyTimeSpan(this IAnonymousData anon, TimeSpan minimum, TimeSpan maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, TimeSpan.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnyTimeSpan(minimum, maximum, Distribution.Uniform));
        }
Пример #11
0
        /// <summary>
        /// Creates an anonymous <see langword="byte"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="byte"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static byte AnyByte(this IAnonymousData anon, byte minimum, byte maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, double.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((byte)anon.AnyInt64(minimum, maximum, distribution));
        }
Пример #12
0
        /// <summary>
        /// Creates a random <see langword="DateTime"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="DateTime"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static DateTime AnyDateTime(this IAnonymousData anon, DateTime minimum, DateTime maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, DateTime.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var ticks = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution);

            return(new DateTime(ticks));
        }
Пример #13
0
        /// <summary>
        /// Creates a random <see langword="TimeSpan"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="TimeSpan"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static TimeSpan AnyTimeSpan(this IAnonymousData anon, TimeSpan minimum, TimeSpan maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, TimeSpan.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            long ticks = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution);

            return(new TimeSpan(ticks));
        }
Пример #14
0
        /// <summary>
        /// Creates a random <see langword="long"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="long"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static long AnyInt64(this IAnonymousData anon, long minimum, long maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, long.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var min = Math.Max(minimum, long.MinValue + 1);

            return(min + (long)(anon.AnyDouble(0, 1, distribution) * ((double)maximum - (double)min)));
        }
Пример #15
0
        /// <summary>
        /// Creates a random <see langword="IEnumerable"/> sequence of objects of the specified type.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="type">The type of objects to create.</param>
        /// <param name="minimumLength">The minimum length of the sequence.</param>
        /// <param name="maximumLength">The maximum length of the sequence.</param>
        /// <returns>A random <see langword="IEnumerable"/> sequence of the specified type of objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="type"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static IEnumerable AnyEnumerable(this IAnonymousData anon, Type type, int minimumLength, int maximumLength)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            int length = anon.AnyInt32(minimumLength, maximumLength);

            return(AnyEnumerable(anon, type, length));
        }
Пример #16
0
        /// <summary>
        /// Creates a random <see langword="DateTimeOffset"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="DateTimeOffset"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static DateTimeOffset AnyDateTimeOffset(this IAnonymousData anon, DateTimeOffset minimum, DateTimeOffset maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, DateTimeOffset.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var ticks  = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution);
            var offset = Offsets[anon.AnyInt32(0, Offsets.Length)];

            return(new DateTimeOffset(ticks, offset));
        }
Пример #17
0
        /// <summary>
        /// Produces and classifies values.
        /// </summary>
        /// <param name="runs">The number of values to produce.</param>
        /// <param name="producer">The delegate used to produce values.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="runs"/> is negative.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="producer"/> is null.</exception>
        public void Classify(int runs, Func <TValue> producer)
        {
            Argument.InRange(runs, 0, int.MaxValue, nameof(runs));
            Argument.NotNull(producer, nameof(producer));

            for (var i = 0; i < runs; ++i)
            {
                Classify(producer());
            }
        }
Пример #18
0
        /// <summary>
        /// Anies the specified retry attempts.
        /// </summary>
        /// <typeparam name="T">The type to create.</typeparam>
        /// <param name="anon">The anon.</param>
        /// <param name="retryAttempts">The retry attempts.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        public static T Any <T>(
            this IAnonymousData anon,
            int retryAttempts,
            Predicate <T> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(predicate, nameof(predicate));
            Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts));

            return(anon.Any <T>(PopulateOption.None, retryAttempts, predicate));
        }
Пример #19
0
            public double AnyDouble(double minimum, double maximum, Distribution distribution)
            {
                Argument.InRange(
                    maximum,
                    minimum,
                    double.MaxValue,
                    nameof(maximum),
                    "The maximum value must be greater than the minimum value.");

                return(factory.AnyDouble(minimum, maximum, distribution));
            }
Пример #20
0
        /// <summary>
        /// Creates a random double value within a specified range using the specified distribution algorithm.
        /// </summary>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random double value.</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public double AnyDouble(double minimum, double maximum, Distribution distribution)
        {
            Argument.InRange(maximum, minimum, double.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");
            if (double.IsInfinity(maximum - minimum))
            {
                throw new ArgumentOutOfRangeException($"The range of {nameof(maximum)} - {nameof(minimum)} is Infinity.");
            }

            var next = (distribution ?? Distribution.Uniform).NextDouble(this.random);

            return(minimum + (next * (maximum - minimum)));
        }
Пример #21
0
        /// <summary>
        /// Anies the specified type.
        /// </summary>
        /// <param name="anon">The anon.</param>
        /// <param name="type">The type.</param>
        /// <param name="retryAttempts">The retry attempts.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        public static object Any(
            this IAnonymousData anon,
            Type type,
            int retryAttempts,
            Predicate <object> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));
            Argument.NotNull(predicate, nameof(predicate));
            Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts));

            return(anon.Any(type, PopulateOption.None, retryAttempts, predicate));
        }
Пример #22
0
        /// <summary>
        /// Creates a random <see langword="string"/> value with a length within the specified range using
        /// the specified distribution algorithm for generating alpha characters.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimumLength">The minimum length.</param>
        /// <param name="maximumLength">The maximum length.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="string"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static string AnyString(this IAnonymousData anon, int minimumLength, int maximumLength, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            var length  = anon.AnyInt32(minimumLength, maximumLength);
            var builder = new StringBuilder(length);

            while (builder.Length < length)
            {
                builder.Append(anon.AnyAlphaChar(distribution));
            }

            return(builder.ToString());
        }
Пример #23
0
        /// <summary>
        /// Anies the specified populate option.
        /// </summary>
        /// <typeparam name="T">The type to create.</typeparam>
        /// <param name="anon">The anon.</param>
        /// <param name="populateOption">The populate option.</param>
        /// <param name="retryAttempts">The retry attempts.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        /// <exception cref="AnonymousDataException">The anonymous data was unable to be created.</exception>
        public static T Any <T>(
            this IAnonymousData anon,
            PopulateOption populateOption,
            int retryAttempts,
            Predicate <T> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(predicate, nameof(predicate));
            Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts));

            for (var i = 0; i < retryAttempts; ++i)
            {
                var result = anon.Any <T>(populateOption);
                if (predicate.Invoke(result))
                {
                    return(result);
                }
            }

            throw new AnonymousDataException(typeof(T), $"Predicate failed {retryAttempts} times.");
        }