Add a test with large automaton

This commit is contained in:
Ivan Korostelev 2019-09-17 13:58:23 +01:00
Родитель 5fdb6c0779
Коммит 2d5ce49ea3
1 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -847,6 +847,40 @@ namespace Microsoft.ML.Probabilistic.Tests
}
}
/// <summary>
/// Tests whether the point mass computation operations fails due to a stack overflow when an automaton becomes sufficiently large.
/// </summary>
[Fact]
[Trait("Category", "StringInference")]
public void IsZeroLargeAutomaton()
{
using (var unlimited = new StringAutomaton.UnlimitedStatesComputation())
{
var zeroAutomaton = MakeAutomaton(Weight.Zero);
var nonZeroAutomaton = MakeAutomaton(Weight.One);
Assert.True(zeroAutomaton.IsZero());
Assert.False(nonZeroAutomaton.IsZero());
}
StringAutomaton MakeAutomaton(Weight endWeight)
{
const int StateCount = 100_000;
var builder = new StringAutomaton.Builder();
var state = builder.Start;
for (var i = 1; i < StateCount; ++i)
{
state = state.AddTransition('a', Weight.One);
}
state.SetEndWeight(endWeight);
return builder.GetAutomaton();
}
}
/// <summary>
/// Tests creating an automaton from state and transition lists.
/// </summary>