public async Task GradeSubmissionAsync_AllBlanksCorrect_FullCredit()
		{
			var question = new ShortAnswerQuestion()
			{
				Blanks = Collections.CreateList
				(
					new ShortAnswerQuestionBlank() { Name = "A", Answer = "One" },
					new ShortAnswerQuestionBlank() { Name = "B", Answer = "Two" }
				)
			};

			var submission = new ShortAnswerQuestionSubmission()
			{
				Blanks = Collections.CreateList
				(
					new SubmissionBlank() { Name = "A", Answer = "One" },
					new SubmissionBlank() { Name = "B", Answer = "Two" }
				)
			};

			var grader = new ShortAnswerQuestionGrader(question);
			var result = await grader.GradeSubmissionAsync(submission);

			Assert.Equal(new[] { true, true }, ((ShortAnswerQuestionResult)result.Result).Correct);
			Assert.Equal(1.0, result.Score);
		}
        public async Task GradeSubmissionAsync_BlankNamesContainCarriageReturns_ParsedCorrectly()
        {
            var question = new ShortAnswerQuestion()
            {
                Blanks = Collections.CreateList
                         (
                    new ShortAnswerQuestionBlank()
                {
                    Name = "A\n", Answer = "One"
                }
                         )
            };

            var submission = new ShortAnswerQuestionSubmission()
            {
                Blanks = Collections.CreateList
                         (
                    new SubmissionBlank()
                {
                    Name = "A\r\n", Answer = "One"
                }
                         )
            };

            var grader = new ShortAnswerQuestionGrader(question);
            var result = await grader.GradeSubmissionAsync(submission);

            Assert.Equal(new[] { true }, ((ShortAnswerQuestionResult)result.Result).Correct);
            Assert.Equal(1.0, result.Score);
        }
		public async Task GradeSubmissionAsync_SomeBlanksIncorrect_NoCredit()
		{
			var question = new ShortAnswerQuestion()
			{
				AllowPartialCredit = false,
				Blanks = Collections.CreateList
				(
					new ShortAnswerQuestionBlank() { Name = "A", Answer = "One" },
					new ShortAnswerQuestionBlank() { Name = "B", Answer = "Two" }
				)
			};

			var submission = new ShortAnswerQuestionSubmission()
			{
				Blanks = Collections.CreateList
				(
					new SubmissionBlank() { Name = "A", Answer = "One" },
					new SubmissionBlank() { Name = "B", Answer = "Wrong" }
				)
			};

			var grader = new ShortAnswerQuestionGrader(question);
			var result = await grader.GradeSubmissionAsync(submission);

			Assert.Equal(new[] { true, false }, ((ShortAnswerQuestionResult)result.Result).Correct);
			Assert.Equal(0.0, result.Score);
		}
Beispiel #4
0
        public void ShortAnswerQuestionTest()
        {
            ShortAnswerQuestion q = new ShortAnswerQuestion("Titre", "Texte");

            //
            Assert.AreEqual(QuestionType.ShortAnswer, q.Type);
            Assert.AreEqual("Titre", q.Name);
            Assert.AreEqual("Texte", q.QuestionText);
            Assert.IsNotNull(q.Answers);
        }
Beispiel #5
0
        public void ShortAnswerQuestionDefaultTest()
        {
            ShortAnswerQuestion q = new ShortAnswerQuestion();

            //
            Assert.AreEqual(QuestionType.ShortAnswer, q.Type);
            Assert.AreEqual(true, String.IsNullOrEmpty(q.Name));
            Assert.AreEqual(true, String.IsNullOrEmpty(q.QuestionText));
            Assert.IsNotNull(q.Answers);
            Assert.AreEqual(false, q.Is100Percent);
        }
        public void getQuestion_EmptyStringTest()
        {
            String   strQuestion = "";
            String   strAnswer   = "Answer 111";
            Question q           = new ShortAnswerQuestion(strQuestion, strAnswer);


            String strResult = q.getQuestion();


            Assert.AreEqual(strQuestion, strResult);
        }
        public void checkAnswer_NormalTest()
        {
            // Arrange
            String   strQuestion = "Test 301";
            String   strAnswer   = "Answer 301";
            Question q           = new ShortAnswerQuestion(strQuestion, strAnswer);

            //Act

            //Assert
            Assert.IsTrue(q.checkAnswer(strAnswer));
        }
