Пример #1
0
 public NebulaCheck.IGen <Test> ItErrorsWhenMinimumLengthIsGreaterThanMaximumLength() =>
 from minLength in Gen.Int32().Between(1, 100)
 from maxLength in Gen.Int32().GreaterThanEqual(0).LessThan(minLength)
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 select Property.ForThese(() =>
 {
Пример #2
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(() =>
 {
Пример #3
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(() =>
 {
Пример #4
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(() =>
 {
Пример #5
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(() =>
 {
Пример #6
0
 public NebulaCheck.IGen <Test> ItProducesValuesLikeInt32() =>
 from min in Gen.Int16()
 from max in Gen.Int16().GreaterThanEqual(min)
 from origin in Gen.Int16().Between(min, max)
 from bias in DomainGen.Bias()
 from seed in DomainGen.Seed()
 from size in DomainGen.Size()
 select Property.ForThese(() =>
 {
Пример #7
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(() =>
 {
Пример #8
0
        public NebulaCheck.IGen <Test> GreaterThanDefersToUnderlyingMethod() =>
        from minExclusive in Gen.Int32().LessThan(int.MaxValue)
        select Property.ForThese(() =>
        {
            var mockGen = SetupMock();

            mockGen.Object.GreaterThan(minExclusive);

            mockGen.Verify(gen => gen.GreaterThanEqual(minExclusive + 1), Times.Once);
        });
Пример #9
0
        public NebulaCheck.IGen <Test> LessThanDefersToUnderlyingMethod() =>
        from maxExclusive in Gen.Byte().GreaterThan(byte.MinValue)
        select Property.ForThese(() =>
        {
            var mockGen = SetupMock();

            mockGen.Object.LessThan(maxExclusive);

            mockGen.Verify(gen => gen.LessThanEqual((byte)(maxExclusive - 1)), Times.Once);
        });
Пример #10
0
        public NebulaCheck.IGen <Test> GreaterThanLengthDefersToUnderlyingMethod() =>
        from minLengthExclusive in Gen.Int32()
        select Property.ForThese(() =>
        {
            var mockGen = SetupMock();

            mockGen.Object.WithLengthGreaterThan(minLengthExclusive);

            mockGen.Verify(gen => gen.WithLengthGreaterThanEqual(minLengthExclusive + 1), Times.Once);
        });
Пример #11
0
        public NebulaCheck.IGen <Test> LessThanCountDefersToUnderlyingMethod() =>
        from maxCountExclusive in Gen.Int32()
        select Property.ForThese(() =>
        {
            var mockGen = SetupMock();

            mockGen.Object.WithCountLessThan(maxCountExclusive);

            mockGen.Verify(gen => gen.WithCountLessThanEqual(maxCountExclusive - 1), Times.Once);
        });
Пример #12
0
            public NebulaCheck.IGen <Test> ItIsAffectedByItsArgument() =>
            from variables in Gen.Int32().WithBias(Gen.Bias.None).Two().ListOf().WithCount(10)
            from seed in DomainGen.Seed()
            select Property.ForThese(() =>
            {
                var gen = GalaxyCheck.Gen.Int32().FunctionOf <object, int>();

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

                variables.Should().Contain(variable => func(variable.Item1) != func(variable.Item2));
            });
Пример #13
0
        public NebulaCheck.IGen <Test> ItProducesValuesLessThanOrEqualMaximum() =>
        from max in Gen.Int64()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().LessThanEqual(max);

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

            exampleSpace.Traverse().Take(100).Should().OnlyContain(value => value <= max);
        });
Пример #14
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();
        });
Пример #15
0
        public NebulaCheck.IGen <Test> ItShrinksToTheSinglePredicatedElement() =>
        from bias in DomainGen.Bias()
        from elementMinimum in Gen.Int32().Between(0, 100)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int32().Between(0, 100).ListOf();

            var minimum = gen.Minimum(seed: seed, pred: list => list.Any(element => element >= elementMinimum));

            minimum.Should().BeEquivalentTo(elementMinimum);
        });
Пример #16
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);
        });
Пример #17
0
        public NebulaCheck.IGen <Test> ItShrinksToTheGivenLimit() =>
        from shrinkLimit in Gen.Int32().Between(0, 100)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var property = InfinitelyShrinkableGen.ForAll(_ => false);

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

            result.Shrinks.Should().Be(shrinkLimit);
            result.TerminationReason.Should().Be(TerminationReason.ReachedShrinkLimit);
        });
Пример #18
0
        public NebulaCheck.IGen <Test> ItShrinksToTheOrigin() =>
        from bias in DomainGen.Bias()
        from origin in Gen.Int64()
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().WithBias(bias).ShrinkTowards(origin);

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

            minimum.Should().Be(origin);
        });
Пример #19
0
        public NebulaCheck.IGen <Test> ItShrinksToTheLocalMinimum_ForANegativeRange() =>
        from bias in DomainGen.Bias()
        from origin in Gen.Int64().Between(0, -100)
        from localMin in Gen.Int64().Between(origin, -200)
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().WithBias(bias).ShrinkTowards(origin);

            var minimum = gen.Minimum(seed: seed, pred: value => value <= localMin);

            minimum.Should().Be(localMin);
        });
        public NebulaCheck.IGen <Test> IfSizeIsBelowChaosSize_AndRangeIsZero_ItDoesNotConsumeRandomness() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size(allowChaos: false)
        from iterations in DomainGen.Iterations()
        from x in Gen.Int64()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().Between(x, x);

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

            sample.RandomnessConsumption.Should().Be(0);
        });
