1
Vote

There seems to be a bug in overload for generate that included values to exclude

description

/// <summary>
    /// Generates a value for the specified type
    /// that is not in a specified list of values.
    /// </summary>
    /// <typeparam name="T">The type to generate a value for.</typeparam>
    /// <param name="excludedValues">A set of values that should not be generated.</param>
    /// <returns>Returns a random value of type <typeparamref name="T" />.</returns>
    /// <exception cref="ArgumentNullException">Thrown if <paramref name="excludedValues"/> is <c>null</c>.</exception>
    public T Generate<T>(SortedSet<T> excludedValues)
    {
        if(excludedValues == null)
        {
            throw new ArgumentNullException("excludedValues");
        }
 
        var value = (T)this.Generate(typeof(T));
 
        while(excludedValues.Contains(value))
        {
            value = (T)this.Generate(typeof(T));
        }
 
        return value;
    }
 
The logic in the while seems to be broken. I created a local extention method that fixes the problem which you can lift if you want to update the library or maybe come up with something better than what I threw together. Also as a feture request could an email address generator be added as well as a way to make string values that do not just consist of a single char.
 
 
while (excludedValues.Any(s => value.ToString().Contains(s)))

comments