Ejemplo n.º 1
0
        public void GetBinary_MinTruncates_Inclusive()
        {
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(new byte[] { 0, 1, 2 });
            rand.IntQueue.Enqueue(2);

            CollectionAssert.AreEqual(new byte[] { 0, 1, 2 }, rand.GetBinary(3, 4));
        }
Ejemplo n.º 2
0
        public void GetBinary_MaxTruncates_Exclusive()
        {
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(new byte[] { 1, 2, 3, 4 });
            rand.IntQueue.Enqueue(5);

            CollectionAssert.AreEqual(new byte[] { 1, 2, 3, 4 }, rand.GetBinary(3, 5));
        }
Ejemplo n.º 3
0
        public void GetBinaryTests(int min, int max, int length, byte[] data)
        {
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(data);
            rand.IntQueue.Enqueue(length);

            CollectionAssert.AreEqual(data, rand.GetBinary(min, max));
        }
Ejemplo n.º 4
0
        public void NextBytesReturnsTopOfBytesArrayQueue()
        {
            byte[] target = new byte[] { 0x1, 0x2, 0x3, 0x4 };
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(target);

            byte[] result = new byte[4];
            rand.NextBytes(result);

            CollectionAssert.AreEqual(target, result, "The two arrays should be the same.");
        }
Ejemplo n.º 5
0
 public void GetSingle_MaxIsTruncated_Exclusive()
 {
     TestRandom rand = new TestRandom();
     rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(10.0f));
     Assert.AreEqual(9.0f, rand.GetSingle(5f, 10f));
 }
Ejemplo n.º 6
0
 public void GetInt64_MinIsTruncated_Inclusive()
 {
     TestRandom rand = new TestRandom();
     rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(5L));
     Assert.AreEqual(6L, rand.GetInt64(6, 10));
 }
Ejemplo n.º 7
0
 public void GetInt32_MinIsTruncated_Inclusive()
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(5);
     Assert.AreEqual(6, rand.GetInt32(6, 10));
 }
Ejemplo n.º 8
0
 public void GetInt32(int target)
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(target);
     Assert.AreEqual(target, rand.GetInt32());
 }
Ejemplo n.º 9
0
        public void NextPopsTheTopOfTheIntQueue()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(0);

            if(rand.IntQueue.Count != 1)
                Assert.Fail("Unable to determine the size of IntQueue.");

            rand.Next();

            Assert.AreEqual(0, rand.IntQueue.Count, "The number of items left in IntQueue should be zero.");
        }
Ejemplo n.º 10
0
        public void NextMinMaxTruncatesValueInIntQueueMin()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(-1);
            int minValue = 0;

            int result = rand.Next(minValue, 100);

            Assert.AreEqual(minValue, result, "The result should have been equal to minValue because the min value represents an inclusive lower bound.");
        }
Ejemplo n.º 11
0
        public void NextMinMaxTruncatesValueInIntQueueMax()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(101);
            int maxValue = 100;

            int result = rand.Next(0, maxValue);

            Assert.AreEqual(maxValue - 1, result, "The result should have been (maxvalue - 1) because the max value represents an exclusive upper bound.");
        }
Ejemplo n.º 12
0
        public void NextMinMaxReturnsNextItemInIntQueue()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(100);

            int result = rand.Next(0, 101);

            Assert.AreEqual(100, result);
        }
Ejemplo n.º 13
0
        public void NextMinMaxPopsIntQueue()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(100);

            if(rand.IntQueue.Count != 1)
                Assert.Fail("Unable to determine the size of IntQueue.");

            rand.Next(0, 101);

            Assert.AreEqual(0, rand.IntQueue.Count, "The number of items in IntQueue should be zero.");
        }
Ejemplo n.º 14
0
        public void NextDoubleReturnsTopOfDoubleQueue()
        {
            TestRandom rand = new TestRandom();
            rand.DoubleQueue.Enqueue(1.1);

            Assert.AreEqual(1.1, rand.NextDouble(), "The result of NextDouble should have been the top of the DoubleQueue.");
        }
Ejemplo n.º 15
0
 public void GetDecimal_MinIsTruncated_Inclusive()
 {
     TestRandom rand = new TestRandom();
     foreach(var item in GetUsableDecimalBits(5m))
         rand.IntQueue.Enqueue(item);
     Assert.AreEqual(6m, rand.GetDecimal(6m, 10m));
 }
