Skip to content

Commit

Permalink
Added two unit tests specific to controlling seeds for name and sylla…
Browse files Browse the repository at this point in the history
…ble generators
  • Loading branch information
kesac committed Jun 5, 2024
1 parent d954b1e commit b51192f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Syllabore/Syllabore.Tests/NameGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}
}
}
20 changes: 20 additions & 0 deletions Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

}
}

0 comments on commit b51192f

Please sign in to comment.