Пример #21
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);
        });
Пример #22
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);
        });
Пример #23
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);
        });
Пример #24
0
        public NebulaCheck.IGen <Test> ItProducesValuesWithinTheGivenDates() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        from fromDateTime in Gen.DateTime()
        from untilDateTime in Gen.DateTime().From(fromDateTime)
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.DateTime().From(fromDateTime).Until(untilDateTime);

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

            sample.Should().OnlyContain(dt => fromDateTime <= dt && dt <= untilDateTime);
        });
Пример #25
0
        public NebulaCheck.IGen <Test> ItProducesDistinctValuesWithOfTheSpecificCount() =>
        from count in Gen.Int32().Between(0, 20)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var elementGen = GalaxyCheck.Gen.Int32();
            var gen        = elementGen.SetOf().WithCount(count);

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

            sample.Should().OnlyContain(set => set.Count == count && set.Distinct().SequenceEqual(set));
        });
Пример #26
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:*");
        });
Пример #27
0
        public NebulaCheck.IGen <Test> ItErrorsWhenTheMaximumLengthIsNegative() =>
        from maxLength in Gen.Int32().LessThan(0)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.String().WithLengthLessThanEqual(maxLength);

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

            action.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error while running generator StringGen: 'maxLength' cannot be negative");
        });
Пример #28
0
        public NebulaCheck.IGen <Test> IfSizeIsBelowChaosSize_AndCountIsSpecific_ItConsumesRandomnessForEachElement() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size(allowChaos: false)
        from elementGen in DomainGen.Gen()
        from count in Gen.Int32().Between(0, 20)
        select Property.ForThese(() =>
        {
            var gen = elementGen.ListOf().WithCount(count);

            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);
        });
Пример #29
0
        public NebulaCheck.IGen <Test> ItErrorsWhenMaximumIsLessThanOrigin() =>
        from max in Gen.Int64().LessThan(long.MaxValue)
        from origin in Gen.Int64().GreaterThan(max)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().LessThanEqual(max).ShrinkTowards(origin);

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

            action.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error while running generator Int64: 'origin' must be between 'min' and 'max'");
        });
Пример #30
0
        public NebulaCheck.IGen <Test> ItErrorsWhenMinimumIsGreaterThanMaximum() =>
        from min in Gen.Int64().GreaterThan(long.MinValue)
        from max in Gen.Int64().LessThan(min)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().GreaterThanEqual(min).LessThanEqual(max);

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

            action.Should()
            .Throw <GalaxyCheck.Exceptions.GenErrorException>()
            .WithMessage("Error while running generator Int64: 'min' cannot be greater than 'max'");
        });