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())
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)
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)
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())
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])
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]])
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]])
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'])
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)
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)
def testSetBaseScoresError(self): exam = utils.ExamConfig() scores = utils.QuestionScores('1', '1/2', '0', weight='2') self.assertRaises(ValueError, exam.set_base_scores, scores)