// copy constuctor public ExerciseSingle(ExerciseSingle othSingle) { if (othSingle != this) { Name = othSingle.Name; this.Problem = (ExerciseProblem)othSingle.Problem.Clone(); } }
// run the program given exercise's test inputs // and return the result that consists of // Item1(pass or not) and Item2 (program's output) private static Tuple <bool, string[]> RunAndTest(ExerciseSingle exercise) { // run the generated file with exercise test inputs string programPath = outputProgramsPath + exercise.Name + dotExe; string[] runtimeArgs = exercise.Problem.TestInputs.ToArray(); string[] actualOutputs = ExternExeRunner.Run(programPath, null, runtimeArgs); // check outputs by asserting // that if the exepectedOutputs is the same as actualOutputs string[] expectedOutputs = exercise.Problem.TestOutputs.ToArray(); if (!Utils.IsSameStringArray(actualOutputs, expectedOutputs)) { return(new Tuple <bool, string[]>(false, expectedOutputs)); } else { return(new Tuple <bool, string[]>(true, expectedOutputs)); } }
public static bool CompileAndTest(string sourceFiles, ExerciseSingle exercise, out string[] errors) { // validate inputs if (sourceFiles == null || sourceFiles.Length == 0 || exercise == null) { throw new System.ArgumentException(); } // compile and generate a executable file (.exe) bool compileSuccess = Compile(exercise.Name, sourceFiles, out errors); if (!compileSuccess) { return(false); } // run the generated file and test it var testResult = RunAndTest(exercise); return(testResult.Item1); }