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> 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(() => {
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(() => {
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(() => {
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(() => {
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(() => {
public NebulaCheck.IGen <Test> ItProducesValuesLikeInt32() => from min in Gen.Int32() from max in Gen.Int32().GreaterThanEqual(min) from origin in Gen.Int32().Between(min, max) from bias in DomainGen.Bias() from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => {
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); });
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); });
public NebulaCheck.IGen <Test> LessThanDefersToUnderlyingMethod() => from maxExclusive in Gen.Int32().GreaterThan(int.MinValue) select Property.ForThese(() => { var mockGen = SetupMock(); mockGen.Object.LessThan(maxExclusive); mockGen.Verify(gen => gen.LessThanEqual(maxExclusive - 1), Times.Once); });
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> 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); });
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 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> 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> 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)); });
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); });
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> 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"); });
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); });
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> ItErrorsWhenMinimumIsGreaterThanMaximum() => from min in Gen.Int32().GreaterThan(int.MinValue) from max in Gen.Int32().LessThan(min) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Int32().GreaterThanEqual(min).LessThanEqual(max); Action action = () => gen.SampleOne(seed: seed, size: size); action.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error while running generator Int32: 'min' cannot be greater than 'max'"); });
public NebulaCheck.IGen <Test> ItErrorsWhenMaximumIsLessThanOrigin() => from max in Gen.Int32().LessThan(int.MaxValue) from origin in Gen.Int32().GreaterThan(max) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Int32().LessThanEqual(max).ShrinkTowards(origin); Action action = () => gen.SampleOne(seed: seed, size: size); action.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error while running generator Int32: 'origin' must be between 'min' and 'max'"); });
public NebulaCheck.IGen <Test> ItErrorsWhenCharTypesIsNone() => from charType in Gen.Choose( Gen.Int32().LessThanEqual(0).Select(x => (GalaxyCheck.Gen.CharType)x), Gen.Int32().GreaterThan((int)GalaxyCheck.Gen.CharType.All).Select(x => (GalaxyCheck.Gen.CharType)x)) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var gen = GalaxyCheck.Gen.Char(charType); Action action = () => gen.SampleOne(seed: seed, size: size); action.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error while running generator CharGen: 'charType' was not a valid flag value"); });
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); });
public NebulaCheck.IGen <Test> IfTheReplayEncodesAGenError_ItThrows() => from func in Gen.Function <object, bool>(Gen.Boolean()) from replaySeed in Gen.Int32() from replaySize in Gen.Int32().Between(0, 100) from replayPath in Gen.Int32().ListOf() select Property.ForThese(() => { var property = GalaxyCheck.Gen.Advanced.Error <object>("", "").ForAll(func); var replay = ReplayEncoding.Encode(CreateReplay(replaySeed, replaySize, replayPath)); Action test = () => property.Check(replay: replay); test.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error replaying last example, given replay string was no longer valid.*"); });
public NebulaCheck.IGen <Test> IfTheReplayEncodesAnInvalidShrinkPath_ItThrows() => from func in Gen.Function(Gen.Boolean()) from replaySeed in Gen.Int32() from replaySize in Gen.Int32().Between(0, 100) from replayPath in Gen.Int32().ListOf().WithCountGreaterThanEqual(1) select Property.ForThese(() => { var property = GalaxyCheck.Property.Nullary(func); var replay = ReplayEncoding.Encode(CreateReplay(replaySeed, replaySize, replayPath)); Action test = () => property.Check(replay: replay); test.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error replaying last example, given replay string was no longer valid.*"); });
public NebulaCheck.IGen <Test> IfTheImageContainsTheTargetReturnValue_ItShrinksToTheFunctionWhereTheImageIsTheTargetReturnValue() => from returnValues in Gen.Int32().ListOf().WithCount(10) from targetReturnValue in Gen.Element(returnValues.AsEnumerable()) from seed in DomainGen.Seed() from size in DomainGen.Size() select Property.ForThese(() => { var variables = Enumerable.Range(0, 10); var gen = GalaxyCheck.Gen.Int32().Between(0, returnValues.Count - 1).Select(i => returnValues[i]).FunctionOf <int, int>(); var func = gen.Minimum( seed: seed, size: 100, pred: (f) => variables.Any(variable => f(variable) == targetReturnValue)); variables.Should().OnlyContain(variable => func(variable) == targetReturnValue); });
public NebulaCheck.IGen <Test> IfTheReplayEncodesAPreconditionFailure_ItThrows() => from value in DomainGen.Any() from replaySeed in Gen.Int32() from replaySize in Gen.Int32().Between(0, 100) from replayPath in Gen.Int32().ListOf() select Property.ForThese(() => { var property = GalaxyCheck.Gen.Constant(value).ForAll((_) => { GalaxyCheck.Property.Precondition(false); }); var replay = ReplayEncoding.Encode(CreateReplay(replaySeed, replaySize, replayPath)); Action test = () => property.Check(replay: replay); test.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error replaying last example, given replay string was no longer valid.*"); });