Skip to content

Commit

Permalink
1.0.17
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Nov 30, 2022
1 parent 653818f commit df8b0bc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 70 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
</PropertyGroup>

<PropertyGroup>
<VersionPrefix>1.0.16</VersionPrefix>
<LangVersion>10.0</LangVersion>
<VersionPrefix>1.0.17</VersionPrefix>
<LangVersion>11</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Generate-ReleaseNotes.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rem https://github.com/StefH/GitHubReleaseNotes

SET version=1.0.16
SET version=1.0.17

GitHubReleaseNotes --output ReleaseNotes.md --skip-empty-releases --exclude-labels question invalid doc --version %version% --token %GH_TOKEN%
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.17 (30 November 2022)
- [#26](https://github.com/StefH/RandomDataGenerator/pull/26) - Fix for non-uniform random value generators [bug] contributed by [DarekDan](https://github.com/DarekDan)
- [#25](https://github.com/StefH/RandomDataGenerator/issues/25) - Location generator distribution seems to be a bit skewed [bug]

# 1.0.16 (03 August 2022)
- [#22](https://github.com/StefH/RandomDataGenerator/pull/22) - Use static RandomValueGenerator [feature] contributed by [StefH](https://github.com/StefH)

Expand Down
137 changes: 70 additions & 67 deletions tests/RandomDataGenerator.Tests/CityRandomizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,82 @@
using RandomDataGenerator.Randomizers;
using Xunit.Abstractions;

namespace RandomDataGenerator.Tests
namespace RandomDataGenerator.Tests;

public class CityRandomizerTests
{
public class CityRandomizerTests
{
private readonly ITestOutputHelper _output;
static readonly Random random = new System.Random(420);
static readonly object randLock = new object();
private readonly ITestOutputHelper _output;
private static readonly Random Random = new(420);
private static readonly object RandLock = new();

public CityRandomizerTests(ITestOutputHelper output)
{
_output = output;
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(4)]
[InlineData(8)]
public void CityDistributionMustBeUniform(int degree)
{
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
var concurrentDictionary = new ConcurrentDictionary<string, long>();
var options = new ParallelOptions { MaxDegreeOfParallelism = degree };
Parallel.For(0, 1000, options, i =>
{
Parallel.For(0, 1000, options, j =>
{
var location = locationGenerator.Generate();
concurrentDictionary.AddOrUpdate(location, _ => 1, (k, v) => v + 1);
});
});
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();

_output.WriteLine($"{topCount}");
_output.WriteLine($"{bottomCount}");

Assert.True(topCount.Value / bottomCount.Value < 2);
Assert.NotEqual(topCount.Key, bottomCount.Key);
}

public CityRandomizerTests(ITestOutputHelper output)
{
this._output = output;
}
[Fact]
public void TwoRandomCitiesMustNotBeTheSame()
{
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
var locationOne = locationGenerator.Generate();
var locationTwo = locationGenerator.Generate();

Assert.NotEqual(locationOne, locationTwo);
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(4)]
[InlineData(8)]
public void CityDistributionMustBeUniform(int degree)
{
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
var concurrentDictionary = new ConcurrentDictionary<string, long>();
var options = new ParallelOptions { MaxDegreeOfParallelism = degree };
Parallel.For(0, 1000, options, i =>
{
Parallel.For(0, 1000, options, j =>
{
var location = locationGenerator.Generate();
concurrentDictionary.AddOrUpdate(location, _ => 1, (k, v) => v + 1);
});
});
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();
_output.WriteLine($"{topCount}");
_output.WriteLine($"{bottomCount}");
Assert.True(topCount.Value/bottomCount.Value<2);
Assert.NotEqual(topCount.Key, bottomCount.Key);
}
[Fact]
public void SystemRandomDistributionMustBeUniform()
{
var concurrentDictionary = new ConcurrentDictionary<int, long>();
Parallel.For(0, 1000, i =>
{
Parallel.For(0, 1000, j =>
{
int index;
lock (RandLock)
{
index = Random.Next(0, 2000);
}

[Fact]
public void TwoRandomCitiesMustNotBeTheSame()
{
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
var locationOne = locationGenerator.Generate();
var locationTwo = locationGenerator.Generate();
Assert.NotEqual(locationOne, locationTwo);
}
concurrentDictionary.AddOrUpdate(index, _ => 1, (k, v) => v + 1);
});
});

[Fact]
public void SystemRandomDistributionMustBeUniform()
{
var concurrentDictionary = new ConcurrentDictionary<int, long>();
Parallel.For(0, 1000, i =>
{
Parallel.For(0, 1000, j =>
{
int index;
lock (randLock)
{
index = random.Next(0, 2000);
}
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();

concurrentDictionary.AddOrUpdate(index, _ => 1, (k, v) => v + 1);
});
});
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();
_output.WriteLine($"{topCount}");
_output.WriteLine($"{bottomCount}");
Assert.True(topCount.Value / bottomCount.Value < 2);
Assert.NotEqual(topCount.Key, bottomCount.Key);
_output.WriteLine($"{topCount}");
_output.WriteLine($"{bottomCount}");

}
}
Assert.True(topCount.Value / bottomCount.Value < 2);
Assert.NotEqual(topCount.Key, bottomCount.Key);
}
}

0 comments on commit df8b0bc

Please sign in to comment.