/// <summary>
        /// Parses the contents of a WebGrader result into a list of DiffResults.
        /// </summary>
        /// <returns>A list of DiffResults corresponding to WebGrader tests.</returns>
        /// <param name="contents">Text of the WebGrader results.</param>
        private List <DiffResult> ParseDiffs(string contents)
        {
            var regex             = new Regex(@"part(\d\d)test(\d\d)\.dif?f?(.+?)\d+\.\d+\.\d+ Input File", RegexOptions.Singleline);
            var submissionRegex   = new Regex(@"\d\.\d+\.\d Submission Output.*?\d?\d?part\d\dtest\d\d\.output(.+?)\d\.\d+\.\d Solution Output", RegexOptions.Singleline);
            var solutionRegex     = new Regex(@"\d\.\d+\.\d Solution Output.*?part\d\dtest\d\d\.solution(.+?)\d\.\d+\.\d stderr", RegexOptions.Singleline);
            var errorRegex        = new Regex(@"\d\.\d+\.\d stderr.*?part\d\dtest\d\d\.err(.*?)\d\.\d+", RegexOptions.Singleline);
            var mazeRegex         = new Regex(@"part\d\dtest\d\d\.maze\.emf(.+?)\d\.\d+\.\d Submission Output", RegexOptions.Singleline);
            var directionsRegex   = new Regex(@"part\d\dtest\d\d\.moves\.emf(.+?)part\d\dtest\d\d\.maze\.emf", RegexOptions.Singleline);
            var matches           = regex.Matches(contents);
            var submissionMatches = submissionRegex.Matches(contents);
            var solutionMatches   = solutionRegex.Matches(contents);
            var errorMatches      = errorRegex.Matches(contents);
            var mazeMatches       = mazeRegex.Matches(contents);
            var directionsMatches = directionsRegex.Matches(contents);

            var diffs = new List <DiffResult>();

            for (int i = 0; i < matches.Count; i++)
            {
                var match         = matches[i];
                var sectionNumber = int.Parse(match.Groups[1].Value);
                var testNumber    = int.Parse(match.Groups[2].Value);
                var diff          = match.Groups[3].Value.Trim();
                var submission    = EnsureSameLengthLines(RemoveLineNumbers(submissionMatches[i].Groups[1].Value.Trim()));
                var solution      = EnsureSameLengthLines(RemoveLineNumbers(solutionMatches[i].Groups[1].Value.Trim()));
                var error         = TrimError(errorMatches[i].Groups[1].Value.Trim());
                var maze          = EnsureSameLengthLines(RemoveLineNumbers(FormatMaze(mazeMatches[i].Groups[1].Value.Trim())));
                var directions    = RemoveLineNumbers(directionsMatches[i].Groups[1].Value.Trim());
                var result        = new DiffResult(diff == "" && error == "", sectionNumber, testNumber, diff, submission, solution, error, maze, directions);
                diffs.Add(result);
            }
            return(diffs);
        }
示例#2
0
        private void WriteInput(Tuple <string, string> filePaths, DiffResult result)
        {
            var commaDelimited = result.Maze.Split('\n').Select(line => string.Join(",", line.ToCharArray().Select(c => c.ToString())));

            System.IO.File.WriteAllLines(filePaths.Item1, commaDelimited);
            System.IO.File.WriteAllText(filePaths.Item2, result.Moves);
        }
示例#3
0
        /// <summary>
        /// Writes the diff result to a file.
        /// </summary>
        /// <param name="result">Result.</param>
        public void WriteDiff(DiffResult result)
        {
            var outPath   = GetFilePath(result.SectionNumber, result.TestNumber);
            var inputPath = GetInputFilePath(result.SectionNumber, result.TestNumber);

            using (var streamWriter = new System.IO.StreamWriter(outPath)) {
                var diffWriter = new DiffResultWriter(Horizontal, Buffer, Filler);
                diffWriter.Write(result, streamWriter);
                WriteInput(inputPath, result);
            }
        }
示例#4
0
 /// <summary>
 /// Calculates the two dimensional diff from a DiffResult instance.
 /// </summary>
 /// <returns>The corresponding two dimensional diff if the submission
 /// string exists, <c>null</c> otherwise.</returns>
 /// <param name="result">Result.</param>
 private Diff2D?GetDiff2D(DiffResult result)
 {
     if (result.Submission != "")
     {
         var diff2d = new DiffGenerator2D(Buffer, Filler).Generate(result.Solution, result.Submission, result.Maze);
         return(diff2d);
     }
     else
     {
         return(null);
     }
 }
示例#5
0
        /// <summary>
        /// Writes the given parsed diff to the given writer. If the diff is empty
        /// (meaning the test passed), then no output is written.
        /// </summary>
        /// <returns><c>true</c> if output was written; <c>false</c>otherwise.</returns>
        /// <param name="result">Result.</param>
        /// <param name="writer">Writer.</param>
        public bool Write(DiffResult result, System.IO.TextWriter writer)
        {
            if (result.IsEmpty)
            {
                return(false);
            }

            var diff2d = GetDiff2D(result);

            writer.Write("{0} Test {1,2}\n\n", result.SectionNumber, result.TestNumber);
            if (!this.Horizontal)
            {
                writer.Write("Submission:\n{0}\n\n", result.Submission);
                writer.Write("Solution:\n{0}\n\n", result.Solution);
                writer.Write("Initial Maze:\n{0}\n\n", result.Maze);
                if (diff2d.HasValue)
                {
                    writer.Write("Diff 2D:\n{0}\n\n", diff2d.Value.Actual);
                }
            }
            else
            {
                string horizontalMazes = GetHorizontalMazes(result.Submission, result.Solution, result.Maze);
                writer.Write("{0}\n\n", horizontalMazes);
                if (diff2d.HasValue)
                {
                    string horizontalDiffs = GetHorizontalMazes(diff2d.Value.Actual, diff2d.Value.Expected, diff2d.Value.Input);
                    writer.Write("Diff 2D:\n{0}\n\n", horizontalDiffs);
                }
            }

            writer.Write("Diff:\n{0}\n\n", result.Diff);

            writer.Write("Moves:\n{0}\n\n", result.Moves);
            if (result.Error == string.Empty)
            {
                writer.Write("No error.");
            }
            else
            {
                writer.Write("Error:\n{0}\n", result.Error);
            }
            return(true);
        }