Esempio n. 1
0
        /// <summary>
        /// Checks if the answer is correct
        /// </summary>
        /// <param name="Answer">The answer to be checked</param>
        /// <returns>Number of points for this answer depending on current valuation criteria</returns>
        public override int CheckAnswer(Answer Answer)
        {
            if (Answer.IsEmpty())
            {
                return(0);
            }

            var TargetAnswer = Answer as MultipleChoiceAnswer;

            // The type should match but need to check it just in case
            if (TargetAnswer == null)
            {
                return(0);
            }

            return(TargetAnswer.SelectedAnswerIndex == CorrectAnswerIndex ? Scoring.FullPointScore : 0);
        }
Esempio n. 2
0
        /// <summary>
        /// Checks if the answer is correct
        /// </summary>
        /// <param name="Answer">The answer to be checked</param>
        /// <returns>Number of points for this answer depending on current valuation criteria</returns>
        public override int CheckAnswer(Answer Answer)
        {
            if (Answer.IsEmpty())
            {
                return(0);
            }

            var TargetAnswer = Answer as SingleTextBoxAnswer;

            // The type should match but need to check it just in case
            if (TargetAnswer == null)
            {
                return(0);
            }

            // Depending on evluation criteria thease can change
            var FinalUserAnswer    = TargetAnswer.UserAnswer;
            var FinalCorrectAnswer = CorrectAnswer;

            // Take into account all criteria

            // If not case sensitive make everything lower case
            if (!Scoring.IsCaseSensitive)
            {
                FinalUserAnswer    = FinalUserAnswer.ToLower();
                FinalCorrectAnswer = FinalCorrectAnswer.ToLower();
            }

            // If white spaces are unimportant delete them
            if (!Scoring.AreWhiteSpacesImportant)
            {
                FinalUserAnswer    = FinalUserAnswer.Replace(" ", string.Empty);
                FinalCorrectAnswer = FinalCorrectAnswer.Replace(" ", string.Empty);
            }

            return(FinalUserAnswer == FinalCorrectAnswer ? Scoring.FullPointScore : 0);
        }
        /// <summary>
        /// Checks if the answer is correct
        /// </summary>
        /// <param name="Answer">Answer to validate</param>
        /// <returns>Number of points for this answer depending on current valuation criteria</returns>
        public override int CheckAnswer(Answer Answer)
        {
            if (Answer == null)
            {
                throw new NullReferenceException();
            }

            var TargetAnswer = Answer as MultipleCheckBoxesAnswer;

            // The type should match but need to check it just in case
            if (TargetAnswer == null)
            {
                throw new Exception("Answer type does not match the question type");
            }

            if (TargetAnswer.UserAnswer.Count != CorrectAnswer.Count)
            {
                throw new Exception("Answers count does not match this question");
            }

            if (Answer.IsEmpty())
            {
                return(0);
            }

            var CorrectAnswersNumber = 0;

            // Get how many answers user got right
            for (var i = 0; i < Options.Count; i++)
            {
                if (TargetAnswer.UserAnswer[i] == CorrectAnswer[i])
                {
                    CorrectAnswersNumber++;
                }
            }

            // TODO: DECIDE ON ROUNDING (CEIL OR FLOOR)
            // Based on evaluation mode givem them proper ammount of points
            switch (Scoring.Mode)
            {
            case ScoringMode.FullAnswer:
                return(CorrectAnswersNumber == CorrectAnswer.Count ? Scoring.FullPointScore : 0);

            case ScoringMode.HalfTheAnswer:

                // Less than the half: 0 points
                if (CorrectAnswersNumber < CorrectAnswer.Count / 2)
                {
                    return(0);
                }

                // If the score is between the half and max: half the points
                if (CorrectAnswersNumber < CorrectAnswer.Count)
                {
                    return(Scoring.FullPointScore / 2);
                }

                // Full score: full points
                return(Scoring.FullPointScore);

            case ScoringMode.EvenParts:

                // For each asnwer give a proper ammount of poitns
                // NOTE: Can be done by ceil or floor rounding.
                return(Scoring.FullPointScore * CorrectAnswersNumber / CorrectAnswer.Count);

            default:
                Debugger.Break();
                throw new Exception("Answer check failed. No evaluating mode detected.");
            }
        }