Skip to content

Commit

Permalink
Added unit test to cover zero probability vowels:
Browse files Browse the repository at this point in the history
- When empty string generation is turned on, a SyllableGenerator should not throw any exceptions if its graphemes have been set to a zero probability of appearing
- In this scenario, a NameGenerator using a zero-probability SyllableGenerator should only be generating empty strings
  • Loading branch information
kesac committed Jan 7, 2024
1 parent 42cbed4 commit b6ea460
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Syllabore/Syllabore.Tests/SyllableGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,23 @@ public void NameGenerator_OnlyVowelsWithNoConsonants_GenerationSuccessful()
{
// Check that the name generator generates nothing but the vowels
var name = ng.Next();
Assert.IsTrue(!string.IsNullOrEmpty(name) && Regex.IsMatch(name, "^[aeiouAEIOU]+$"));
Assert.IsTrue(Regex.IsMatch(name, "^[aeiouAEIOU]+$"));
}
}

[TestMethod]
public void NameGenerator_ZeroProbabilityVowelsButEmptyStringsEnabled_GenerationSuccessful()
{
var sut = new SyllableGenerator()
.WithVowels("aeiou")
.WithProbability(x => x.OfVowels(0.0))
.AllowEmptyStrings(true);

var ng = new NameGenerator(sut);

for (int i = 0; i < 1000; i++)
{
Assert.IsTrue(ng.Next() == string.Empty);
}
}

Expand Down

0 comments on commit b6ea460

Please sign in to comment.