Example #1
0
        public string ToHtml(TestCase test)
        {
            StringBuilder result = new StringBuilder();

            // Check for std input
            if (!string.IsNullOrEmpty(test.StdInText))
            {
                string htmlStdInput   = JarvisEncoding.ToHtmlEncodingWithNewLines(test.StdInText);
                string caseHeaderText = "Test Input:";

                result.Append(Utilities.BuildInputBlock(caseHeaderText, htmlStdInput));
            }

            // check for std output file
            if (!string.IsNullOrEmpty(test.StdOutputFile))
            {
                if (test.StdOutText.Length < 100000)
                {
                    string expectedStdOutput = Utilities.ReadFileContents(test.TestsPath + test.StdOutputFile);

                    string htmlActualStdOutput   = JarvisEncoding.ToHtmlEncodingWithNewLines(test.StdOutText);
                    string htmlExpectedStdOutput = JarvisEncoding.ToHtmlEncodingWithNewLines(expectedStdOutput);
                    string htmlDiff = JarvisEncoding.GetDiff(htmlActualStdOutput, htmlExpectedStdOutput);

                    string caseHeaderText = "Test Output:";

                    if (string.IsNullOrWhiteSpace(test.StdOutText))
                    {
                        caseHeaderText += "<br/ ><span style=\"color:#ff0000\">Warning: actual output was empty!</span>";
                    }

                    result.Append(Utilities.BuildDiffBlock(caseHeaderText, htmlActualStdOutput, htmlExpectedStdOutput, htmlDiff));

                    test.Passed = htmlDiff.Contains("No difference");
                }
                else
                {
                    test.Passed = false;
                    result.Append("<p>Too much output!</p>");
                }
            }

            return(result.ToString());
        }
Example #2
0
        public string ToHtml(TestCase test)
        {
            StringBuilder result = new StringBuilder();

            // check for file output files
            if (test.FileOutputFiles.Count > 0)
            {
                foreach (OutputFile fileout in test.FileOutputFiles)
                {
                    string   expectedOutput = Utilities.ReadFileContents(test.TestsPath + fileout.CourseFile);
                    FileInfo info           = new FileInfo(test.HomeworkPath + fileout.StudentFile);
                    if (File.Exists(test.HomeworkPath + fileout.StudentFile) && info.Length < 1000000)
                    {
                        string actualOutput = Utilities.ReadFileContents(test.HomeworkPath + fileout.StudentFile);

                        string htmlExpectedOutput = JarvisEncoding.ToHtmlEncodingWithNewLines(expectedOutput);
                        string htmlActualOutput   = JarvisEncoding.ToHtmlEncodingWithNewLines(actualOutput);

                        string htmlDiff = JarvisEncoding.GetDiff(htmlActualOutput, htmlExpectedOutput);

                        result.Append(Utilities.BuildDiffBlock("From " + fileout.StudentFile + ":", htmlActualOutput, htmlExpectedOutput, htmlDiff));

                        test.Passed = htmlDiff.Contains("No difference");
                    }
                    else if (!File.Exists(test.HomeworkPath + fileout.StudentFile))
                    {
                        test.Passed = false;
                        result.Append("<p>Cannot find output file: " + fileout.StudentFile + "</p>");
                    }
                    else if (info.Length >= 1000000)
                    {
                        test.Passed = false;
                        result.Append("<p>The file output was too large [" + info.Length.ToString() + "] bytes!!!");
                    }
                }
            }

            return(result.ToString());
        }