From b51192fc305c70678f31ec46bbb0207b58b51f42 Mon Sep 17 00:00:00 2001 From: kesac Date: Tue, 4 Jun 2024 19:17:11 -0600 Subject: [PATCH] Added two unit tests specific to controlling seeds for name and syllable generators --- .../Syllabore.Tests/NameGeneratorTests.cs | 27 +++++++++++++++++++ .../Syllabore.Tests/SyllableGeneratorTests.cs | 20 ++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Syllabore/Syllabore.Tests/NameGeneratorTests.cs b/Syllabore/Syllabore.Tests/NameGeneratorTests.cs index 706ec19..52f275d 100644 --- a/Syllabore/Syllabore.Tests/NameGeneratorTests.cs +++ b/Syllabore/Syllabore.Tests/NameGeneratorTests.cs @@ -158,5 +158,32 @@ public void NameGeneration_WithSequencesOnly_Allowed() Assert.Fail(e.Message); } } + + + [TestMethod] + [DataRow(0)] + [DataRow(12345)] + public void NameGenerator_StaticRandomSeed_CreatesPredictableOutput(int seed) + { + var sutSyllables = new SyllableGenerator("aeiou", "strlmnp"); + sutSyllables.Random = new Random(seed); + + var sut = new NameGenerator(); + sut.Random = new Random(seed); + sut.UsingSyllables(sutSyllables); + + var comparisonSyllables = new SyllableGenerator("aeiou", "strlmnp"); + comparisonSyllables.Random = new Random(seed); + + var comparison = new NameGenerator(); + comparison.Random = new Random(seed); + comparison.UsingSyllables(comparisonSyllables); + + for (int i = 0; i < 1000; i++) + { + Assert.AreEqual(sut.Next(), comparison.Next()); + } + + } } } \ No newline at end of file diff --git a/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs b/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs index 634e76e..f739f93 100644 --- a/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs +++ b/Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs @@ -737,5 +737,25 @@ bool isTrailingConsonantSequenceExpected Assert.IsTrue(trailingConsonantsDetected == isTrailingConsonantSequenceExpected); } + [TestMethod] + [DataRow(0)] + [DataRow(12345)] + public void SyllableGenerator_StaticRandomSeed_CreatesPredictableOutput(int seed) + { + var sut = new SyllableGenerator("aeiou", "strlmnp"); + sut.Random = new Random(seed); + + var comparison = new SyllableGenerator("aeiou", "strlmnp"); + comparison.Random = new Random(seed); + + for (int i = 0; i < 1000; i++) + { + Assert.AreEqual(sut.NextStartingSyllable(), comparison.NextStartingSyllable()); + Assert.AreEqual(sut.NextSyllable(), comparison.NextSyllable()); + Assert.AreEqual(sut.NextEndingSyllable(), comparison.NextEndingSyllable()); + } + + } + } }