public void TestCmpfiles(bool okay) { string checker = Path.GetFullPath("checker_cmpfiles.exe".GetLocalFilePath()); Random r = new Random(1337); string file1 = Path.GetTempFileName(); string file2 = Path.GetTempFileName(); File.WriteAllText(file1, "The quick brown fox jumps over the lazy dog"); if (okay) { File.WriteAllText(file2, "The quick brown fox jumps over the lazy dog"); } else { File.WriteAllText(file2, "The quick brown fox jumps over the lazy dog."); } IOutputVerifier verifier = new ExecutableOutputVerifierMutable { ConsoleApplication = new FileSystemConsoleApplication(checker, CheckerCore.CrashReporting.CrashReportFinder.Instance), Arguments = new VerifierArgumentType[] { VerifierArgumentType.FileStdout, VerifierArgumentType.FileSolution }, Bindings = new IVerifierResultBinder[] { new StdOutContainsBinder("OK", new OutputVerificationResult( OutputVerificationResultType.CorrectAnswer, 1 )), new StdOutContainsBinder("NO", new OutputVerificationResult( OutputVerificationResultType.WrongAnswer, 0 )) }, Stdin = VerifierArgumentType.None }; OutputVerificationInfo info = new OutputVerificationInfo( 0, null, null, StringOrFile.FromFile(file1), StringOrFile.FromFile(file2) ); OutputVerificationResult result = verifier.Verify(info); if (okay) { Assert.AreEqual(result.ScoreMultiplier, 1); Assert.AreEqual(result.Type, OutputVerificationResultType.CorrectAnswer); } else { Assert.AreEqual(result.ScoreMultiplier, 0); Assert.AreEqual(result.Type, OutputVerificationResultType.WrongAnswer); } }
public bool TryCreateTestViewModels(out List <SolutionTest> tests) { //TODO: Fix this shit because it's ugly Java-ish practice if (!CanCreateTests) { tests = null; return(false); } string[] inputs = TestInputFiles.PathsArray.ToArray(); string[] expectedOutputs = TestSolutionFiles.PathsArray.ToArray(); if (SortFilenamesAlphabetically) { Array.Sort <string>(inputs, (x, y) => x.CompareTo(y)); Array.Sort <string>(expectedOutputs, (x, y) => x.CompareTo(y)); } ; double totalExplicitScore = Tests .Where(x => !double.IsNaN(x.MaxScore)) .Sum(x => x.MaxScore); int autoScoreCount = Tests .Where(x => double.IsNaN(x.MaxScore)) .Count(); double autoScore = (100.00 - totalExplicitScore) / autoScoreCount; tests = new List <SolutionTest>(); for (int i = 0; i < inputs.Length; i++) { tests.Add(new SolutionTest( inputFile: StringOrFile.FromFile(inputs[i]), expectedOutputFile: StringOrFile.FromFile(expectedOutputs[i]), outputVerifier: Checker.CreateModel(), processArguments: String.Empty, timeLimit: TimeSpan.FromSeconds(TimeLimitSeconds), maxScore: !double.IsNaN(Tests[i].MaxScore) ? Tests[i].MaxScore : autoScore, testGroup: Tests[i].TestGroup ?? string.Empty )); } return(true); }