public override float GetScore(UserAnswer userAnswer) { var choiceAnswer = userAnswer as ChoiceUserAnswer; if (choiceAnswer == null) { throw new WrongAnswerTypeException("Wrong answer type"); } if (choiceAnswer.QuestionId != QuestionId) { throw new Exception("Answer.QuestionId doesn't match UserAnswer.QuestionId"); } if (NumericValue == choiceAnswer.Value) { return(MaxScore); } if (AllValidChoicesRequired) { return(0f); } int userAnswerNumericValue = choiceAnswer.Value; int answerNumericValue = NumericValue; int numberOfValidChoices = 0; int numberOfUsersValidChoices = 0; while (answerNumericValue != 0) { bool isChoiceValid = (answerNumericValue & 1) == 1; bool isUserChoiceValid = (userAnswerNumericValue & 1) == 1; if (isUserChoiceValid && !isChoiceValid) { return(0f); } if (isChoiceValid) { numberOfValidChoices++; if (isUserChoiceValid) { numberOfUsersValidChoices++; } } userAnswerNumericValue >>= 1; answerNumericValue >>= 1; } if (userAnswerNumericValue != 0) { return(0f); } return(MaxScore - MaxScore / numberOfValidChoices * (numberOfValidChoices - numberOfUsersValidChoices)); }
public override float GetScore(UserAnswer userAnswer) { var writtenAnswer = userAnswer as WrittenUserAnswer; if (writtenAnswer == null) { throw new WrongAnswerTypeException("Wrong answer type"); } if (writtenAnswer.QuestionId != QuestionId) { throw new Exception("Answer.QuestionId doesn't match UserAnswer.QuestionId"); } return(writtenAnswer.Value == Value ? MaxScore : 0); }
public AnswerPair(UserAnswer userAnswer, Answer answer) { UserAnswer = userAnswer; Answer = answer; }
public void AddAnswerPair(UserAnswer userAnswer, Answer answer) { answerPairs.Add(new AnswerPair(userAnswer, answer)); }