Beispiel #8
0
        public void ShortAnswerQuestionAddTest2()
        {
            ShortAnswerQuestion q = new ShortAnswerQuestion();

            //
            q.AddAnswer("true", "aucune", 50);
            q.AddAnswer("true", "aucune", 50);
            Action action = () => q.AddAnswer("true", "aucune", 50);

            Assert.ThrowsException <OverflowException>(action);
            //
            Trace.WriteLine(q.MoodleXML.OuterXml);
        }
        public void checkAnswer_ExtrasSpaceAfterTest()
        {
            // Arrange
            String   strQuestion             = "Test question here?";
            String   strAnswer               = "Answer to question";
            String   strAnswerWithSpaceAfter = "Answer to question ";
            Question q = new ShortAnswerQuestion(strQuestion, strAnswer);

            //Act

            //Assert
            Assert.IsTrue(q.checkAnswer(strAnswerWithSpaceAfter));
        }
        // GET: Activities/DisplaySAQLogForStudent
        public ActionResult DisplaySAQLogForStudent(long saqID, string StudentPhone)
        {
            ActivityData        activityData = rsContext.getActivity(saqID);
            ShortAnswerQuestion saq          = Adapting.getShortAnswerQuestionFromData((ShortAnswerQuestionData)activityData);

            AnswerByPhone answer  = Adapting.getAnswerByPhoneFromData(rsContext.getAnswerByPhoneAndActivityID(saq.id, StudentPhone, saq.RoomId));
            Student       student = Adapting.getStudentFromData(rsContext.getStudent(StudentPhone, answer.RoomID));

            TempData["StudentAnswer"] = answer.Answer;
            TempData["StudentName"]   = student.FirstName + " " + student.LastName;

            return(View(saq));
        }
        public void getQuestion_LongStringTest()
        {
            // Arrange
            String   strQuestion = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
            String   strAnswer   = "Answer 111";
            Question q           = new ShortAnswerQuestion(strQuestion, strAnswer);

            //Act
            String strResult = q.getQuestion();

            //Assert
            Assert.AreEqual(strQuestion, strResult);
        }
        public void checkAnswer_LowerCaseTest()
        {
            // Arrange
            String   strQuestion        = "Test 302";
            String   strAnswer          = "Answer 302";
            String   strLowerCaseAnswer = "answer 302";
            Question q = new ShortAnswerQuestion(strQuestion, strAnswer);

            //Act

            //Assert
            Assert.IsTrue(q.checkAnswer(strLowerCaseAnswer));
        }
        public void getAnswer_NormalTest()
        {
            // Arrange
            String   strQuestion = "Test 201";
            String   strAnswer   = "Answer 201";
            Question q           = new ShortAnswerQuestion(strQuestion, strAnswer);

            //Act
            String strResult = q.getAnswer();

            //Assert
            Assert.AreEqual(strAnswer, strResult);
        }
        public void checkAnswer_WrongAnswerTest()
        {
            // Arrange
            String   strQuestion    = "Test 304";
            String   strAnswer      = "Given Answer 304";
            String   strWrongAnswer = "Wrong Answer 304";
            Question q = new ShortAnswerQuestion(strQuestion, strAnswer);

            //Act
            String strResult = q.getAnswer();

            //Assert
            Assert.IsFalse(q.checkAnswer(strWrongAnswer));
        }
