Ejemplo n.º 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);
        }
        BuildNonNegativeDeltasAndPermutationFactory(int numberOfDeltas)
        {
            var factoryForNonNegativeDelta =
                TestVariable.Create(from signedDelta in Enumerable.Range(0, 5)
                                    select signedDelta);

            return
                (Synthesis.CreateWithPermutation <Int32, Int32>(
                     Enumerable.Repeat(factoryForNonNegativeDelta, numberOfDeltas)));
        }
        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)));
        }
        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)));
        }
        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);
        }