コード例 #1
0
        public void TestFindMissingIntMissingFoundLargeFile()
        {
            // Warning: Running this test will create a 4 GB file on your system during the test.
            // Disable the next line to enable the test.
            Assert.Inconclusive();

            // Initialize file size.
            // This is larger than the maximum number of possible positive integers so is a reasonable
            // test of a large file.
            long fileSizeInts = 1024 * 1024 * 1024; // 4 GB (~1 billion integers)

            // Initialize test values.
            int exclusionNumber = 15465;
            int bufferSizeBytes = 1024 * 1024 * 1024; // Maximum 1 GB of space.

            // Write the file.
            string fileName = FileHelpers.WriteFileOfInts(fileSizeInts, exclusionValue: exclusionNumber);

            // Do test.
            try
            {
                Assert.AreEqual(exclusionNumber, ArrayFindMissingInt1Complete.FindMissingInt(fileName, bufferSizeBytes));
            }
            finally
            {
                // Delete the file.
                File.Delete(fileName);
            }
        }
コード例 #2
0
        public void TestFindMissingIntMissingFoundVeryLargeFile()
        {
            // Warning: Running this test will create a 16 GB file on your system during the test.
            // Disable the next line to enable the test.
            Assert.Inconclusive();

            // Warning: Enabling this line will create a 16 GB file.
            long fileSizeInts = 1024L * 1024 * 1024 * 4; // 16 GB (~4 billion integers)

            // Initialize test values.
            int exclusionNumber = 15465;
            int bufferSizeBytes = 1024 * 1024 * 1024; // Maximum 1 GB of space.

            // Write the file.
            string fileName = FileHelpers.WriteFileOfInts(fileSizeInts, exclusionValue: exclusionNumber, fileName: @"C:\Temp\VeryLarge.bin");

            // Do test.
            try
            {
                Assert.AreEqual(exclusionNumber, ArrayFindMissingInt1Complete.FindMissingInt(fileName, bufferSizeBytes));
            }
            finally
            {
                // Delete the file.
                File.Delete(fileName);
            }
        }
コード例 #3
0
        public void TestFindMissingIntErrorBufferTooSmall()
        {
            // Initialize test data.
            var test = new[] { 0, 2, 3, 7, 6, 4, 1, 5, 8, 9 };

            // Write the file.
            string fileName = FileHelpers.WriteFileFromBuffer(test);

            // Do test.
            try
            {
                ArrayFindMissingInt1Complete.FindMissingInt(fileName, 1, 0, 9);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
                return;
            }
            finally
            {
                // Delete the file.
                File.Delete(fileName);
            }

            Assert.Fail();
        }
コード例 #4
0
        public void TestFindMissingIntMissingNotFoundBufferMatchEvenBytes()
        {
            // Initialize test data.
            var test = new[] { 0, 2, 3, 7, 6, 4, 1, 5 };

            // Write the file.
            string fileName = FileHelpers.WriteFileFromBuffer(test);

            // Do test.
            Assert.AreEqual(-1, ArrayFindMissingInt1Complete.FindMissingInt(fileName, 1, 0, 7));

            // Delete the file.
            File.Delete(fileName);
        }
コード例 #5
0
        public void TestFindMissingIntMissingNotFoundMediumFile()
        {
            // Initialize test values.
            int fileSizeInts    = 1024 * 1024 * 4; // 16 MB (~ 4 million integers).
            int bufferSizeBytes = 1024 * 1024;     // 1 MB

            // Write the file.
            string fileName = FileHelpers.WriteFileOfInts(fileSizeInts, maxValue: int.MaxValue / 1024);

            // Do test.
            Assert.AreEqual(-1, ArrayFindMissingInt1Complete.FindMissingInt(fileName, bufferSizeBytes, 0, int.MaxValue / 1024));

            // Delete the file.
            File.Delete(fileName);
        }