<commit_before>﻿namespace BashSoft.Judge
{
    using BashSoft.Exceptions;
    using BashSoft.IO;
    using System;
    using System.IO;

    public static class Tester
    {
        public static void CompareContent(string userOutputPath, string expectedOutputPath)
        {
            OutputWriter.WriteMessageOnNewLine("Reading files...");

            try
            {
                var mismatchesPath = GetMismatchPath(expectedOutputPath);
                var actualOutputLines = File.ReadAllLines(userOutputPath);
                var expectedOutputLine = File.ReadAllLines(expectedOutputPath);
                var mismatches = GetLineWithPossibleMismatches(actualOutputLines, expectedOutputLine, out bool hasMismatches);

                Printoutput(mismatches, hasMismatches, mismatchesPath);

                OutputWriter.WriteMessageOnNewLine("Files read!");
            }
            catch (FileNotFoundException)
            {
                OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
            }
        }

        private static void Printoutput(string[] mismatches, bool hasMismatch, string mismatchesPath)
        {
            if (hasMismatch)
            {
                foreach (var mismatch in mismatches)
                {
                    OutputWriter.WriteMessageOnNewLine(mismatch);
                }

                try
                {
                    File.WriteAllLines(mismatchesPath, mismatches);
                }
                catch (DirectoryNotFoundException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
                }

                return;
            }

            OutputWriter.WriteMessageOnNewLine("Files are identical. There are no mismatches.");
        }

        private static string[] GetLineWithPossibleMismatches(string[] actualOutputLines, string[] expectedOutputLine, out bool hasMismatches)
        {
            hasMismatches = false;
            var output = string.Empty;
            var mismatches = new string[actualOutputLines.Length];

            OutputWriter.WriteMessageOnNewLine("Comparing files...");

            var minOutputLine = actualOutputLines.Length;

            if (actualOutputLines.Length != expectedOutputLine.Length)
            {
                hasMismatches = true;
                minOutputLine = Math.Min(actualOutputLines.Length, expectedOutputLine.Length);
                OutputWriter.DisplayException(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
            }

            for (int index = 0; index < minOutputLine; index++)
            {
                var actualLine = actualOutputLines[index];
                var expectedLine = expectedOutputLine[index];

                if (!actualLine.Equals(expectedLine))
                {
                    output = $"Mismatch at line {index} \"{expectedLine}\", actual: \"{actualLine}\"";
                    output += Environment.NewLine;
                    hasMismatches = true;
                }
                else
                {
                    output = actualLine;
                    output += Environment.NewLine;
                }

                mismatches[index] = output;
            }

            return mismatches;
        }

        private static string GetMismatchPath(string expectedOutputPath)
        {
            var indexOf = expectedOutputPath.LastIndexOf('\\');
            var directoryPath = expectedOutputPath.Substring(0, indexOf);
            var finalPath = directoryPath + @"\Mismatches.txt";

            return finalPath;
        }
    }
}<commit_msg>Remove whitespaces<commit_after>﻿namespace BashSoft.Judge
{
    using BashSoft.Exceptions;
    using BashSoft.IO;
    using System;
    using System.IO;

    public static class Tester
    {
        public static void CompareContent(string userOutputPath, string expectedOutputPath)
        {
            OutputWriter.DisplayDarkGreenLine("Reading files...");

            try
            {
                var mismatchesPath = GetMismatchPath(expectedOutputPath);
                var actualOutputLines = File.ReadAllLines(userOutputPath);
                var expectedOutputLine = File.ReadAllLines(expectedOutputPath);
                var mismatches = GetLineWithPossibleMismatches(actualOutputLines, expectedOutputLine, out bool hasMismatches);

                Printoutput(mismatches, hasMismatches, mismatchesPath);

                OutputWriter.WriteEmptyLine();
                OutputWriter.DisplayDarkGreenLine("Files read!");
            }
            catch (FileNotFoundException)
            {
                OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
            }
        }

        private static string GetMismatchPath(string expectedOutputPath)
        {
            var indexOf = expectedOutputPath.LastIndexOf('\\');
            var directoryPath = expectedOutputPath.Substring(0, indexOf);
            var finalPath = directoryPath + @"\Mismatches.txt";

            return finalPath;
        }

        private static string[] GetLineWithPossibleMismatches(string[] actualOutputLines, string[] expectedOutputLine, out bool hasMismatches)
        {
            hasMismatches = false;
            var output = string.Empty;
            var mismatches = new string[actualOutputLines.Length];

            OutputWriter.WriteMessageOnNewLine("Comparing files...");
            OutputWriter.WriteEmptyLine();

            var minOutputLine = actualOutputLines.Length;

            if (actualOutputLines.Length != expectedOutputLine.Length)
            {
                hasMismatches = true;
                minOutputLine = Math.Min(actualOutputLines.Length, expectedOutputLine.Length);

                OutputWriter.DisplayException(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
            }

            for (var index = 0; index < minOutputLine; index++)
            {
                var actualLine = actualOutputLines[index];
                var expectedLine = expectedOutputLine[index];

                if (!actualLine.Equals(expectedLine))
                {
                    //TODO: Create mismaching line for "Mismatchs.txt"
                    output = $"Mismatch at line {index} \"{expectedLine}\", actual: \"{actualLine}\"";
                    //output += Environment.NewLine;
                    hasMismatches = true;
                }
                else
                {
                    output = actualLine;
                    //output += Environment.NewLine;
                }

                mismatches[index] = output;
            }

            return mismatches;
        }

        private static void Printoutput(string[] mismatches, bool hasMismatch, string mismatchesPath)
        {
            if (hasMismatch)
            {
                foreach (var mismatch in mismatches)
                {
                    OutputWriter.WriteMessageOnNewLine(mismatch);
                }

                try
                {
                    File.WriteAllLines(mismatchesPath, mismatches);
                }
                catch (DirectoryNotFoundException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
                }

                return;
            }
            else
            {
                OutputWriter.WriteMessageOnNewLine("Files are identical. There are no mismatches.");
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.0724017127286882, 'fraction_numerical': 0.0005190086933956144, 'mean_word_length': 1.5355263157894736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3009849', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1671, 'n_words': 342}