BuildExpressionFactoryRecursively(Boolean directlyToTheRightOfABinaryOperator)
        {
            var binaryOperatorExpressionFactory =
                Synthesis.Create(
                    Deferral.Create(
                        () =>
                        BuildExpressionFactoryRecursively(
                            directlyToTheRightOfABinaryOperator)),
                    Deferral.Create(() => BuildExpressionFactoryRecursively(true)),
                    BinaryOperatorFactory, BinaryExpressionFrom);

            var negatedExpressionFactory =
                Synthesis.Create(
                    Deferral.Create(() => BuildExpressionFactoryRecursively(true)),
                    expression =>
                    Tuple.Create(expression.Item1,
                                 String.Format(
                                     directlyToTheRightOfABinaryOperator ? "(-{0})" : "-{0}",
                                     expression.Item2)));

            var bracketedExpressionFactory =
                Synthesis.Create(
                    Deferral.Create(() => BuildExpressionFactoryRecursively(false)),
                    expression =>
                    Tuple.Create(false, String.Format("({0})", expression.Item2)));

            return
                (Interleaving.Create(new[]
            {
                ConstantFactory, binaryOperatorExpressionFactory,
                negatedExpressionFactory, bracketedExpressionFactory
            }));
        }
예제 #2
0
        public ITypedFactory <String> BuildFactoryRecursivelyUsingDeferral()
        {
            var simplerFactoryForShorterStrings =
                Deferral.Create(BuildFactoryRecursivelyUsingDeferral);

            var factoryForNonEmptyStrings = Synthesis.Create(
                _factoryForSingleCharacters, simplerFactoryForShorterStrings,
                (leftmostCharacterToPrepend, shorterString) =>
                leftmostCharacterToPrepend + shorterString);

            return
                (Interleaving.Create(new[]
                                     { _emptyStringFactory, factoryForNonEmptyStrings }));
        }
        public ITypedFactory <IEnumerable <ThingHistory> > HistoriesForSeveralThingsFactory(int minimumNumberOfThings = 1)
        {
            var historiesForSeveralThingsFactory = Synthesis.Create(
                from thingRecordIndex in Enumerable.Range(0, minimumNumberOfThings)
                select ThingFactory(thingRecordIndex, minimumNumberOfThings))
                                                   .WithFilter(ThingsShareItemsEfficiently(minimumNumberOfThings));

            return
                (Interleaving.Create(new[]
            {
                historiesForSeveralThingsFactory,
                Deferral.Create(() => HistoriesForSeveralThingsFactory(1 + minimumNumberOfThings))
            }));
        }
        private static ITypedFactory <TestCase> BuildTestCaseFactory(Int32 numberOfVertices)
        {
            var connectionsFactory =
                BuildConnectionsFactory(numberOfVertices)
                .WithFilter(dictionary => ConnectionsImplyADag(dictionary, numberOfVertices));

            var testCaseFactory = Synthesis.Create(connectionsFactory,
                                                   connections => new TestCase()
            {
                NumberOfVertices = numberOfVertices, Connections = connections
            });

            return
                (Interleaving.Create(new[]
                                     { testCaseFactory, Deferral.Create(() => BuildTestCaseFactory(1 + numberOfVertices)) }));
        }
        private static ITypedFactory <String> BuildExpressionFactoryRecursively()
        {
            var subexpressionFactory =
                Interleaving.Create(new[]
            {
                ConstantFactory,
                Synthesis.Create(Deferral.Create(BuildExpressionFactoryRecursively),
                                 expression => String.Format("({0})", expression))
            });

            var binaryOperatorExpressionFactory = Synthesis.Create(subexpressionFactory,
                                                                   BinaryOperatorFactory, subexpressionFactory,
                                                                   (lhsOperand, binaryOperator, rhsOperand) =>
                                                                   String.Format("{0} {1} {2}", lhsOperand, binaryOperator, rhsOperand));

            return
                (Interleaving.Create(new[]
                                     { ConstantFactory, binaryOperatorExpressionFactory }));
        }