Exemplo n.º 1
0
        public void ZeroDetection()
        {
            StringDistribution dist1 = StringDistribution.OneOf(1.0, StringDistribution.Zero(), 0.0, StringDistribution.Any());

            Assert.True(dist1.IsZero());
            StringInferenceTestUtilities.TestProbability(dist1, 0.0, string.Empty, "a", "bc");

            StringDistribution dist2 = StringDistribution.Capitalized(2, 4).Product(StringDistribution.Any(minLength: 5, maxLength: 7));

            Assert.True(dist2.IsZero());
            StringInferenceTestUtilities.TestProbability(dist2, 0.0, string.Empty, "Abc", "Abcdef");

            StringDistribution dist3 = StringDistribution.Digits(minLength: 3, maxLength: 3).Product(StringDistribution.String("12a"));

            Assert.True(dist3.IsZero());
            StringInferenceTestUtilities.TestProbability(dist3, 0.0, string.Empty, "12a", "1", "2", "666");

            StringDistribution dist4 = StringDistribution.Any(minLength: 1, maxLength: 2).Product(StringDistribution.Any(minLength: 2, maxLength: 3).Product(StringDistribution.Any(minLength: 3, maxLength: 4)));

            Assert.True(dist4.IsZero());
            StringInferenceTestUtilities.TestProbability(dist4, 0.0, string.Empty, "a", "ab", "abc", "abcd");

            StringDistribution dist5 = StringDistribution.Any().Append(StringDistribution.Zero());

            Assert.True(dist5.IsZero());
            StringInferenceTestUtilities.TestProbability(dist5, 0.0, string.Empty, "a", "bc");

            StringDistribution dist6 = StringDistribution.Zero().Append(StringDistribution.OneOf("abc", "def"));

            Assert.True(dist6.IsZero());
            StringInferenceTestUtilities.TestProbability(dist6, 0.0, string.Empty, "a", "bc");
        }
Exemplo n.º 2
0
        public void RegexpBuildingPerformanceTest1()
        {
            Assert.Timeout(() =>
            {
                StringDistribution dist =
                    StringDistribution.OneOf(
                        StringDistribution.Lower() + StringDistribution.Upper() + StringDistribution.Optional(StringDistribution.Upper(2)),
                        StringDistribution.Digits(3) + StringDistribution.String("XXX") + StringDistribution.Letters(3, 5));

                Console.WriteLine(dist.ToString());

                ProfileAction(() => RegexpTreeBuilder.BuildRegexp(dist.GetWorkspaceOrPoint()), 6000);
            }, 10000);
        }
Exemplo n.º 3
0
        public void Digits()
        {
            var uniformOverValue           = StringDistribution.Digits(2, 3);
            var uniformOverLengthThenValue =
                StringDistribution.Digits(2, 3, DistributionKind.UniformOverLengthThenValue);

            var lp12A = uniformOverValue.GetLogProb("12");
            var lp13A = uniformOverValue.GetLogProb("123");
            var lp12B = uniformOverLengthThenValue.GetLogProb("12");
            var lp13B = uniformOverLengthThenValue.GetLogProb("123");

            Assert.Equal(1.0 / 1100, Math.Exp(lp12A), 1e-10);
            Assert.Equal(1.0 / 1100, Math.Exp(lp13A), 1e-10);
            Assert.Equal(0.5 / 100, Math.Exp(lp12B), 1e-10);
            Assert.Equal(0.5 / 1000, Math.Exp(lp13B), 1e-10);
        }