Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Repeatable Results by Preserving Insert Order in Unique Array Generation Methods #4586

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ public static T[] ArrayOfUniqueValues<T>(int count)
{
T value = GenerateValue<T>(random);

if (!uniqueValues.Contains(value))
uniqueValues.Add(value);
if (uniqueValues.Add(value))
result[uniqueValues.Count - 1] = value;
}

uniqueValues.CopyTo(result);

return result;
}

Expand Down Expand Up @@ -178,9 +176,10 @@ public static string[] ArrayOfUniqueStrings(int count, int minLength, int maxLen

while (unique.Count != count)
{
unique.Add(GenerateRandomString(random, minLength, maxLength));
string randomString = GenerateRandomString(random, minLength, maxLength);
if (unique.Add(randomString))
strings[unique.Count - 1] = randomString;
}
unique.CopyTo(strings);
return strings;
}

Expand Down
Loading