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 })); }
public void TakeEnumeratorOutForTestDrive() { var a = TestVariable.Create(LevelsOne); var b = TestVariable.Create(LevelsTwo); var c = Synthesis.Create(a, b, ((resultOne, resultTwo) => string.Format("{0}, {1}", resultOne.ToString(), resultTwo.ToString()))); var d = Synthesis.Create(TestVariable.Create(LevelsOne), input => input.ToString()); var dWithATwist = Synthesis.Create(new List <IFactory> { d }, (Converter <Object, Object>)(thing => thing)); var e = Interleaving.Create(new List <IFactory> { dWithATwist, c }); var strength = e.MaximumStrength; do { foreach (var u in e.CreateEnumerable(strength)) { Console.WriteLine(u.ToString()); } Console.WriteLine("****************"); } while (--strength != 0U); }
private static ITypedFactory <TestCase> BuildTestCaseFactory() { var factoryForLeastItemInSequence = TestVariable.Create(Enumerable.Range(-3, 10)); const int maximumNumberOfDeltas = 4; var factoryForNonNegativeDeltasAndPermutation = Interleaving.Create( from numberOfDeltas in Enumerable.Range(0, 1 + maximumNumberOfDeltas) select BuildNonNegativeDeltasAndPermutationFactory(numberOfDeltas)); var testCaseFactoryForTrivialCase = Singleton.Create(new TestCase()); var testCaseFactoryForNonTrivialCases = Synthesis.Create(factoryForLeastItemInSequence, factoryForNonNegativeDeltasAndPermutation, (leastItemInSequence, nonNegativeDeltasAndItsPermutation) => new TestCase(leastItemInSequence, nonNegativeDeltasAndItsPermutation.Item1, nonNegativeDeltasAndItsPermutation.Item2)); return (Interleaving.Create(new[] { testCaseFactoryForTrivialCase, testCaseFactoryForNonTrivialCases })); }
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 })); }
public ITypedFactory <String> BuildFactoryRecursively(Int32 maximumStringLength) { if (0 == maximumStringLength) { return(_emptyStringFactory); } var simplerFactoryForShorterStrings = BuildFactoryRecursively(maximumStringLength - 1); var factoryForNonEmptyStrings = Synthesis.Create( _factoryForSingleCharacters, simplerFactoryForShorterStrings, (leftmostCharacterToPrepend, shorterString) => leftmostCharacterToPrepend + shorterString); return (Interleaving.Create(new[] { _emptyStringFactory, factoryForNonEmptyStrings })); }