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);
        });
Beispiel #2
0
        public NebulaCheck.IGen <Test> IfDeepCheckIsDisabled_ForAnEasilyFalsifiableProperty_ItIsLimitedByDeepCheckDisabled() =>
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var property = GalaxyCheck.Gen.Int32().ForAll(x => x < 1);

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

            result.TerminationReason.Should().Be(GalaxyCheck.Runners.Check.TerminationReason.DeepCheckDisabled);
        });
        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);
        });
        public NebulaCheck.IGen <Test> TheDefaultMinimumIsTheMinimumInt32() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen0 = GalaxyCheck.Gen.Char();
            var gen1 = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.All);

            SampleTraversal(gen0, seed, size).Should().BeEquivalentTo(SampleTraversal(gen1, seed, size));
        });
        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);
        });
Beispiel #6
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);
        });
        public NebulaCheck.IGen <Test> IfCharTypeIsNumeric_ItOnlyProducesNumericCharacters() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Numeric);

            var sample = SampleTraversal(gen, seed, size);

            sample.Should().OnlyContain(c => new Regex(@"[0-9]").IsMatch(c.ToString()));
        });
            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));
            });
        public NebulaCheck.IGen <Test> IfCharTypeIsControl_ItOnlyProducesCharactersInControlAsciiSet() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Control);

            var sample = SampleTraversal(gen, seed, size);

            sample.Should().OnlyContain(c => c <= 37 || c == 127);
        });
        public NebulaCheck.IGen <Test> Otherwise_ItShrinksToNullCharacter() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Control);

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

            minimum.Should().Be('\u0000');
        });
        public NebulaCheck.IGen <Test> OtherwiseIfCharTypeHasWhitespace_ItShrinksToSpace() =>
        from charType in TestGen.CharType(GalaxyCheck.Gen.CharType.Alphabetical)
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Whitespace | charType);

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

            minimum.Should().Be(' ');
        });
        public NebulaCheck.IGen <Test> IfCharTypeHasAlphabetical_ItShrinksToLowercaseA() =>
        from charType in TestGen.CharType()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Char(GalaxyCheck.Gen.CharType.Alphabetical | charType);

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

            minimum.Should().Be('a');
        });
Beispiel #13
0
        public NebulaCheck.IGen <Test> ItDoesNotConsumeRandomness() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Constant(value);

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

            sample.RandomnessConsumption.Should().Be(0);
        });
        public NebulaCheck.IGen <Test> ItCanGenerateAnEmptyRecord() =>
        from value in DomainGen.Any()
        from seed in DomainGen.Seed()
        from size in DomainGen.Size()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Create <EmptyRecord>();

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

            instance.Should().NotBeNull();
        });
Beispiel #15
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();
        });
Beispiel #16
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));
        });
        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);
        });
        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();
        });
Beispiel #19
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);
        });
            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 #21
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);
        });
Beispiel #22
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);
        });
Beispiel #23
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);
        });
        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> 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);
        });
        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>();
        });
Beispiel #27
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> 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);
        });
Beispiel #29
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 #30
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);
        });