예제 #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(() =>
 {
예제 #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(() =>
 {
예제 #3
0
 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(() =>
 {
예제 #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(() =>
 {
예제 #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(() =>
 {
예제 #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);
        });
예제 #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();
        });
예제 #8
0
        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);
        });
예제 #10
0
        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>();
        });
예제 #11
0
        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);
        });
예제 #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));
        });
예제 #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);
        });
예제 #14
0
            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());
            });
예제 #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);
        });
예제 #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);
        });
예제 #17
0
            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));
            });
예제 #18
0
        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);
        });
예제 #19
0
        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);
        });
예제 #20
0
        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);
        });
예제 #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:*");
        });
예제 #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");
        });
예제 #23
0
        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);
        });
예제 #24
0
        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);
        });
예제 #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);
        });
예제 #26
0
        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));
        });
예제 #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(() =>
 {