Skip to content

Commit

Permalink
Merge pull request #56 from MagnusMikkelsen/master
Browse files Browse the repository at this point in the history
Document workaround for issue #26 It generates the same string being called in a sequence
  • Loading branch information
moodmosaic committed Jun 30, 2020
2 parents 703c5e2 + e79ae4d commit 11f25ba
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
16 changes: 16 additions & 0 deletions Src/Fare.Benchmarking/Benchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using BenchmarkDotNet.Attributes;

namespace Fare.Benchmarking
{
public class Benchmark
{
private readonly Random random = new Random();

[Benchmark]
public Xeger XegerCtorSimple() => new Xeger(".");

[Benchmark]
public Xeger XegerCtorInjectRandom() => new Xeger(".", this.random);
}
}
16 changes: 16 additions & 0 deletions Src/Fare.Benchmarking/Fare.Benchmarking.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fare\Fare.csproj" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions Src/Fare.Benchmarking/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BenchmarkDotNet.Running;

namespace Fare.Benchmarking
{
public class Program
{
public static void Main(string[] args)
{
BenchmarkRunner.Run<Benchmark>();
}
}
}
2 changes: 1 addition & 1 deletion Src/Fare.IntegrationTests/XegerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public XegerTests(ITestOutputHelper testOutput)
{
this._testOutput = testOutput;
}

[Theory, MemberData(nameof(RegexPatternTestCases))]
public void GeneratedTextIsCorrect(string pattern)
{
Expand Down
12 changes: 10 additions & 2 deletions Src/Fare.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2020
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fare", "Fare\Fare.csproj", "{24033E0E-0304-4F06-94CD-6F6416ECA509}"
EndProject
Expand All @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\Build.fsx = ..\Build.fsx
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fare.Benchmarking", "Fare.Benchmarking\Fare.Benchmarking.csproj", "{67368248-4A8C-4D5B-B155-4D9307634F40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,12 @@ Global
{20F5CC3B-9D71-472A-BD28-3A4C104A00E4}.Release|Any CPU.Build.0 = Release|Any CPU
{20F5CC3B-9D71-472A-BD28-3A4C104A00E4}.Verify|Any CPU.ActiveCfg = Verify|Any CPU
{20F5CC3B-9D71-472A-BD28-3A4C104A00E4}.Verify|Any CPU.Build.0 = Verify|Any CPU
{67368248-4A8C-4D5B-B155-4D9307634F40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67368248-4A8C-4D5B-B155-4D9307634F40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67368248-4A8C-4D5B-B155-4D9307634F40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67368248-4A8C-4D5B-B155-4D9307634F40}.Release|Any CPU.Build.0 = Release|Any CPU
{67368248-4A8C-4D5B-B155-4D9307634F40}.Verify|Any CPU.ActiveCfg = Debug|Any CPU
{67368248-4A8C-4D5B-B155-4D9307634F40}.Verify|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 5 additions & 2 deletions Src/Fare/Xeger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public Xeger(string regex, Random random)
}

/// <summary>
/// Initializes a new instance of the <see cref="Xeger"/> class.
/// Initializes a new instance of the <see cref="Xeger"/> class.<br/>
/// Note that if multiple instances are created within short time using this overload,<br/>
/// the instances might generate identical random strings.<br/>
/// To avoid this, use the constructor overload that accepts an argument of type Random.
/// </summary>
/// <param name="regex">The regex.</param>
public Xeger(string regex)
Expand Down Expand Up @@ -138,4 +141,4 @@ private string RemoveStartEndMarkers(string regExp)
return regExp;
}
}
}
}

0 comments on commit 11f25ba

Please sign in to comment.