Beispiel #1
0
        public void NextFloatMinimumMaximumTest()
        {
            var random = new MockRandom
            {
                MockNextDouble = float.NegativeInfinity
            };
            var nextFloat = random.NextFloat(0, 1);

            Assert.IsTrue(float.IsNegativeInfinity(nextFloat), $@"Expected negative infinity, got {nextFloat}.");
        }
Beispiel #2
0
        public void NextDoubleTest()
        {
            var random = new MockRandom
            {
                MockNextDouble = double.NegativeInfinity
            };

            var nextDouble = random.NextDouble();

            Assert.IsTrue(double.IsNegativeInfinity(nextDouble), $@"Expected negative infinity, got {nextDouble}.");
        }
Beispiel #3
0
        public void NextULongTest()
        {
            var byteGenerator = new Random();
            var random        = new MockRandom();
            var buffer        = new byte[8];

            for (var i = 0; i < 100; i++)
            {
                byteGenerator.NextBytes(buffer);
                random.MockNextBytes = buffer;
                Assert.AreEqual(BitConverter.ToUInt64(buffer, 0), random.NextULong());
            }
        }
Beispiel #4
0
        public void NextULongMaximumTest()
        {
            var random = new MockRandom();

            var byteGenerator = new Random();
            var buffer        = new byte[8];

            for (var i = 0; i < 100; i++)
            {
                byteGenerator.NextBytes(buffer);
                random.MockNextBytes = buffer;

                var value   = BitConverter.ToUInt64(buffer, 0);
                var maximum = unchecked ((ulong)byteGenerator.NextInt64());

                Assert.AreEqual(
                    value % maximum, random.NextULong(maximum),
                    $"value={value}, maximum={maximum}, %={value % maximum}, {random.NextULong( maximum )}"
                    );
            }
        }
Beispiel #5
0
        public void NextLongMaximumTest()
        {
            var random = new MockRandom();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => random.NextLong(-1));

            var byteGenerator = new Random();

            var buffer = new byte[8];

            for (var i = 0; i < 100; i++)
            {
                byteGenerator.NextBytes(buffer);
                random.MockNextBytes = buffer;

                var value   = BitConverter.ToInt64(buffer, 0);
                var maximum = byteGenerator.NextInt64();

                Assert.AreEqual(
                    value % maximum, random.NextLong(maximum),
                    $"value={value}, maximum={maximum}, %={value % maximum}, {random.NextLong( maximum )}"
                    );
            }
        }
Beispiel #6
0
        public void NextFloatMinimumThrowsExceptionWhenMaximumLessThanMinimumTest()
        {
            var random = new MockRandom();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => random.NextFloat(1, 0));
        }
Beispiel #7
0
        public void NextFloatMaximumThrowsExceptionWhenNegativeTest()
        {
            var random = new MockRandom();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => random.NextFloat(-1));
        }
Beispiel #8
0
        public void NextDoubleMinimumMaximumTest()
        {
            var random = new MockRandom();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => random.NextDouble(1, 0));
        }
Beispiel #9
0
        public void NextDecimalMaximumTest()
        {
            var random = new MockRandom();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => random.NextDecimal(-1));
        }