public void ProfessorCodeTest() { PyInterpretUtility util = new PyInterpretUtility(); var studentCode = @"def myFunc(): return 1"; var profCode = @"output = myFunc() if(output == 1): print(""Correct!"") else: print(""You fail!"")"; var output = util.Test(studentCode, profCode); Assert.AreEqual(output, "Correct!\r\n"); }
/// <summary> /// Tests student code against the instructor solution code for the specified problem /// and records the result in the database if desired. /// </summary> /// <param name="userId">The currently logged in user solving the problem</param> /// <param name="prob">The problem being solved</param> /// <param name="studentCode">The student solution code</param> /// <param name="record">true to record this attempt in the database, false otherwise (optional, defaults to true)</param> /// <returns>null if the solution is correct, otherwise an error message</returns> public string SolveProblem(int userId, ProblemData prob, string studentCode, bool record = true) { var py = new Modules.PyInterpret.PyInterpretUtility(); string output = py.Test(studentCode, prob.SolutionCode); bool correct = false; if (output == "Correct\r\n" || output == "Correct") correct = true; if (record) problemModel.UpdateSolution(new UserData(userId), prob, correct); if (correct) return null; else return output; }