Beispiel #15
0
        public void ShortAnswerQuestionAddTest()
        {
            ShortAnswerQuestion q = new ShortAnswerQuestion();

            //
            q.AddAnswer("Réponse", "Feedback", 100);
            Assert.AreEqual(1, q.Answers.Count);
            //
            Answer shortAnswer = q.Answers[0];

            Assert.AreEqual("Réponse", shortAnswer.Text);
            Assert.AreEqual("Feedback", shortAnswer.Feedback);
            Assert.AreEqual(100, shortAnswer.Fraction);
        }
        /// <summary>
        /// Creates a short answer question.
        /// </summary>
        /// <param name="number">Question number</param>
        /// <param name="questionText">Question</param>
        /// <param name="answers">Answers to question (as strings)</param>
        /// <returns>Created <seealso cref="ShortAnswerQuestion"/> instance.</returns>
        public static ShortAnswerQuestion Build(int number, string questionText, IEnumerable <string> answers)
        {
            var question = new ShortAnswerQuestion(number, questionText)
            {
                Id = number
            };

            foreach (var answer in answers)
            {
                question.AddAnswer(new ShortAnswer(answer));
            }

            return(question);
        }
Beispiel #17
0
        public void ShortAnswerFromXMLTest()
        {
            String xml = "  <question type='shortanswer'>" +
                         "    <name>" +
                         "      <text>Linux</text>" +
                         "    </name>" +
                         "    <questiontext format='html'>" +
                         "      <text><![CDATA[<p>Linux</p>]]></text>" +
                         "    </questiontext>" +
                         "    <generalfeedback format='html'>" +
                         "      <text>feedback</text>" +
                         "    </generalfeedback>" +
                         "    <defaultgrade>1.0000000</defaultgrade>" +
                         "    <penalty>0.3333333</penalty>" +
                         "    <hidden>0</hidden>" +
                         "    <usecase>0</usecase>" +
                         "    <answer fraction='100' format='moodle_auto_format'>" +
                         "      <text>trim</text>" +
                         "      <feedback format='html'>" +
                         "        <text></text>" +
                         "      </feedback>" +
                         "    </answer>" +
                         "  </question>";
            //
            //
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            //
            XmlElement root = doc.DocumentElement;
            //
            ShortAnswerQuestion question = new ShortAnswerQuestion();

            question.MoodleXML = (XmlNode)root;
            //
            Assert.AreEqual("Linux", question.Name);
            Assert.AreEqual("<p>Linux</p>", question.QuestionText);
            Assert.AreEqual("feedback", question.GeneralFeedback);
            Assert.AreEqual(1, question.DefaultGrade);
            Assert.AreEqual(0.3333333, question.Penalty);
            Assert.AreEqual(false, question.UseCase);
            //
            Assert.AreEqual(1, question.Answers.Count);
            Answer ans = question.Answers[0];

            Assert.AreEqual(100, ans.Fraction);
            Assert.AreEqual("trim", ans.Text);
            Assert.AreEqual(true, String.IsNullOrEmpty(ans.Feedback));
        }
 /// <summary>
 /// Verifies that the given short answer question was correctly duplicated.
 /// </summary>
 private void VerifyShortAnswerQuestion(
     DatabaseContext dbContext,
     ShortAnswerQuestion oldQuestion,
     ShortAnswerQuestion newQuestion)
 {
     VerifyCollectionDuplicated
     (
         dbContext,
         oldQuestion,
         newQuestion,
         q => q.Blanks,
         b => b.Id,
         b => b.Name
     );
 }
        // GET: Student/ViewRoomOrWaitingScreen
        public ActionResult ViewRoomOrWaitingScreen(StudentLoginViewModel model)
        {
            RoomData     roomData     = rsContext.getRoom(model.Room);
            ActivityData activityData = rsContext.getActivity(roomData.CurrentActivityId);

            if (activityData == null)
            {
                //Waiting Screen
                return(RedirectToAction("Wait", model));
            }
            else
            {
                if (activityData is TrueFalseQuestionData)
                {
                    //True/False Question
                    TrueFalseQuestion tfq = (TrueFalseQuestion)Adapting.getTrueFalseQuestionFromData((TrueFalseQuestionData)activityData);
                    return(RedirectToAction("TrueFalseQuestion", new { expId = -1, currActivityIndex = -1, activityId = tfq.id, numOfActivities = 0, studentPhone = model.PhoneNumber, studentRoom = model.Room }));
                }
                else if (activityData is ShortAnswerQuestionData)
                {
                    //Short Answer Question
                    ShortAnswerQuestion saq = (ShortAnswerQuestion)Adapting.getShortAnswerQuestionFromData((ShortAnswerQuestionData)activityData);
                    return(RedirectToAction("ShortAnswerQuestion", new { expId = -1, currActivityIndex = -1, activityId = saq.id, numOfActivities = 0, studentPhone = model.PhoneNumber, studentRoom = model.Room }));
                }
                else if (activityData is AmericanQuestionData)
                {
                    //American Answer Question
                    AmericanQuestion aq = (AmericanQuestion)Adapting.getAmericanQuestionFromData((AmericanQuestionData)activityData);
                    return(RedirectToAction("AmericanQuestion", new { expId = -1, currActivityIndex = -1, activityId = aq.id, numOfActivities = 0, studentPhone = model.PhoneNumber, studentRoom = model.Room }));
                }

                else if (activityData is ExperimentData)
                {
                    // Experiment
                    Experiment exp = (Experiment)Adapting.getExperimentFromData((ExperimentData)activityData);
                    if (exp.ActiveExpID == 0)
                    {
                        //Waiting Screen
                        Thread.Sleep(2000);
                        return(RedirectToAction("Wait", model));
                    }
                    return(RedirectToAction("GroupCreation", new { expId = exp.id, studentPhone = model.PhoneNumber, studentRoom = model.Room, currActivityIndex = 0 }));
                }
            }

            return(View());
        }
