Exemplo n.º 1
0
 public void ZeroSizeTest()
 {
     using (var array = new MemoryMappedHugeArrayUInt32(
                new MemoryMappedStream(new MemoryStream()), 0, 1024))
     {
         Assert.AreEqual(0, array.Length);
     }
     using (var array = new MemoryMappedHugeArrayUInt32(
                new MemoryMappedStream(new MemoryStream()), 100, 1024))
     {
         array.Resize(0);
         Assert.AreEqual(0, array.Length);
     }
 }
        public void MemoryMappedHugeArrayResizeTests()
        {
            var randomGenerator = new RandomGenerator(66707770); // make this deterministic

            using (var intArray = new MemoryMappedHugeArrayUInt32(new MemoryMappedStream(new MemoryStream()), 1000, 256))
            {
                var intArrayRef = new uint[1000];

                for (uint idx = 0; idx < 1000; idx++)
                {
                    if (randomGenerator.Generate(2.0) > 1)
                    { // add data.
                        intArrayRef[idx] = idx;
                        intArray[idx]    = idx;
                    }
                    else
                    {
                        intArrayRef[idx] = int.MaxValue;
                        intArray[idx]    = int.MaxValue;
                    }

                    Assert.AreEqual(intArrayRef[idx], intArray[idx]);
                }

                Array.Resize <uint>(ref intArrayRef, 335);
                intArray.Resize(335);

                Assert.AreEqual(intArrayRef.Length, intArray.Length);
                for (int idx = 0; idx < intArrayRef.Length; idx++)
                {
                    Assert.AreEqual(intArrayRef[idx], intArray[idx]);
                }
            }

            using (var intArray = new MemoryMappedHugeArrayUInt32(new MemoryMappedStream(new MemoryStream()), 1000, 256))
            {
                var intArrayRef = new uint[1000];

                for (uint idx = 0; idx < 1000; idx++)
                {
                    if (randomGenerator.Generate(2.0) > 1)
                    { // add data.
                        intArrayRef[idx] = idx;
                        intArray[idx]    = idx;
                    }
                    else
                    {
                        intArrayRef[idx] = int.MaxValue;
                        intArray[idx]    = int.MaxValue;
                    }

                    Assert.AreEqual(intArrayRef[idx], intArray[idx]);
                }

                Array.Resize <uint>(ref intArrayRef, 1235);
                var oldSize = intArray.Length;
                intArray.Resize(1235);
                // huge array is not initialized.
                for (long idx = oldSize; idx < intArray.Length; idx++)
                {
                    intArray[idx] = 0;
                }

                Assert.AreEqual(intArrayRef.Length, intArray.Length);
                for (int idx = 0; idx < intArrayRef.Length; idx++)
                {
                    Assert.AreEqual(intArrayRef[idx], intArray[idx], string.Format("Array element not equal at index: {0}. Expected {1}, found {2}",
                                                                                   idx, intArray[idx], intArrayRef[idx]));
                }
            }
        }
        public void MemoryMappedHugeArrayResizeTests()
        {
            var randomGenerator = new RandomGenerator(66707770); // make this deterministic

            using (var intArray = new MemoryMappedHugeArrayUInt32(new MemoryMappedStream(new MemoryStream()), 1000, 256))
            {
                var intArrayRef = new uint[1000];

                for (uint idx = 0; idx < 1000; idx++)
                {
                    if (randomGenerator.Generate(2.0) > 1)
                    { // add data.
                        intArrayRef[idx] = idx;
                        intArray[idx] = idx;
                    }
                    else
                    {
                        intArrayRef[idx] = int.MaxValue;
                        intArray[idx] = int.MaxValue;
                    }

                    Assert.AreEqual(intArrayRef[idx], intArray[idx]);
                }

                Array.Resize<uint>(ref intArrayRef, 335);
                intArray.Resize(335);

                Assert.AreEqual(intArrayRef.Length, intArray.Length);
                for (int idx = 0; idx < intArrayRef.Length; idx++)
                {
                    Assert.AreEqual(intArrayRef[idx], intArray[idx]);
                }
            }

            using (var intArray = new MemoryMappedHugeArrayUInt32(new MemoryMappedStream(new MemoryStream()), 1000, 256))
            {
                var intArrayRef = new uint[1000];

                for (uint idx = 0; idx < 1000; idx++)
                {
                    if (randomGenerator.Generate(2.0) > 1)
                    { // add data.
                        intArrayRef[idx] = idx;
                        intArray[idx] = idx;
                    }
                    else
                    {
                        intArrayRef[idx] = int.MaxValue;
                        intArray[idx] = int.MaxValue;
                    }

                    Assert.AreEqual(intArrayRef[idx], intArray[idx]);
                }

                Array.Resize<uint>(ref intArrayRef, 1235);
                var oldSize = intArray.Length;
                intArray.Resize(1235);
                // huge array is not initialized.
                for (long idx = oldSize; idx < intArray.Length;idx++)
                {
                    intArray[idx] = 0;
                }

                Assert.AreEqual(intArrayRef.Length, intArray.Length);
                for (int idx = 0; idx < intArrayRef.Length; idx++)
                {
                    Assert.AreEqual(intArrayRef[idx], intArray[idx], string.Format("Array element not equal at index: {0}. Expected {1}, found {2}",
                        idx, intArray[idx], intArrayRef[idx]));
                }
            }
        }
 public void ZeroSizeTest()
 {
     using (var array = new MemoryMappedHugeArrayUInt32(
         new MemoryMappedStream(new MemoryStream()), 0, 1024))
     {
         Assert.AreEqual(0, array.Length);
     }
     using (var array = new MemoryMappedHugeArrayUInt32(
         new MemoryMappedStream(new MemoryStream()), 100, 1024))
     {
         array.Resize(0);
         Assert.AreEqual(0, array.Length);
     }
 }