Skip to content

Commit

Permalink
Generated string should contain only 0-9, a-Z characters (#131)
Browse files Browse the repository at this point in the history
* make it work on MacOS

* Revert "make it work on MacOS"

This reverts commit dfa095d.

* generate string only which contain a-z, A-Z and 0-9 characters
  • Loading branch information
adamsitnik authored Sep 21, 2018
1 parent 4b34c30 commit c6c8759
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/benchmarks/Tests/UniqueValuesGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,20 @@ private void AssertGeneratedArraysContainAlwaysSameValues<T>(int size)
Assert.Equal(generatedArray, anotherGeneratedArray);
}
}

[Fact]
public void GeneratedStringsContainOnlySimpleLettersAndDigits()
{
var strings = ValuesGenerator.ArrayOfUniqueValues<string>(1024);

foreach (var text in strings)
{
Assert.All(text, character =>
Assert.True(
char.IsDigit(character)
|| (character >= 'a' && character <= 'z')
|| (character >= 'A' && character <= 'Z')));
}
}
}
}
11 changes: 10 additions & 1 deletion src/benchmarks/ValuesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ private static string GenerateRandomString(Random random, int minLength, int max

var builder = new StringBuilder(length);
for (int i = 0; i < length; i++)
builder.Append((char) random.Next(char.MinValue, char.MaxValue));
{
var rangeSelector = random.Next(0, 3);

if (rangeSelector == 0)
builder.Append((char) random.Next('a', 'z'));
else if (rangeSelector == 1)
builder.Append((char) random.Next('A', 'Z'));
else
builder.Append((char) random.Next('0', '9'));
}

return builder.ToString();
}
Expand Down

0 comments on commit c6c8759

Please sign in to comment.