//Since RunExe returns the results string, we run it and right after add it to the result list. public void RunSubmittedProgram() { if (exeExists) { if (TestCases.testCases.Count != 0) { numberOfOverallResults = 0; submittedProgramOutputs.Clear(); //Reset the output results upon a new Run so compiledProgramOutputs.Clear(); //we can add fresh results. foreach (SingleTestCase tc in TestCases.testCases) { if (File.Exists(exePath) && Submissions.checkExe) //If there's a submitted .exe and it needs to be checked. { string outputResults = CodeChecker.RunEXE(exePath, tc.input); submittedProgramOutputs.Add(new OutputResult(outputResults)); } if (File.Exists(compiledExePath) && Submissions.checkCode) //If there's just the compiled .exe and only it needs to be checked. { string outputResults = CodeChecker.RunEXE(compiledExePath, tc.input); compiledProgramOutputs.Add(new OutputResult(outputResults)); } } numberOfOverallResults = Math.Max(submittedProgramOutputs.Count, compiledProgramOutputs.Count); } if (File.Exists(exePath) && File.Exists(compiledExePath)) { possibleCheating = !CompareBothLists(); //If the 2 lists are different, there might be a possible cheating. Check manually. } } }
public void CompileCode_ReturnsOutput() { //Arrange var filePath = @"..\..\..\Assets\Test Required FIles\CodeCheckerTest\Source.c"; //Act var results = CodeChecker.CompileCode(filePath); Assert.IsNotNull(results); }
public void RunEXE_ReturnsOutput() { //Arrange var filePath = @"..\..\..\Assets\Test Required FIles\CodeCheckerTest\Source.exe"; var input = "2 3"; //Act var results = CodeChecker.RunEXE(filePath, input); Assert.IsNotNull(results); }
//Run this function from Start buttun. Compile the .c code. //We don't pass an argument here since SingleSubmission it supposed to be contained in Submissions and it has the list. public void CompileSubmittedCode() { if (codeExists && Submissions.checkCode) { this.compilerOutput = CodeChecker.CompileCode(codePath); //If it succeeds, the new .exe file path should be this (replace ".c" with ".exe"): this.compiledExePath = codePath.Substring(0, codePath.Length - 2) + ".exe"; } if (File.Exists(compiledExePath)) { this.exeExists = true; //If it works, then we have a code. } else { this.compiledExePath = null; //If the path doesn't exist (compilation failed), remove it from saved .exe path. } }