示例#1
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())
示例#2
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)
示例#3
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)
示例#4
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())
示例#5
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])
示例#6
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]])
示例#7
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]])
示例#8
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'])
示例#9
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)
示例#10
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)
示例#11
0
 def testSetBaseScoresError(self):
     exam = utils.ExamConfig()
     scores = utils.QuestionScores('1', '1/2', '0', weight='2')
     self.assertRaises(ValueError, exam.set_base_scores, scores)