Ejemplo n.º 16
0
        public void GetGuid(byte[] targetBytes)
        {
            System.Guid target = new System.Guid(targetBytes);
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(targetBytes);

            Assert.AreEqual(target, rand.GetGuid());
        }
Ejemplo n.º 17
0
        public void NextReturnsTopOfIntQueue()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(101);

            Assert.AreEqual(101, rand.Next(), "The result of Next should have been the top of the IntQueue");
        }
Ejemplo n.º 18
0
 public void GetInt32_MaxIsTruncated_Exclusive()
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(10);
     Assert.AreEqual(9, rand.GetInt32(5, 10));
 }
Ejemplo n.º 19
0
        public void GetBoolean_True()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(1);

            Assert.IsTrue(rand.GetBoolean());
        }
Ejemplo n.º 20
0
 public void GetInt64_MaxIsTruncated_Exclusive()
 {
     TestRandom rand = new TestRandom();
     rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(10L));
     Assert.AreEqual(9L, rand.GetInt64(5, 10));
 }
Ejemplo n.º 21
0
        public void GetDateTime(System.DateTime target)
        {
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(target.Ticks));

            Assert.AreEqual(target, rand.GetDateTime(System.DateTime.MinValue, System.DateTime.MaxValue));
        }
Ejemplo n.º 22
0
        public void GetSingle(System.Single target)
        {
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(target));

            Assert.AreEqual(target, rand.GetSingle());
        }
Ejemplo n.º 23
0
        public void GetDateTime_MaxIsTruncated_Exclusive()
        {
            System.DateTime max = new System.DateTime(1000, 1, 1, 0, 0, 0, 1);
            System.DateTime target = new System.DateTime(max.Ticks - 1);

            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(max.Ticks));

            Assert.AreEqual(target, rand.GetDateTime(System.DateTime.MinValue, max));
        }
Ejemplo n.º 24
0
 public void GetSingle_MinIsTruncated_Inclusive()
 {
     TestRandom rand = new TestRandom();
     rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(5.0f));
     Assert.AreEqual(6.0f, rand.GetSingle(6f, 10f));
 }
Ejemplo n.º 25
0
        public void GetDateTime_MinIsTruncated_Inclusive()
        {
            System.DateTime min = new System.DateTime(1000, 1, 1, 0, 0, 0, 1);
            System.DateTime target = new System.DateTime(min.Year, min.Month, min.Day, min.Hour, min.Minute, min.Second, min.Millisecond - 1);

            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(target.Ticks));

            Assert.AreEqual(min, rand.GetDateTime(min, System.DateTime.MaxValue));
        }
Ejemplo n.º 26
0
        public void GetDecimal(System.Decimal target)
        {
            TestRandom rand = new TestRandom();
            foreach(var item in GetUsableDecimalBits(target))
                rand.IntQueue.Enqueue(item);

            Assert.AreEqual(target, rand.GetDecimal());
        }
Ejemplo n.º 27
0
        public void GetDecimalScaleMustBeBetween0And28Inclusive(int low, int mid, int high, int signed, int scale, int badScale)
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(low);
            rand.IntQueue.Enqueue(mid);
            rand.IntQueue.Enqueue(high);
            rand.IntQueue.Enqueue(signed);
            rand.IntQueue.Enqueue(badScale);

            Assert.AreEqual(new System.Decimal(low, mid, high, (signed % 2) == 1, (byte)scale), rand.GetDecimal(), @"
            The two decimal values should be equal.
            ");
        }
Ejemplo n.º 28
0
 public void GetBoolean_False()
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(0);
     Assert.IsFalse(rand.GetBoolean());
 }
Ejemplo n.º 29
0
        public void NextBytesPopsTheTopOfTheBytesArrayQueue()
        {
            byte[] target = new byte[] { 0x1, 0x2, 0x3, 0x4 };
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(target);

            if(rand.ByteArrayQueue.Count != 1)
                Assert.Fail("Unable to determine the size of ByteArrayQueue.");

            byte[] result = new byte[4];
            rand.NextBytes(result);

            Assert.AreEqual(0, rand.ByteArrayQueue.Count, "The number of items left in ByteArrayQueue should be zero.");
        }