コード例 #1
0
        private string[] GetLinesWithPossibleMismatches(string[] actualOutputLines, string[] expectedOutputLines, out bool hasMismatch)
        {
            hasMismatch = false;
            string output = string.Empty;

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

            int minOutputLines = actualOutputLines.Length;

            if (actualOutputLines.Length != expectedOutputLines.Length)
            {
                hasMismatch    = true;
                minOutputLines = Math.Min(actualOutputLines.Length, expectedOutputLines.Length);
                OutputWriter.DisplayException(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
            }

            string[] mismatches = new string[minOutputLines];
            for (int i = 0; i < minOutputLines; i++)
            {
                string actualLine   = actualOutputLines[i];
                string expectedLine = expectedOutputLines[i];

                if (!actualLine.Equals(expectedLine))
                {
                    output      = string.Format($"Mismatch at line {i} -- expected: \"{expectedLine}\", actual: \"{actualLine}\"");
                    output     += Environment.NewLine;
                    hasMismatch = true;
                }
                else
                {
                    output  = actualLine;
                    output += Environment.NewLine;
                }

                mismatches[i] = output;
            }

            return(mismatches);
        }
コード例 #2
0
        public static string[] GetLineWithPossibleMismatches(string[] actualOutputLines, string[] expectedOutputLines, out bool hasMismatch)
        {
            hasMismatch = false;
            string output = string.Empty;

            string[] mismatches = new string[actualOutputLines.Length];
            OutputWriter.WriteMessageOnNewLine("Comparing files...");

            int minOutputLines = actualOutputLines.Length;

            if (actualOutputLines.Length != expectedOutputLines.Length)
            {
                ;
            }
            {
                hasMismatch    = true;
                minOutputLines = Math.Min(actualOutputLines.Length, expectedOutputLines.Length);
                OutputWriter.DisplayException(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
                mismatches = new string[minOutputLines];
            }
            for (int index = 0; index < minOutputLines; index++)
            {
                string actualLine   = actualOutputLines[index];
                string expectedLine = expectedOutputLines[index];
                if (actualLine != expectedLine)
                {
                    output      = $"Mismatch at line {index} -- expected: \"{expectedLine}\", actual: \"{actualLine}\"";
                    hasMismatch = true;
                }
                else
                {
                    output  = actualLine;
                    output += Environment.NewLine;
                }
                mismatches[index] = output;
            }
            return(mismatches);
        }
コード例 #3
0
        private static void FilterAndTake(Dictionary <string, List <int> > wantedData,
                                          Predicate <double> givenFilter,
                                          int studentsToTake)
        {
            int counterForPrinted = 0;

            foreach (var userName_Point in wantedData)
            {
                if (counterForPrinted == studentsToTake)
                {
                    break;
                }
                double averageScore           = userName_Point.Value.Average();
                double percentageOfAllfilment = averageScore / 100;
                double mark = percentageOfAllfilment * 4 + 2;

                if (givenFilter(mark))
                {
                    OutputWriter.PrintStudent(userName_Point);
                    counterForPrinted++;
                }
            }
        }
コード例 #4
0
        private void PrintOutPut(string[] mismatches, bool hasMismatch, string mismatchPath)
        {
            if (hasMismatch)
            {
                foreach (var line in mismatches)
                {
                    OutputWriter.WriteMessageOnNewLine(line);
                }

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

                return;
            }

            OutputWriter.WriteMessageOnNewLine("Files are identical. There are no mismatches.");
        }
コード例 #5
0
        public void CompareContent(string userOutputPath, string expectedOutputPath)
        {
            try
            {
                OutputWriter.WriteMessageOnNewLine("Reading files...");

                string mismatchPath = this.GetMismatchPath(expectedOutputPath);

                string[] actualOutputLines   = File.ReadAllLines(userOutputPath);
                string[] expectedOutputLines = File.ReadAllLines(expectedOutputPath);

                bool     hasMismatch;
                string[] mismatches = this.GetLinesWithPossibleMismatches(actualOutputLines, expectedOutputLines, out hasMismatch);

                this.PrintOutPut(mismatches, hasMismatch, mismatchPath);
                OutputWriter.WriteMessageOnNewLine("Files read!");
            }

            catch (IOException)
            {
                OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
            }
        }