예제 #1
0
        public void TestNext()
        {
            var generator = new TestNumberGenerator();

            Assert.AreEqual(int.MinValue, generator.Next());
            Assert.AreEqual(int.MinValue + 1, generator.Next());
        }
예제 #2
0
        public void TestGetBytes()
        {
            var generator = new TestNumberGenerator();
            var bytes     = new byte[4];

            for (int expected = 0; expected < 1000; expected++)
            {
                generator.NextBytes(bytes);
                Assert.AreEqual(expected, BitConverter.ToInt32(bytes, 0));
            }
        }
예제 #3
0
        public void TestNextMax()
        {
            var generator = new TestNumberGenerator();

            int max = 1000;

            for (int expected = 0; expected < max; expected++)
            {
                Assert.AreEqual(expected, generator.Next(1000));
            }

            Assert.AreEqual(0, generator.Next(1000));
        }
예제 #4
0
        public void TestNextMinMax()
        {
            var generator = new TestNumberGenerator();

            int min = -100;
            int max = 100;

            for (int expected = 0; expected < max - min; expected++)
            {
                Assert.AreEqual(expected + min, generator.Next(min, max));
            }

            Assert.AreEqual(min, generator.Next(min, max));
        }
예제 #5
0
        public void TestSchuffle()
        {
            var actual = new List <int>
            {
                0, 1, 2, 3, 4, 5
            };

            var random = new TestNumberGenerator();

            actual.Shuffle(random);

            var expected = new List <int>
            {
                4, 3, 5, 2, 1, 0
            };

            // Note: the result highly depends on TestNumberGenerator
            Assert.IsTrue(expected.SequenceEqual(actual));
        }