public void FutureTest()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var output = util.Execute(@"x = 3/2
     print(x)");
     Assert.AreEqual(output, "1.5\r\n");
 }
 public void UnallowedCodeTest1()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var studentCode = @"import os";
     var output = util.Execute(studentCode);
     Assert.AreEqual(output, "Code not permitted: os");
 }
        public void ReturnTest()
        {
            PyInterpretUtility util = new PyInterpretUtility();
            var output = util.Execute(@"def myFunction(number):
            print(number)

            def professorFunction(num):
            myFunction(num)

            professorFunction(3)    "
            );
            Assert.AreEqual(output, "3\r\n");
        }
 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");
 }
        public void EncapsulatedTest()
        {
            PyInterpretUtility util = new PyInterpretUtility();
            var output = util.Execute(@"def encap():
            def myFunction(number):
            print(number)

            def professorFunction():
            myFunction(3)

            professorFunction()

            encap()"
            );
            Assert.AreEqual(output, "3\r\n");
        }
Exemple #6
0
 public string ExecutePythonCode(string code)
 {
     var py = new Modules.PyInterpret.PyInterpretUtility();
     return py.Execute(code);
 }
Exemple #7
0
        /// <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;
        }
 public void PrintTest()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var output = util.Execute("print(\"TESTVALUE\")");
     Assert.AreEqual(output, "TESTVALUE\r\n");
 }
 public void UnallowedCodeTest5()
 {
     PyInterpretUtility util = new PyInterpretUtility();
     var studentCode = @"eval(etc)";
     var output = util.Execute(studentCode);
     Assert.AreEqual(output, "Code not permitted: eval");
 }