Beispiel #1
0
 public NebulaCheck.IGen <Test> IfThereIsOneChoice_ItProducesValuesLikeTheSource() =>
 from choiceGen in DomainGen.Gen()
 from choiceWeight in Gen.Int32().GreaterThan(1)
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 select Property.ForThese(() =>
 {
Beispiel #2
0
 public NebulaCheck.IGen <Test> ItProducesValuesLikeList() =>
 from elementGen in DomainGen.Gen()
 from count in Gen.Int32().Between(0, 20)
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 select Property.ForThese(() =>
 {
 public NebulaCheck.IGen <Test> ItHasACountLimitEnabledByDefault() =>
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 from elementGen in DomainGen.Gen()
 from excessiveCount in Gen.Int32().Between(1001, 2000)
 select Property.ForThese(() =>
 {
Beispiel #4
0
 public NebulaCheck.IGen <Test> ItErrorsWhenMinimumCountIsGreaterThanMaximumCount() =>
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 from elementGen in DomainGen.Gen()
 from minCount in Gen.Int32().Between(1, 20)
 from maxCount in Gen.Int32().GreaterThanEqual(0).LessThan(minCount)
 select Property.ForThese(() =>
 {
Beispiel #5
0
 public NebulaCheck.IGen <Test> ItOnlyCallsThePropertyFunctionOnce() =>
 from gen in DomainGen.Gen()
 from func in Gen.Function <object, bool>(Gen.Boolean())
 from seed in Gen.Int32()
 let property0 = gen.ForAll(func)
                 let result0 = property0.Check(seed: seed)
                                   where result0.Falsified
                               select Property.ForThese(() =>
 {
Beispiel #6
0
        public static NebulaCheck.IGen <Test> ItReportsTheNumberOfTimesTheGenCouldShrink() =>
        from gen in DomainGen.Gen()
        from numberOfShrinks in Gen.Int32().Between(0, 100)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var minimum = gen
                          .Unfold(x => UnfoldToNumberOfShrinks(x, numberOfShrinks))
                          .Advanced.MinimumWithMetrics(seed: seed);

            minimum.Shrinks.Should().Be(numberOfShrinks);
        });
Beispiel #7
0
        public NebulaCheck.IGen <Test> IfTheShrinkLimitIsZero_ThePropertyCanStillBeFalsified() =>
        from gen in DomainGen.Gen()
        from shrinkLimit in Gen.Int32().LessThanEqual(0)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var property = gen.ForAll(_ => false);

            var result = property.Check(seed: seed, shrinkLimit: shrinkLimit);

            result.Falsified.Should().BeTrue();
        });
        public NebulaCheck.IGen <Test> WhenItIsNotEnumerated_ItWillNotShrink() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.InfiniteOf();

            var sample = gen.Advanced.SampleOneExampleSpace(seed: seed, size: size);

            sample.Traverse().Should().ContainSingle();
        });
        public NebulaCheck.IGen <Test> AGeneratedEnumerableWithoutALimitNeverThrows() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.InfiniteOf(iterationLimit: null).Select(EnsureSourceCanShrink);

            var sample = gen.Advanced.SampleOneExampleSpace(seed: seed, size: size);

            AssertUnlimited(sample);
        });
        public NebulaCheck.IGen <Test> ItExhaustsWithAnImpossiblePredicate() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.Where(_ => false).InfiniteOf();

            Action test = () => gen.SampleOne(seed: seed, size: size).Take(1).ToList();

            test.Should().Throw <GalaxyCheck.Exceptions.GenExhaustionException>();
        });
        public NebulaCheck.IGen <Test> AGeneratedEnumerableHasTheDefaultIterationLimitIfNotConfiguredOtherwise() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.InfiniteOf().Select(EnsureSourceCanShrink);

            var sample = gen.Advanced.SampleOneExampleSpace(seed: seed, size: size);

            AssertLimit(sample, ExpectedDefaultIterationLimit);
        });
Beispiel #12
0
        public NebulaCheck.IGen <Test> ItProducesValuesDeterministically() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.InfiniteOf();

            var sample = gen.SampleOne(seed: seed, size: size);

            sample.Take(10).Should().BeEquivalentTo(sample.Take(10));
        });
Beispiel #13
0
        public NebulaCheck.IGen <Test> IfThePropertyIsInfallible_ItReturnsTheGivenIterations() =>
        from gen in DomainGen.Gen()
        from iterations in DomainGen.Iterations()
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var property = gen.ForAll((_) => true);

            var result = property.Check(iterations: iterations, seed: seed);

            result.Iterations.Should().Be(iterations);
        });
            public NebulaCheck.IGen <Test> ItIsPure() =>
            from returnGen in DomainGen.Gen()
            from seed in DomainGen.Seed()
            from size in DomainGen.Size()
            select Property.ForThese(() =>
            {
                var gen = returnGen.FunctionOf();

                var func = gen.SampleOne(seed: seed, size: size);

                func().Should().Be(func());
            });
Beispiel #15
0
        public NebulaCheck.IGen <Test> IfSizeIsBelowChaosSize_AndCountIsOfARange_ItConsumesRandomnessForTheCountAndForEachElement() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size(allowChaos: false)
        from elementGen in DomainGen.Gen()
        select Property.ForThese(() =>
        {
            var gen = elementGen.ListOf().WithCountBetween(0, 20);

            var listSample    = gen.Advanced.SampleOneWithMetrics(seed: seed, size: size);
            var elementSample = elementGen.Advanced.SampleWithMetrics(iterations: listSample.Value.Count, seed: seed, size: size);

            listSample.RandomnessConsumption.Should().Be(elementSample.RandomnessConsumption + 1);
        });
