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));
        }
        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));
        }
        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));
        }
예제 #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.");
        }
 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));
 }
 public void GetInt64_MinIsTruncated_Inclusive()
 {
     TestRandom rand = new TestRandom();
     rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(5L));
     Assert.AreEqual(6L, rand.GetInt64(6, 10));
 }
 public void GetInt32_MinIsTruncated_Inclusive()
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(5);
     Assert.AreEqual(6, rand.GetInt32(6, 10));
 }
 public void GetInt32(int target)
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(target);
     Assert.AreEqual(target, rand.GetInt32());
 }
예제 #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.");
        }
예제 #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.");
        }
예제 #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.");
        }
예제 #12
0
        public void NextMinMaxReturnsNextItemInIntQueue()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(100);

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

            Assert.AreEqual(100, result);
        }
예제 #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.");
        }
예제 #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.");
        }
예제 #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));
 }
예제 #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());
        }
예제 #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");
        }
예제 #18
0
 public void GetInt32_MaxIsTruncated_Exclusive()
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(10);
     Assert.AreEqual(9, rand.GetInt32(5, 10));
 }
예제 #19
0
        public void GetBoolean_True()
        {
            TestRandom rand = new TestRandom();
            rand.IntQueue.Enqueue(1);

            Assert.IsTrue(rand.GetBoolean());
        }
예제 #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));
 }
예제 #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));
        }
예제 #22
0
        public void GetSingle(System.Single target)
        {
            TestRandom rand = new TestRandom();
            rand.ByteArrayQueue.Enqueue(System.BitConverter.GetBytes(target));

            Assert.AreEqual(target, rand.GetSingle());
        }
예제 #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));
        }
예제 #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));
 }
예제 #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));
        }
예제 #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());
        }
예제 #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.
            ");
        }
예제 #28
0
 public void GetBoolean_False()
 {
     TestRandom rand = new TestRandom();
     rand.IntQueue.Enqueue(0);
     Assert.IsFalse(rand.GetBoolean());
 }
예제 #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.");
        }