public void SamplesDistributionTest() { var source = DiscreteUniform.Samples(MathTool.GetRandomFactory()(), 0, 10).AsParallel().Take(99999).Select(x => (double)x).ToList(); var histogram = new Histogram(source, 11, 0, 11); DisplayDistribution("DiscreteUniform", histogram); }
public void StaticSampleUniform() { DiscreteUniform.Sample(new Random(), 0, 10).Should().Be.GreaterThanOrEqualTo(0).And.Be.LessThanOrEqualTo(10); DiscreteUniform.Samples(new Random(), 0, 10).Take(10).Where(x => x >= 0 && x <= 10).Count().Should().Be(10); Assert.Throws <InvalidOperationException>(() => DiscreteUniform.Sample(new Random(), 10, 0)); Assert.Throws <InvalidOperationException>(() => DiscreteUniform.Samples(new Random(), 10, 0).First()); }
public void SamplesTest([Values(-10, 0, 10, 20)] int lower, [Values(10, 4, 20, 20)] int upper) { var uniform = new DiscreteUniform(lower, upper); uniform.Samples().Take(100).RunEach(x => x.Should() .Be.GreaterThanOrEqualTo(lower) .And .Be.LessThanOrEqualTo(upper)); }