コード例 #1
0
ファイル: Checker.cs プロジェクト: Dimitvp/OpenJudgeSystem
        protected virtual CheckerDetails PrepareCheckerDetails(
            string receivedOutput,
            string expectedOutput,
            bool isTrialTest,
            CheckerDetails adminCheckerDetails)
        {
            CheckerDetails checkerDetails;
            if (isTrialTest)
            {
                const int FragmentMaxLength = 4096;

                checkerDetails = default(CheckerDetails);

                var firstDifferenceIndex = expectedOutput.GetFirstDifferenceIndexWith(receivedOutput, this.IgnoreCharCasing);

                if (expectedOutput != null)
                {
                    checkerDetails.ExpectedOutputFragment =
                        PrepareOutputFragment(expectedOutput, firstDifferenceIndex, FragmentMaxLength);
                }

                if (receivedOutput != null)
                {
                    checkerDetails.UserOutputFragment =
                        PrepareOutputFragment(receivedOutput, firstDifferenceIndex, FragmentMaxLength);
                }
            }
            else
            {
                // Test report for admins
                checkerDetails = adminCheckerDetails;
            }

            return checkerDetails;
        }
コード例 #2
0
        public override CheckerResult Check(string inputData, string receivedOutput, string expectedOutput, bool isTrialTest)
        {
            this.NormalizeEndLines(ref receivedOutput);
            this.NormalizeEndLines(ref expectedOutput);

            var userFileReader = new StringReader(receivedOutput);
            var correctFileReader = new StringReader(expectedOutput);

            var userLines = new List<string>();
            var correctLines = new List<string>();

            var resultType = CheckerResultType.Ok;

            var adminCheckerDetails = new CheckerDetails();
            int lineNumber = 0;
            using (userFileReader)
            {
                using (correctFileReader)
                {
                    var userLine = userFileReader.ReadLine();
                    var correctLine = correctFileReader.ReadLine();

                    while (userLine != null && correctLine != null)
                    {
                        correctLines.Add(correctLine);
                        userLines.Add(userLine);

                        correctLine = correctFileReader.ReadLine();
                        userLine = userFileReader.ReadLine();

                        lineNumber++;
                    }

                    if (userLine != correctLine)
                    {
                        // one of the streams still has lines
                        adminCheckerDetails = this.PrepareAdminCheckerDetailsForInvalidNumberOfLines(lineNumber, userLine, correctLine);
                        resultType = CheckerResultType.InvalidNumberOfLines;
                    }
                }
            }

            userLines.Sort();
            correctLines.Sort();

            if (resultType == CheckerResultType.Ok)
            {
                for (int i = 0; i < userLines.Count; i++)
                {
                    if (!this.AreEqualExactLines(userLines[i], correctLines[i]))
                    {
                        adminCheckerDetails = this.PrepareAdminCheckerDetailsForDifferentLines(
                            i,
                            correctLines[i],
                            userLines[i]);
                        resultType = CheckerResultType.WrongAnswer;
                        break;
                    }
                }
            }

            var checkerDetails = new CheckerDetails();
            if (resultType != CheckerResultType.Ok)
            {
                checkerDetails = this.PrepareCheckerDetails(receivedOutput, expectedOutput, isTrialTest, adminCheckerDetails);
            }

            return new CheckerResult
            {
                IsCorrect = resultType == CheckerResultType.Ok,
                ResultType = resultType,
                CheckerDetails = checkerDetails
            };
        }
コード例 #3
0
ファイル: Checker.cs プロジェクト: Dimitvp/OpenJudgeSystem
        protected virtual CheckerDetails PrepareAdminCheckerDetailsForInvalidNumberOfLines(
            int lineNumber,
            string userLine,
            string correctLine)
        {
            const int FragmentMaxLength = 256;

            var adminCheckerDetails = new CheckerDetails
            {
                Comment = string.Format("Invalid number of lines on line {0}", lineNumber)
            };

            var firstDifferenceIndex = correctLine.GetFirstDifferenceIndexWith(userLine, this.IgnoreCharCasing);

            if (correctLine != null)
            {
                adminCheckerDetails.ExpectedOutputFragment =
                    PrepareOutputFragment(correctLine, firstDifferenceIndex, FragmentMaxLength);
            }

            if (userLine != null)
            {
                adminCheckerDetails.UserOutputFragment =
                    PrepareOutputFragment(userLine, firstDifferenceIndex, FragmentMaxLength);
            }

            return adminCheckerDetails;
        }
コード例 #4
0
        protected CheckerResult CheckLineByLine(
            string inputData,
            string receivedOutput,
            string expectedOutput,
            Func<string, string, bool> areEqual,
            bool isTrialTest)
        {
            this.NormalizeEndLines(ref receivedOutput);
            this.NormalizeEndLines(ref expectedOutput);

            var userFileReader = new StringReader(receivedOutput);
            var correctFileReader = new StringReader(expectedOutput);

            CheckerResultType resultType;

            var adminCheckerDetails = new CheckerDetails();
            int lineNumber = 0;
            using (userFileReader)
            {
                using (correctFileReader)
                {
                    while (true)
                    {
                        string userLine = userFileReader.ReadLine();
                        string correctLine = correctFileReader.ReadLine();

                        if (userLine == null && correctLine == null)
                        {
                            // No more lines in both streams
                            resultType = CheckerResultType.Ok;
                            break;
                        }

                        if (userLine == null || correctLine == null)
                        {
                            // One of the two streams is already empty
                            adminCheckerDetails = this.PrepareAdminCheckerDetailsForInvalidNumberOfLines(
                                lineNumber,
                                userLine,
                                correctLine);
                            resultType = CheckerResultType.InvalidNumberOfLines;
                            break;
                        }

                        if (!areEqual(userLine, correctLine))
                        {
                            // Lines are different => wrong answer
                            adminCheckerDetails = this.PrepareAdminCheckerDetailsForDifferentLines(
                                lineNumber,
                                correctLine,
                                userLine);
                            resultType = CheckerResultType.WrongAnswer;
                            break;
                        }

                        lineNumber++;
                    }
                }
            }

            var checkerDetails = new CheckerDetails();
            if (resultType != CheckerResultType.Ok)
            {
                checkerDetails = this.PrepareCheckerDetails(receivedOutput, expectedOutput, isTrialTest, adminCheckerDetails);
            }

            return new CheckerResult
            {
                IsCorrect = resultType == CheckerResultType.Ok,
                ResultType = resultType,
                CheckerDetails = checkerDetails
            };
        }