コード例 #1
0
        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 void TestStuff()
        {
            const int deferralBudget = 4;
            var       historiesForSeveralThingsFactory = HistoriesForSeveralThingsFactory();

            var randomBehaviourSeedFactory = TestVariable.Create(new[] { 67, 890478236, 1123789, 892367 });

            var topLevelTestCaseFactory =
                Synthesis.Create(historiesForSeveralThingsFactory, randomBehaviourSeedFactory, Tuple.Create)
                .WithDeferralBudgetOf(deferralBudget);

            const int strength = 3;

            var numberOfTestCases = topLevelTestCaseFactory.ExecuteParameterisedUnitTestForAllTestCases(strength,
                                                                                                        topLevelTestCase =>
            {
                Console.WriteLine("***************");
                foreach (var thingHistory in topLevelTestCase.Item1)
                {
                    Console.WriteLine("Thing record index: {0} => item index: {1}", thingHistory.ThingRecordIndex,
                                      thingHistory.ItemIndex);
                }
            });

            Console.WriteLine("Number of test cases validated: {0}", numberOfTestCases);
        }
        public ITypedFactory <ThingHistory> ThingFactory(int thingRecordIndex, int maximumNumberOfItems)
        {
            var itemIndexFactory          = TestVariable.Create(Enumerable.Range(0, maximumNumberOfItems));
            var numberOfRejectionsFactory = TestVariable.Create(Enumerable.Range(0, 3));

            return(Synthesis.Create(itemIndexFactory, numberOfRejectionsFactory, numberOfRejectionsFactory,
                                    (itemIndex, numberOfRejectionsBeforeAcceptance, numberOfRejectionsBeforeWithdrawal) =>
                                    new ThingHistory(thingRecordIndex, itemIndex, numberOfRejectionsBeforeAcceptance,
                                                     numberOfRejectionsBeforeWithdrawal)));
        }
コード例 #5
0
        private static ITypedFactory <IEnumerable <Tuple <Int32, Int32> > > BuildConnectionsFactory(Int32 numberOfVertices)
        {
            var numberOfPotentialUniqueConnectionsWithoutSelfLoops =
                NumberOfPotentialUniqueConnectionsWithoutSelfLoops(numberOfVertices);

            var connectionSwitchFactory = TestVariable.Create(new[] { false, true });

            return
                (Synthesis.Create(
                     Enumerable.Repeat(connectionSwitchFactory, numberOfPotentialUniqueConnectionsWithoutSelfLoops),
                     connectionSwitches => EnumerateConnections(connectionSwitches, numberOfVertices)));
        }
コード例 #6
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))
            }));
        }
コード例 #8
0
        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 }));
        }
コード例 #10
0
        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 }));
        }
        public void TestStandardDictionaryWithJustOneKey()
        {
            var keyFactory = TestVariable.Create(Enumerable.Range(-2, 5));

            var operationFactory =
                TestVariable.Create(
                    from operationKind in
                    ((IEnumerable <OperationKind>)
                     Enum.GetValues(typeof(OperationKind)))
                    select operationKind);

            const Int32 numberOfOperations = 10;

            var randomBehaviour = new Random(0);

            var operationKindSequenceFactory =
                Synthesis.Create(Enumerable.Repeat(operationFactory, numberOfOperations))
                .WithFilter(FilterOutThreeOrMoreConsecutiveIdenticalOperationKinds);

            var operationListBuilderFactory = Synthesis.Create(keyFactory,
                                                               operationKindSequenceFactory, (key, operationKindSequence) =>
            {
                var result = new OperationListBuilder(key, randomBehaviour);

                foreach (var operationKind in operationKindSequence)
                {
                    result.AppendNewOperationOfKind(operationKind);
                }

                return(result);
            });
            const Int32 strength = 4;

            var numberOfTestCasesExercised =
                operationListBuilderFactory.ExecuteParameterisedUnitTestForAllTestCases(
                    strength, ParameterisedUnitTestForStandardDictionaryWithJustOneKey);

            Console.Out.WriteLine("Exercised {0} test cases.", numberOfTestCasesExercised);
        }