Exemple #1
0
        public void TestAdd()
        {
            ProblemData problem = new ProblemData(0);
            problem.Name = "Hello, World!";
            problem.Class = new ClassData(2);

            //This test works as of 10:30am on 2/21
            //Commenting it out to prevent cluttering the database
            //- Josh
            //Assert.IsTrue(problemModel.Add(problem));
        }
Exemple #2
0
        public void TestUpdateSets()
        {
            ProblemData prob = new ProblemData(3);
            List<ProblemSetData> original = setModel.GetForProblem(prob);

            //Test remove from sets
            Assert.IsTrue(problemModel.UpdateSets(prob, new List<ProblemSetData>()));
            Assert.AreEqual(0, setModel.GetForProblem(prob).Count);

            //Test add to sets
            Assert.IsTrue(problemModel.UpdateSets(prob, original));
            CollectionAssert.AreEqual(original, setModel.GetForProblem(prob));

            //Test add bad data
            List<ProblemSetData> badList = new List<ProblemSetData>(original);
            badList.Add(new ProblemSetData { Id = original[0].Id, PrereqCount = original[0].PrereqCount }); //Can't have duplicate set entries
            Assert.IsTrue(problemModel.UpdateSets(prob, badList));
            CollectionAssert.AreEqual(original, setModel.GetForProblem(prob));
        }
Exemple #3
0
 public int AddProblem(ProblemData prob)
 {
     return problemModel.Add(prob);
 }
Exemple #4
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;
        }
Exemple #5
0
 public bool ModifyProblem(ProblemData prob)
 {
     return problemModel.Modify(prob);
 }
 public JsonResult Test(int id, string instructorCode, string studentCode)
 {
     try
     {
         ProblemData prob = new ProblemData(id);
         prob.SolutionCode = instructorCode;
         string output = GlobalStaticVars.StaticCore.SolveProblem(WebSecurity.CurrentUserId, prob, studentCode, false);
         if (output == null)
             return Json(new { success = true });
         else
             return Json(new { success = false, output = output });
     }
     catch (Exception e)
     {
         RedirectToAction("ServerError", "Error");
         return new JsonResult();
     }
 }
Exemple #7
0
        public ActionResult TestPage(ProblemData prob)
        {
            try
            {
                prob.Description = BBCode.ToHtml(prob.Description);
                prob.SolutionCode = null;
                    //Do not send solution code to client so it can't be seen and used to cheat the problem

                ViewBag.Record = false;

                return View("Solve", prob);
            }
            catch (Exception e)
            {
                return RedirectToAction("ServerError", "Error");
            }
        }