Пример #1
0
        public IGen <Test> EncodeDecodeIsAnIsomorphism() =>
        from seed in Gen.Int32()
        from size in Gen.Int32().Between(0, 100)
        from exampleSpacePath in Gen.Int32().ListOf()
        select Property.ForThese(() =>
        {
            var replay0 = CreateReplay(seed, size, exampleSpacePath);
            var replay1 = ReplayEncoding.Decode(ReplayEncoding.Encode(replay0));

            replay1.GenParameters.Should().Be(replay0.GenParameters);
            replay1.ExampleSpacePath.Should().BeEquivalentTo(replay0.ExampleSpacePath);
        });
Пример #2
0
        public void Examples(int seed, int size, IEnumerable <int> exampleSpacePath, string expectedEncoding)
        {
            var replay = CreateReplay(seed, size, exampleSpacePath);

            // TODO: Cross-platform consistent replay encoding
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                var encoded = ReplayEncoding.Encode(replay);

                encoded.Should().Be(expectedEncoding);
            }
        }
Пример #3
0
        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.*");
        });
Пример #4
0
        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.*");
        });
Пример #5
0
        private static Counterexample <T> FromCounterexampleContext <T>(
            CounterexampleContext <T> counterexampleContext)
        {
            var replay        = new Replay(counterexampleContext.ReplayParameters, counterexampleContext.ReplayPath);
            var replayEncoded = ReplayEncoding.Encode(replay);

            return(new Counterexample <T>(
                       counterexampleContext.ExampleSpace.Current.Id,
                       counterexampleContext.ExampleSpace.Current.Value,
                       counterexampleContext.ExampleSpace.Current.Distance,
                       counterexampleContext.ReplayParameters,
                       counterexampleContext.ReplayPath,
                       replayEncoded,
                       counterexampleContext.Exception,
                       counterexampleContext.PresentationalValue));
        }
Пример #6
0
        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.*");
        });