Beispiel #20
0
        public async Task GradeSubmissionAsync_SomeBlanksIncorrect_NoCredit()
        {
            var question = new ShortAnswerQuestion()
            {
                AllowPartialCredit = false,
                Blanks             = Collections.CreateList
                                     (
                    new ShortAnswerQuestionBlank()
                {
                    Name = "A", Answer = "One"
                },
                    new ShortAnswerQuestionBlank()
                {
                    Name = "B", Answer = "Two"
                }
                                     )
            };

            var submission = new ShortAnswerQuestionSubmission()
            {
                Blanks = Collections.CreateList
                         (
                    new SubmissionBlank()
                {
                    Name = "A", Answer = "One"
                },
                    new SubmissionBlank()
                {
                    Name = "B", Answer = "Wrong"
                }
                         )
            };

            var grader = new ShortAnswerQuestionGrader(question);
            var result = await grader.GradeSubmissionAsync(submission);

            Assert.Equal(new[] { true, false }, ((ShortAnswerQuestionResult)result.Result).Correct);
            Assert.Equal(0.0, result.Score);
        }
Beispiel #21
0
        public List <TestQuestion> GetQuestions()
        {
            List <TestQuestion> questions = null;
            string dir = System.IO.Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "Midterm.json");

            using (StreamReader sr = new StreamReader(dir))
            {
                string jsonContent = sr.ReadToEnd();
                questions = new List <TestQuestion>(JsonConvert.DeserializeObject <List <TestQuestion> >(jsonContent));
            }

            for (int i = 0; i < questions.Count; i++)
            {
                switch (questions[i].Type)
                {
                case "TrueFalseQuestion":
                    questions[i] = new TrueFalseQuestion(questions[i]);
                    break;

                case "ShortAnswerQuestion":
                    questions[i] = new ShortAnswerQuestion(questions[i]);
                    break;

                case "LongAnswerQuestion":
                    questions[i] = new LongAnswerQuestion(questions[i]);
                    break;

                case "MultipleChoiceQuestion":
                    questions[i] = new MultipleChoiceQuestion(questions[i]);
                    break;

                default:
                    break;
                }
            }

            return(questions);
        }
