Exemple #1
0
        public void Sample()
        {
            var value = "abc123";

            var singleton = Singleton.New(value);

            // Use a ThrowingRng to check that the state of the RNG is left untouched when sampling.
            var rng = new ThrowingRng();

            var sample = singleton.Sample(rng);

            Assert.Equal(value, sample);
        }
        public void SampleUsingQuerySyntax()
        {
            var inputDistribution = new MockDistribution <String>("ABCDEF");

            var outputDistribution =
                from x in inputDistribution
                select x.Length;

            // Use a throwing RNG to check that sampling from the distribution
            // does not update the state of the RNG directly.
            var rng = new ThrowingRng();

            Assert.Equal(6, outputDistribution.Sample(rng));
        }
        public void Sample(String inputSample, Int32 expectedOutputSample)
        {
            var inputDistribution = new MockDistribution <String>(inputSample);

            var outputDistribution = inputDistribution.Select(x => x.Length);

            // Use a throwing RNG to check that sampling from the distribution
            // does not update the state of the RNG directly.
            var rng = new ThrowingRng();

            var sampleFromOutputDistribution = outputDistribution.Sample(rng);

            Assert.Equal(expectedOutputSample, sampleFromOutputDistribution);
        }
Exemple #4
0
        public void TrySample()
        {
            var value = 123.456;

            var singleton = Singleton.New(value);

            // Use a ThrowingRng to check that the state of the RNG is left untouched when sampling.
            var rng = new ThrowingRng();

            var success = singleton.TrySample(rng, out var sample);

            Assert.True(success);
            Assert.Equal(value, sample);
        }
        public void TrySample(
            String inputResult,
            Boolean inputSuccess,
            Int32 expectedOutputResult,
            Boolean expectedOutputSuccess)
        {
            var inputDistribution = new MockDistribution <String>(inputResult, inputSuccess);

            var outputDistribution = inputDistribution.Select(x => x.Length);

            // Use a throwing RNG to check that sampling from the distribution
            // does not update the state of the RNG directly.
            var rng = new ThrowingRng();

            Assert.Equal(expectedOutputSuccess, outputDistribution.TrySample(rng, out var result));
            Assert.Equal(expectedOutputResult, result);
        }