Esempio n. 1
0
        // [TestCase(@"files/example_1GB.txt", @"files/example_expected.txt", 50000)]
        public async Task Sort_ProducesCorrectResult(string inputFileName, string expectedOutputFileName, int batchSize)
        {
            // arrange
            var options = new FileSorterOptions
            {
                BatchSize = batchSize
            };

            _fixture.Register(() => options);
            var outFileName = FileSorter.DefaultOutFileName(inputFileName);
            var sorter      = _fixture.Create <FileSorter>();

            // act
            await sorter.Sort(inputFileName, outFileName, CancellationToken.None);

            // assert
            await using var outputExpectedFile = File.OpenRead(expectedOutputFileName);
            using var outputExpectedReader     = new StreamReader(outputExpectedFile);

            await using var outputActualFile = File.OpenRead(outFileName);
            using var outputActualReader     = new StreamReader(outputActualFile);

            while (!outputExpectedReader.EndOfStream)
            {
                var expectedLine = await outputExpectedReader.ReadLineAsync();

                Assert.IsTrue(!outputActualReader.EndOfStream);
                var actualLine = await outputActualReader.ReadLineAsync();

                Assert.AreEqual(expectedLine, actualLine);
            }

            Assert.IsTrue(outputActualReader.EndOfStream);
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            string fileName;

            if (args.Length < 1)
            {
                Console.Write("File name: ");

                fileName = Console.ReadLine();
            }
            else
            {
                fileName = args[0];
            }

            if (!File.Exists(fileName))
            {
                Console.WriteLine($"File '{fileName}' doesn't exist.");
            }

            var options = Options.Create(new FileSorterOptions
            {
                BatchSize = 50000
            });

            var sorter      = new FileSorter(options);
            var outFileName = FileSorter.DefaultOutFileName(fileName);

            var sw = new Stopwatch();

            sw.Start();

            Task.WaitAll(sorter.Sort(fileName, outFileName, CancellationToken.None));

            sw.Stop();

            Console.WriteLine($"Sorted. Output: '{outFileName}', elapsed: {sw.Elapsed.TotalSeconds:0.000} s.");
        }