Beispiel #16
0
        public NebulaCheck.IGen <Test> ItConsumesRandomnessOncePerIteration() =>
        from elementGen in DomainGen.Gen()
        from iterations in DomainGen.Iterations()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.InfiniteOf();

            var sample = gen.Advanced.SampleWithMetrics(iterations: iterations, seed: seed, size: size);

            sample.RandomnessConsumption.Should().Be(iterations);
        });
            public NebulaCheck.IGen <Test> ItIsPure() =>
            from input in DomainGen.Any().Two()
            from returnGen in DomainGen.Gen()
            from seed in DomainGen.Seed()
            from size in DomainGen.Size()
            select Property.ForThese(() =>
            {
                var gen = returnGen.FunctionOf <object, object, object>();

                var func = gen.SampleOne(seed: seed, size: size);

                func(input.Item1, input.Item2).Should().Be(func(input.Item1, input.Item2));
            });
        public NebulaCheck.IGen <Test> ItProducesValuesWithOfTheSpecificCount() =>
        from elementGen in DomainGen.Gen()
        from count in Gen.Int32().Between(0, 20)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.ListOf().WithCount(count);

            var exampleSpace = gen.Advanced.SampleOneExampleSpace(seed: seed, size: size);

            exampleSpace.Traverse().Take(100).Should().OnlyContain(value => value.Count == count);
        });
        public NebulaCheck.IGen <Test> AGeneratedEnumerableHasTheGivenLimit() =>
        from elementGen in DomainGen.Gen()
        from limit in Gen.Int32().Between(1, 1000)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.InfiniteOf(iterationLimit: limit).Select(EnsureSourceCanShrink);

            var sample = gen.Advanced.SampleOneExampleSpace(seed: seed, size: size);

            AssertLimit(sample, limit);
        });
        public NebulaCheck.IGen <Test> ItShrinksTheCountToTheLocalMinimumCount() =>
        from bias in DomainGen.Bias()
        from elementGen in DomainGen.Gen()
        from localMinCount in Gen.Int32().Between(0, 5)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.List(elementGen);

            var minimum = gen.Minimum(seed: seed, pred: list => list.Count >= localMinCount);

            minimum.Should().HaveCount(localMinCount);
        });
Beispiel #21
0
        public NebulaCheck.IGen <Test> IfTheReplayIsInAnInvalidFormat_ItThrows() =>
        from gen in DomainGen.Gen()
        from func in Gen.Function <object, bool>(Gen.Boolean())
        from replay in Gen.Constant("0")
        select Property.ForThese(() =>
        {
            var property = gen.ForAll(func);

            Action test = () => property.Check(replay: replay);

            test.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error decoding replay string:*");
        });
Beispiel #22
0
        public NebulaCheck.IGen <Test> ItErrorsWhenMaximumCountIsNegative() =>
        from elementGen in DomainGen.Gen()
        from maxCount in Gen.Int32().LessThan(0)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.List(elementGen).WithCountLessThanEqual(maxCount);

            Action action = () => gen.SampleOne(seed: seed, size: size);

            action.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error while running generator ListGen: 'maxCount' cannot be negative");
        });
        public NebulaCheck.IGen <Test> WhenItIsEnumeratedOnce_AndTheElementGeneratorDoesNotShrink_ItWillShrinkOnce() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = elementGen.NoShrink().InfiniteOf().Select(enumerable =>
            {
                enumerable.Take(1).ToList();
                return(enumerable);
            });

            var sample = gen.Advanced.SampleOneExampleSpace(seed: seed, size: size);

            sample.Traverse().Should().HaveCount(2);
        });
        public NebulaCheck.IGen <Test> ItShrinksTheCountToTheMinimumCountWhilstShrinkingTheElementsToTheirMinimums() =>
        from bias in DomainGen.Bias()
        from elementGen in DomainGen.Gen()
        from minCount in Gen.Int32().Between(0, 20)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var elementMinimum = elementGen.Minimum(seed: seed);
            var gen            = GalaxyCheck.Gen.List(elementGen).WithCountGreaterThanEqual(minCount);

            var minimum = gen.Minimum(seed: seed);

            minimum.Should()
            .HaveCount(minCount).And
            .AllBeEquivalentTo(elementMinimum);
        });
Beispiel #25
0
        public NebulaCheck.IGen <Test> IfThePropertyIsInfallible_ItCallsTheTestFunctionForEachIteration() =>
        from gen in DomainGen.Gen()
        from iterations in DomainGen.Iterations()
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var numberOfCalls = 0;
            var property      = gen.ForAll((_) =>
            {
                numberOfCalls++;
                return(true);
            });

            property.Check(iterations: iterations, seed: seed);

            numberOfCalls.Should().Be(iterations);
        });
        public NebulaCheck.IGen <Test> WhenItIsEnumeratedOnce_ItWillShrinkToTheSmallestElementRepeated() =>
        from elementGen in DomainGen.Gen()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var elementMin = elementGen.Minimum(seed: SeedUtility.Fork(seed), size: size);

            var infiniteGen = elementGen.InfiniteOf().Select(enumerable =>
            {
                enumerable.Take(1).ToList();
                return(enumerable);
            });

            var minimum = infiniteGen.Minimum(seed: seed, size: size);

            minimum.Take(10).Should().BeEquivalentTo(Enumerable.Range(0, 10).Select(_ => elementMin));
        });
Beispiel #27
0
 public NebulaCheck.IGen <Test> TheDefaultMinimumCountIsZero() =>
 from elementGen in DomainGen.Gen()
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 select Property.ForThese(() =>
 {