Ejemplo n.º 1
0
 def testSort(self):
     scores = [
         utils.QuestionScores('1', '1/3', '0'),
         utils.QuestionScores('2', '2/3', '1/2'),
         utils.QuestionScores('1', '1/3', '0'),
         utils.QuestionScores('2', '2/3', '0'),
         utils.QuestionScores('1/2', '1/6', '0'),
     ]
     sorted_scores = [scores[4], scores[0], scores[2], scores[3], scores[1]]
     self.assertEqual(sorted(scores), sorted_scores)
Ejemplo n.º 2
0
 def testSetQuestionScores(self):
     exam = utils.ExamConfig()
     exam.num_questions = 5
     scores = [
         utils.QuestionScores('1', '1/3', '0'),
         utils.QuestionScores('2', '2/3', '0'),
         utils.QuestionScores('1', '1/3', '0'),
         utils.QuestionScores('2', '2/3', '0'),
         utils.QuestionScores('1/2', '1/6', '0'),
     ]
     exam.set_question_scores('A', scores)
     exam.set_question_scores(
         'B', [scores[1], scores[2], scores[4], scores[0], scores[3]])
Ejemplo n.º 3
0
 def testSetQuestionScoresError(self):
     exam = utils.ExamConfig()
     scores = [
         utils.QuestionScores('1', '1/3', '0'),
         utils.QuestionScores('2', '2/3', '0'),
         utils.QuestionScores('1', '1/3', '0'),
         utils.QuestionScores('2', '2/3', '0'),
         utils.QuestionScores('1/2', '1/6', '0'),
     ]
     self.assertRaises(ValueError, exam.set_question_scores, 'A', scores)
     exam.num_questions = 5
     exam.set_question_scores('A', scores)
     self.assertRaises(
         ValueError, exam.set_question_scores, 'B',
         [scores[1], scores[1], scores[4], scores[0], scores[3]])
Ejemplo n.º 4
0
 def testAllWeightsAreOneWeightsNegative(self):
     exam = utils.ExamConfig()
     exam.num_questions = 5
     exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'))
     exam.set_question_weights('A', [1, 2, 1, '1/2', 1])
     exam.set_question_weights('B', [2, 1, 1, 1, '1/2'])
     self.assertFalse(exam.all_weights_are_one())
Ejemplo n.º 5
0
 def testSetEqualScores2(self):
     exam = utils.ExamConfig()
     exam.num_questions = 5
     exam.models = ['A', 'B']
     exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'),
                          same_weights=True)
     for scores in exam.scores['A'] + exam.scores['B']:
         self.assertEqual(scores, exam.base_scores)
Ejemplo n.º 6
0
 def testSetEqualScores1(self):
     exam = utils.ExamConfig()
     exam.num_questions = 5
     exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'))
     exam.set_equal_scores('A')
     exam.set_equal_scores('B')
     for scores in exam.scores['A'] + exam.scores['B']:
         self.assertEqual(scores, exam.base_scores)
Ejemplo n.º 7
0
 def testAllWeightsAreOneWeights(self):
     exam = utils.ExamConfig()
     exam.num_questions = 5
     self.assertFalse(exam.all_weights_are_one())
     exam.models = ['A', 'B']
     self.assertFalse(exam.all_weights_are_one())
     exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'),
                          same_weights=True)
     self.assertTrue(exam.all_weights_are_one())
Ejemplo n.º 8
0
    def testSetEqualScores3(self):
        """Test for issue #96.

        An exception because of different weights was raised because
        of the issue.

        """
        exam = utils.ExamConfig()
        exam.num_questions = 5
        exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'),
                             same_weights=True)
        exam.set_equal_scores('A')
        exam.set_equal_scores('B')
        for scores in exam.scores['A'] + exam.scores['B']:
            self.assertEqual(scores, exam.base_scores)
        exam.set_base_scores(utils.QuestionScores('2', '1', '0'),
                             same_weights=True)
        for scores in exam.scores['A'] + exam.scores['B']:
            self.assertEqual(scores, exam.base_scores)
Ejemplo n.º 9
0
 def testScoreEqualScores(self):
     answers = [0, 1, 2, 3, 0, 1]
     solutions = [1, 1, 3, 3, 4, 1]
     base_score = utils.QuestionScores('1', '1/2', '0')
     question_scores = 6 * [base_score]
     score = utils.Score(answers, solutions, question_scores)
     self.assertEqual(score.correct, 3)
     self.assertEqual(score.incorrect, 1)
     self.assertEqual(score.blank, 2)
     self.assertEqual(score.score, 2.5)
     self.assertEqual(score.max_score, 6.0)
