Skip to content

Commit df8b0bc

Browse files
committed
1.0.17
1 parent 653818f commit df8b0bc

File tree

4 files changed

+77
-70
lines changed

4 files changed

+77
-70
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
</PropertyGroup>
55

66
<PropertyGroup>
7-
<VersionPrefix>1.0.16</VersionPrefix>
8-
<LangVersion>10.0</LangVersion>
7+
<VersionPrefix>1.0.17</VersionPrefix>
8+
<LangVersion>11</LangVersion>
99
<Nullable>enable</Nullable>
1010
</PropertyGroup>
1111
</Project>

Generate-ReleaseNotes.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
rem https://github.com/StefH/GitHubReleaseNotes
22

3-
SET version=1.0.16
3+
SET version=1.0.17
44

55
GitHubReleaseNotes --output ReleaseNotes.md --skip-empty-releases --exclude-labels question invalid doc --version %version% --token %GH_TOKEN%

ReleaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.17 (30 November 2022)
2+
- [#26](https://github.com/StefH/RandomDataGenerator/pull/26) - Fix for non-uniform random value generators [bug] contributed by [DarekDan](https://github.com/DarekDan)
3+
- [#25](https://github.com/StefH/RandomDataGenerator/issues/25) - Location generator distribution seems to be a bit skewed [bug]
4+
15
# 1.0.16 (03 August 2022)
26
- [#22](https://github.com/StefH/RandomDataGenerator/pull/22) - Use static RandomValueGenerator [feature] contributed by [StefH](https://github.com/StefH)
37

tests/RandomDataGenerator.Tests/CityRandomizerTests.cs

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,82 @@
33
using RandomDataGenerator.Randomizers;
44
using Xunit.Abstractions;
55

6-
namespace RandomDataGenerator.Tests
6+
namespace RandomDataGenerator.Tests;
7+
8+
public class CityRandomizerTests
79
{
8-
public class CityRandomizerTests
9-
{
10-
private readonly ITestOutputHelper _output;
11-
static readonly Random random = new System.Random(420);
12-
static readonly object randLock = new object();
10+
private readonly ITestOutputHelper _output;
11+
private static readonly Random Random = new(420);
12+
private static readonly object RandLock = new();
13+
14+
public CityRandomizerTests(ITestOutputHelper output)
15+
{
16+
_output = output;
17+
}
18+
19+
[Theory]
20+
[InlineData(1)]
21+
[InlineData(2)]
22+
[InlineData(4)]
23+
[InlineData(8)]
24+
public void CityDistributionMustBeUniform(int degree)
25+
{
26+
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
27+
var concurrentDictionary = new ConcurrentDictionary<string, long>();
28+
var options = new ParallelOptions { MaxDegreeOfParallelism = degree };
29+
Parallel.For(0, 1000, options, i =>
30+
{
31+
Parallel.For(0, 1000, options, j =>
32+
{
33+
var location = locationGenerator.Generate();
34+
concurrentDictionary.AddOrUpdate(location, _ => 1, (k, v) => v + 1);
35+
});
36+
});
37+
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
38+
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();
39+
40+
_output.WriteLine($"{topCount}");
41+
_output.WriteLine($"{bottomCount}");
42+
43+
Assert.True(topCount.Value / bottomCount.Value < 2);
44+
Assert.NotEqual(topCount.Key, bottomCount.Key);
45+
}
1346

14-
public CityRandomizerTests(ITestOutputHelper output)
15-
{
16-
this._output = output;
17-
}
47+
[Fact]
48+
public void TwoRandomCitiesMustNotBeTheSame()
49+
{
50+
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
51+
var locationOne = locationGenerator.Generate();
52+
var locationTwo = locationGenerator.Generate();
1853

54+
Assert.NotEqual(locationOne, locationTwo);
55+
}
1956

20-
[Theory]
21-
[InlineData(1)]
22-
[InlineData(2)]
23-
[InlineData(4)]
24-
[InlineData(8)]
25-
public void CityDistributionMustBeUniform(int degree)
26-
{
27-
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
28-
var concurrentDictionary = new ConcurrentDictionary<string, long>();
29-
var options = new ParallelOptions { MaxDegreeOfParallelism = degree };
30-
Parallel.For(0, 1000, options, i =>
31-
{
32-
Parallel.For(0, 1000, options, j =>
33-
{
34-
var location = locationGenerator.Generate();
35-
concurrentDictionary.AddOrUpdate(location, _ => 1, (k, v) => v + 1);
36-
});
37-
});
38-
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
39-
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();
40-
_output.WriteLine($"{topCount}");
41-
_output.WriteLine($"{bottomCount}");
42-
Assert.True(topCount.Value/bottomCount.Value<2);
43-
Assert.NotEqual(topCount.Key, bottomCount.Key);
44-
}
57+
[Fact]
58+
public void SystemRandomDistributionMustBeUniform()
59+
{
60+
var concurrentDictionary = new ConcurrentDictionary<int, long>();
61+
Parallel.For(0, 1000, i =>
62+
{
63+
Parallel.For(0, 1000, j =>
64+
{
65+
int index;
66+
lock (RandLock)
67+
{
68+
index = Random.Next(0, 2000);
69+
}
4570

46-
[Fact]
47-
public void TwoRandomCitiesMustNotBeTheSame()
48-
{
49-
var locationGenerator = RandomizerFactory.GetRandomizer(new FieldOptionsCity { ValueAsString = true, UseNullValues = false });
50-
var locationOne = locationGenerator.Generate();
51-
var locationTwo = locationGenerator.Generate();
52-
Assert.NotEqual(locationOne, locationTwo);
53-
}
71+
concurrentDictionary.AddOrUpdate(index, _ => 1, (k, v) => v + 1);
72+
});
73+
});
5474

55-
[Fact]
56-
public void SystemRandomDistributionMustBeUniform()
57-
{
58-
var concurrentDictionary = new ConcurrentDictionary<int, long>();
59-
Parallel.For(0, 1000, i =>
60-
{
61-
Parallel.For(0, 1000, j =>
62-
{
63-
int index;
64-
lock (randLock)
65-
{
66-
index = random.Next(0, 2000);
67-
}
75+
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
76+
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();
6877

69-
concurrentDictionary.AddOrUpdate(index, _ => 1, (k, v) => v + 1);
70-
});
71-
});
72-
var topCount = concurrentDictionary.OrderByDescending(pair => pair.Value).First();
73-
var bottomCount = concurrentDictionary.OrderBy(pair => pair.Value).First();
74-
_output.WriteLine($"{topCount}");
75-
_output.WriteLine($"{bottomCount}");
76-
Assert.True(topCount.Value / bottomCount.Value < 2);
77-
Assert.NotEqual(topCount.Key, bottomCount.Key);
78+
_output.WriteLine($"{topCount}");
79+
_output.WriteLine($"{bottomCount}");
7880

79-
}
80-
}
81+
Assert.True(topCount.Value / bottomCount.Value < 2);
82+
Assert.NotEqual(topCount.Key, bottomCount.Key);
83+
}
8184
}

0 commit comments

Comments
 (0)