Beispiel #22
0
        public async Task GradeSubmissionAsync_AllBlanksCorrect_FullCredit()
        {
            var question = new ShortAnswerQuestion()
            {
                Blanks = Collections.CreateList
                         (
                    new ShortAnswerQuestionBlank()
                {
                    Name = "A", Answer = "One"
                },
                    new ShortAnswerQuestionBlank()
                {
                    Name = "B", Answer = "Two"
                }
                         )
            };

            var submission = new ShortAnswerQuestionSubmission()
            {
                Blanks = Collections.CreateList
                         (
                    new SubmissionBlank()
                {
                    Name = "A", Answer = "One"
                },
                    new SubmissionBlank()
                {
                    Name = "B", Answer = "Two"
                }
                         )
            };

            var grader = new ShortAnswerQuestionGrader(question);
            var result = await grader.GradeSubmissionAsync(submission);

            Assert.Equal(new[] { true, true }, ((ShortAnswerQuestionResult)result.Result).Correct);
            Assert.Equal(1.0, result.Score);
        }
        //POST: Teacher/DisplayShortAnswerQuestion
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        public ActionResult DisplayShortAnswerQuestion(long ActivityId)
        {
            ShortAnswerQuestionData quesData    = (ShortAnswerQuestionData)rsContext.getActivity(ActivityId);
            TeacherData             teacherData = rsContext.getTeacher(User.Identity.Name);

            if (teacherData == null)
            {
                throw new ArgumentNullException(nameof(teacherData));
            }

            //RoomData roomData = teacherData.getRoomData();
            RoomData roomData = rsContext.getRoom(teacherData.RoomId);

            if (roomData == null)
            {
                throw new ArgumentNullException(nameof(roomData));
            }

            roomData.updateCurrentActivityId(quesData.id);
            rsContext.SaveChanges();
            ShortAnswerQuestion ques = Adapting.getShortAnswerQuestionFromData(quesData);

            return(View(ques));
        }
        private void OnQuestionTypeChange()
        {
            // Added to prevent a bug, the bind event sometimes will be called again and again
            if (Question.QuestionType == _lastQuestionType)
            {
                return;
            }

            if (_parameterSetState)
            {
                _parameterSetState = false;
                return;
            }

            Console.WriteLine("OnQuestionTypeChange");

            var questionText = Question.Question;
            var questionType = Question.QuestionType;

            if (questionType == "choice")
            {
                Question = new ChoiceQuestion();
                ((ChoiceQuestion)Question).Choices = new List <string>();
            }
            else if (questionType == "short_answer")
            {
                Question = new ShortAnswerQuestion();
            }

            Question.Question     = questionText;
            Question.QuestionType = questionType;
            _lastQuestionType     = questionType;

            QuestionUpdated.InvokeAsync(Question);
            StateHasChanged();
        }
        public ActionResult SaveShortAnswerQuestion(ShortAnswerQuestion ques)
        {
            TeacherData teacherData = rsContext.getTeacher(User.Identity.Name);

            if (ques.expID == -1)
            {
                ques.RoomId = teacherData.RoomId;
                ShortAnswerQuestionData saData = Adapting.getShortAnswerQuestionAsData(ques);
                rsContext.addActivity(saData);
                rsContext.SaveChanges();
                return(RedirectToDashboard());
            }
            else
            {
                ques.RoomId = 0;
                ShortAnswerQuestionData saData = Adapting.getShortAnswerQuestionAsData(ques);
                rsContext.addActivity(saData);
                ExperimentData experimentData = (ExperimentData)rsContext.getActivity(ques.expID);
                saData.experimentOrder = experimentData.activities.Count;
                experimentData.addStep(saData);
                rsContext.SaveChanges();
                return(RedirectToAction("EditExperiment", new { ExpID = ques.expID }));
            }
        }
 /// <summary>
 /// Creates a question loader for a short answer question.
 /// </summary>
 IQuestionResolver IQuestionResultVisitor <IQuestionResolver, UserQuestionData> .Visit(
     ShortAnswerQuestion question,
     UserQuestionData userQuestionData)
 {
     return(new DefaultQuestionResolver(userQuestionData));
 }
