示例#1
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);
        });
示例#2
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> 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);
        });
示例#4
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);
        });
示例#5
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'");
        });
示例#6
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'");
        });
        public NebulaCheck.IGen <Test> IfSizeIsBelowChaosSize_AndRangeIsNonZero_ItConsumesRandomnessOncePerIteration() =>
        from seed in DomainGen.Seed()
        from size in DomainGen.Size(allowChaos: false)
        from iterations in DomainGen.Iterations()
        from x in Gen.Int64()
        from y in Gen.Int64()
            where x != y
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().Between(x, y);

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

            sample.RandomnessConsumption.Should().Be(sample.Values.Count);
        });
示例#8
0
        public NebulaCheck.IGen <Test> ItShrinksAnyScenarioWithin128Attempts_ForANegativeRange() =>
        from bias in DomainGen.Bias().NoShrink()
        from localMin in Gen.Int64().Between(0, long.MinValue / 2).NoShrink()
        from seed in DomainGen.Seed()
        select Property.ForThese(() =>
        {
            var gen = GalaxyCheck.Gen.Int64().LessThanEqual(0).WithBias(bias);

            var minimum = gen.Advanced.MinimumWithMetrics(
                seed: seed,
                deepMinimum: false,
                pred: value => value <= localMin);

            minimum.Shrinks.Should().BeLessOrEqualTo(128);
        });