Example #1
0
 public void ZeroSizeTest()
 {
     using (var map = new MemoryMapStream())
     {
         using (var array = new Array<uint>(map, 0))
         {
             Assert.AreEqual(0, array.Length);
         }
         using (var array = new Array<uint>(map, 100))
         {
             array.Resize(0);
             Assert.AreEqual(0, array.Length);
         }
     }
 }
Example #2
0
        public void ResizeTests()
        {
            var randomGenerator = new System.Random(66707770); // make this deterministic 

            using (var map = new MemoryMapStream())
            {
                using (var array = new Array<uint>(map, 1000, 256, 256, 32))
                {
                    var arrayExepected = new uint[1000];

                    for (uint i = 0; i < 1000; i++)
                    {
                        if (randomGenerator.Next(4) >= 2)
                        { // add data.
                            arrayExepected[i] = i;
                            array[i] = i;
                        }
                        else
                        {
                            arrayExepected[i] = int.MaxValue;
                            array[i] = int.MaxValue;
                        }

                        Assert.AreEqual(arrayExepected[i], array[i]);
                    }

                    Array.Resize<uint>(ref arrayExepected, 335);
                    array.Resize(335);

                    Assert.AreEqual(arrayExepected.Length, array.Length);
                    for (int i = 0; i < arrayExepected.Length; i++)
                    {
                        Assert.AreEqual(arrayExepected[i], array[i]);
                    }
                }

                using (var array = new Array<uint>(map, 1000, 256, 256, 32))
                {
                    var arrayExpected = new uint[1000];

                    for (uint i = 0; i < 1000; i++)
                    {
                        if (randomGenerator.Next(4) >= 1)
                        { // add data.
                            arrayExpected[i] = i;
                            array[i] = i;
                        }
                        else
                        {
                            arrayExpected[i] = int.MaxValue;
                            array[i] = int.MaxValue;
                        }

                        Assert.AreEqual(arrayExpected[i], array[i]);
                    }

                    Array.Resize<uint>(ref arrayExpected, 1235);
                    var oldSize = array.Length;
                    array.Resize(1235);

                    Assert.AreEqual(arrayExpected.Length, array.Length);
                    for (int i = 0; i < arrayExpected.Length; i++)
                    {
                        Assert.AreEqual(arrayExpected[i], array[i], 
                            string.Format("Array element not equal at index: {0}. Expected {1}, found {2}",
                                i, array[i], arrayExpected[i]));
                    }
                }
            }
        }