Beispiel #27
0
 /// <summary>
 /// Creates a question loader for a short answer question.
 /// </summary>
 IQuestionLoader IQuestionResultVisitor <IQuestionLoader> .Visit(ShortAnswerQuestion question)
 {
     return(new ShortAnswerQuestionLoader(_dbContext, question));
 }
Beispiel #28
0
 /// <summary>
 /// Creates a question loader for a short answer question.
 /// </summary>
 IUserQuestionDataUpdater IQuestionResultVisitor <IUserQuestionDataUpdater> .Visit(
     ShortAnswerQuestion question)
 {
     return(_defaultUserQuestionDataUpdater);
 }
 /// <summary>
 /// Creates a question updater for a short answer question.
 /// </summary>
 IQuestionUpdater IQuestionResultVisitor <IQuestionUpdater, IModelErrorCollection> .Visit(
     ShortAnswerQuestion question,
     IModelErrorCollection errors)
 {
     return(new ShortAnswerQuestionUpdater(_dbContext, question, errors));
 }
 public DecoratedShortAnswerQuestion(ShortAnswerQuestion question)
 {
     Id = question.Id;
     Question = question.Question;
 }
Beispiel #31
0
 /// <summary>
 /// Creates a question duplicator for a short answer question.
 /// </summary>
 IQuestionDuplicator IQuestionResultVisitor <IQuestionDuplicator> .Visit(ShortAnswerQuestion question)
 {
     return(new ShortAnswerQuestionDuplicator(_dbContext, question));
 }
Beispiel #32
0
        /// <summary>
        /// 通过题目类型更改题目
        /// </summary>
        /// <param name="type">题目类型</param>
        /// <param name="id">题目Id</param>
        /// <param name="examid">考试Id</param>
        /// <param name="stem">题目题干</param>
        /// <param name="parameters">题目参数</param>
        /// <returns>更改成功与否</returns>
        public bool UpdateExamQuestion(ExamQuestion.QuestionType type, int id, int examid, string stem, object[] parameters)
        {
            if (parameters == null)
            {
                return(false);
            }
            ExaminationQuestion question = null;

            switch (type)
            {
            case ExamQuestion.QuestionType.ChoiceQuestion:
                if (parameters.Length == 2)
                {
                    List <string> ops = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(parameters[1].ToString());
                    question = new ChoiceQuestion(Convert.ToInt32(parameters[0].ToString()), ops.ToArray(), stem);
                }
                else
                {
                    return(false);
                }
                break;

            case ExamQuestion.QuestionType.GapFillingQuestion:
                if (parameters.Length == 1)
                {
                    question = new GapFillingQuestion(parameters[0].ToString(), stem);
                }
                else
                {
                    return(false);
                }
                break;

            case ExamQuestion.QuestionType.ShortAnswerQuestion:
                if (parameters.Length == 1)
                {
                    question = new ShortAnswerQuestion(parameters[0].ToString(), stem);
                }
                else
                {
                    return(false);
                }
                break;

            case ExamQuestion.QuestionType.TrueOrFalseQuestion:
                if (parameters.Length == 1)
                {
                    question = new TrueOrFalseQuestion(Convert.ToBoolean(parameters[0].ToString()), stem);
                }
                else
                {
                    return(false);
                }
                break;
            }
            if (question == null)
            {
                return(false);
            }
            ExamQuestion examQuestion = new ExamQuestion(id, examid, question);

            return(UpdateExaminationQuestion(examQuestion));
        }
Beispiel #33
0
 /// <summary>
 /// Creates a question grader for a short answer question.
 /// </summary>
 IQuestionGrader IQuestionResultVisitor <IQuestionGrader> .Visit(ShortAnswerQuestion question)
 {
     return(new ShortAnswerQuestionGrader(question));
 }