Ejemplo n.º 10
0
 def testSetQuestionWeightsError(self):
     exam = utils.ExamConfig()
     self.assertRaises(ValueError, exam.set_question_weights, 'A',
                       [1, 2, 2])
     exam.num_questions = 3
     self.assertRaises(ValueError, exam.set_question_weights, 'A',
                       [1, 2, 2])
     exam.set_base_scores(utils.QuestionScores('1', '1/3', '0'))
     exam.set_question_weights('A', [1, 2, 2])
     self.assertRaises(ValueError, exam.set_question_weights, 'B',
                       [2, 1, 1])
Ejemplo n.º 11
0
 def testFractionAndInt(self):
     score = utils.QuestionScores('1', '1/3', '0')
     self.assertEqual(score.format_all(), '1;1/3;0')
     self.assertEqual(score.format_score(utils.QuestionScores.CORRECT), '1')
     self.assertEqual(score.format_score(utils.QuestionScores.INCORRECT),
                      '1/3')
     self.assertEqual(score.format_score(utils.QuestionScores.BLANK), '0')
     self.assertEqual(score.score(utils.QuestionScores.CORRECT), 1)
     self.assertEqual(score.score(utils.QuestionScores.INCORRECT),
                      fractions.Fraction(-1, 3))
     self.assertEqual(score.score(utils.QuestionScores.BLANK), 0)
     self.assertEqual(score.format_weight(), '1')
Ejemplo n.º 12
0
 def testClone(self):
     score1 = utils.QuestionScores('1', '1/3', '1/6', weight='3/2')
     score2 = score1.clone()
     self.assertEqual(score2.correct_score, score1.correct_score)
     self.assertEqual(score2.incorrect_score, score1.incorrect_score)
     self.assertEqual(score2.blank_score, score1.blank_score)
     self.assertEqual(score2.weight, score1.weight)
     score3 = score1.clone(new_weight=2)
     self.assertEqual(score3.correct_score, score1.correct_score)
     self.assertEqual(score3.incorrect_score, score1.incorrect_score)
     self.assertEqual(score3.blank_score, score1.blank_score)
     self.assertEqual(score3.weight, 2)
Ejemplo n.º 13
0
 def testScoreError(self):
     answers = [0, 1, 2, 3, 0, 1]
     solutions = [1, 1, 3, 3, 4, 1]
     base_score = utils.QuestionScores('1', '1/2', '0')
     question_scores = [
         base_score,
         base_score.clone(new_weight=2),
         base_score.clone(new_weight=2),
         base_score,
         base_score,
     ]
     self.assertRaises(ValueError, utils.Score, answers, solutions,
                       question_scores)
Ejemplo n.º 14
0
 def testSignedFormat(self):
     score = utils.QuestionScores('1', '1/3', '1/6')
     result = score.format_score(utils.QuestionScores.CORRECT, signed=True)
     self.assertEqual(result, '1')
     result = score.format_score(utils.QuestionScores.INCORRECT,
                                 signed=True)
     self.assertEqual(result, '-1/3')
     result = score.format_score(utils.QuestionScores.BLANK, signed=True)
     self.assertEqual(result, '-1/6')
     result = score.format_correct_score(signed=True)
     self.assertEqual(result, '1')
     result = score.format_incorrect_score(signed=True)
     self.assertEqual(result, '-1/3')
     result = score.format_blank_score(signed=True)
     self.assertEqual(result, '-1/6')
     score = utils.QuestionScores('1.0', '0.5', '0.25')
     result = score.format_score(utils.QuestionScores.CORRECT, signed=True)
     self.assertEqual(result, '1.0000000000000000')
     result = score.format_score(utils.QuestionScores.INCORRECT,
                                 signed=True)
     self.assertEqual(result, '-0.5000000000000000')
     result = score.format_score(utils.QuestionScores.BLANK, signed=True)
     self.assertEqual(result, '-0.2500000000000000')
Ejemplo n.º 15
0
 def testWeight(self):
     score = utils.QuestionScores('1', '1/3', '1/6', weight='3/2')
     self.assertEqual(score.format_all(), '1;1/3;1/6')
     self.assertEqual(score.format_score(utils.QuestionScores.CORRECT), '1')
     self.assertEqual(score.format_score(utils.QuestionScores.INCORRECT),
                      '1/3')
     self.assertEqual(score.format_score(utils.QuestionScores.BLANK), '1/6')
     self.assertEqual(score.score(utils.QuestionScores.CORRECT),
                      fractions.Fraction(3, 2))
     self.assertEqual(score.score(utils.QuestionScores.INCORRECT),
                      fractions.Fraction(-1, 2))
     self.assertEqual(score.score(utils.QuestionScores.BLANK),
                      fractions.Fraction(-1, 4))
     self.assertEqual(score.format_weight(), '3/2')
Ejemplo n.º 16
0
 def testGetQuestionWeights(self):
     exam = utils.ExamConfig()
     exam.num_questions = 3
     self.assertEqual(exam.get_question_weights('A'), None)
     exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'))
     self.assertEqual(exam.get_question_weights('A'), None)
     exam.set_question_weights('A', [1, 2, '1/2'])
     exam.set_question_weights('B', ['1/2', '1', '2'])
     self.assertEqual(exam.get_question_weights('A'),
                      [1, 2, fractions.Fraction(1, 2)])
     self.assertEqual(exam.get_question_weights('B'),
                      [fractions.Fraction(1, 2), 1, 2])
     self.assertEqual(exam.get_question_weights('A', formatted=True),
                      ['1', '2', '1/2'])
     self.assertEqual(exam.get_question_weights('B', formatted=True),
                      ['1/2', '1', '2'])
Ejemplo n.º 17
0
 def testFloat(self):
     score = utils.QuestionScores(1.0, 0.5, 0.0)
     key_1 = '1.0000000000000000'
     key_2 = '0.5000000000000000'
     key_3 = '0.0000000000000000'
     self.assertEqual(score.format_all(), ';'.join((key_1, key_2, key_3)))
     self.assertEqual(score.format_score(utils.QuestionScores.CORRECT),
                      key_1)
     self.assertEqual(score.format_correct_score(), key_1)
     self.assertEqual(score.format_score(utils.QuestionScores.INCORRECT),
                      key_2)
     self.assertEqual(score.format_incorrect_score(), key_2)
     self.assertEqual(score.format_score(utils.QuestionScores.BLANK), key_3)
     self.assertEqual(score.format_blank_score(), key_3)
     self.assertEqual(score.score(utils.QuestionScores.CORRECT), 1.0)
     self.assertEqual(score.score(utils.QuestionScores.INCORRECT), -0.5)
     self.assertEqual(score.score(utils.QuestionScores.BLANK), 0.0)
     self.assertEqual(score.format_weight(), '1')
Ejemplo n.º 18
0
 def testScoreDifferentScores(self):
     answers = [0, 1, 2, 3, 0, 1]
     solutions = [1, 1, 3, 3, 4, 1]
     base_score = utils.QuestionScores('1', '1/2', '0')
     question_scores = [
         base_score,
         base_score.clone(new_weight=2),
         base_score.clone(new_weight=2),
         base_score,
         base_score,
         base_score.clone(new_weight=3),
     ]
     score = utils.Score(answers, solutions, question_scores)
     self.assertEqual(score.correct, 3)
     self.assertEqual(score.incorrect, 1)
     self.assertEqual(score.blank, 2)
     self.assertEqual(score.score, 5.0)
     self.assertEqual(score.max_score, 10.0)
Ejemplo n.º 19
0
 def testSetBaseScoresError(self):
     exam = utils.ExamConfig()
     scores = utils.QuestionScores('1', '1/2', '0', weight='2')
     self.assertRaises(ValueError, exam.set_base_scores, scores)
Ejemplo n.º 20
0
 def testSetQuestionWeights(self):
     exam = utils.ExamConfig()
     exam.num_questions = 5
     scores = [
         utils.QuestionScores('1', '1/2', '0', weight='1'),
         utils.QuestionScores('1', '1/2', '0', weight='2'),
         utils.QuestionScores('1', '1/2', '0', weight='1'),
         utils.QuestionScores('1', '1/2', '0', weight='2'),
         utils.QuestionScores('1', '1/2', '0', weight='1/2'),
         utils.QuestionScores('1', '1/2', '0', weight='1'),
         utils.QuestionScores('1', '1/2', '0', weight='1'),
         utils.QuestionScores('1', '1/2', '0', weight='1/2'),
         utils.QuestionScores('1', '1/2', '0', weight='2'),
         utils.QuestionScores('1', '1/2', '0', weight='2'),
     ]
     exam.set_base_scores(utils.QuestionScores('1', '1/2', '0'))
     exam.set_question_weights('A', [1, 2, 1, 2, '1/2'])
     exam.set_question_weights('B', ['1', '1', '1/2', '2', '2'])
     for value, key in zip(exam.scores['A'] + exam.scores['B'], scores):
         self.assertEqual(value, key)