def test_random_algo_insert_one(self): options = ['optionA', 'optionB', 'optionC'] # test insert into empty pool pool = {} expected_answer = options[0] expected_rationale = "rationale" expected_student_id = "student id" offer_answer(pool, expected_answer, expected_rationale, expected_student_id, {'name': 'random'}, options) expected_pool = {expected_answer: {expected_student_id: {}}} self.assertEqual(expected_pool, pool)
def test_simple_algo_insert_one(self): options = ['optionA', 'optionB', 'optionC'] # test insert into empty pool pool = {} expected_answer = options[0] expected_rationale = "rationale" expected_student_id = "student id" offer_answer(pool, expected_answer, expected_rationale, expected_student_id, {'name': 'simple'}, options) expected_pool = {expected_answer: {expected_student_id: {}}} self.assertEqual(expected_pool, pool)
def test_simple_algo_drop_from_pool(self): options = ['optionA', 'optionB', 'optionC'] pool = {'optionA': {i: {} for i in xrange(6)}} with patch('random.choice', return_value="0"): with patch('ubcpi.answer_pool.get_max_size', return_value="6"): offer_answer(pool, options[0], "some rationale", "test student 7", {'name': 'simple'}, options) # make sure student "0" for optionA is removed self.assertFalse("0" in pool['optionA']) # make sure the new student answer is added self.assertTrue("test student 7" in pool['optionA'])
def test_simple_algo_drop_from_pool(self): options = ['optionA', 'optionB', 'optionC'] pool = {'optionA': {i: {} for i in range(6)}} with patch('random.choice', return_value=0): with patch('ubcpi.answer_pool.get_max_size', return_value=6): offer_answer(pool, options[0], "some rationale", "test student 7", {'name': 'simple'}, options) # make sure student "0" for optionA is removed self.assertFalse("0" in pool['optionA']) # make sure the new student answer is added self.assertTrue("test student 7" in pool['optionA'])
def test_simple_algo_insert_max(self): options = ['optionA', 'optionB', 'optionC'] pool = {} expected_pool = {} for i in range(6): for cur_expected_answer in options: cur_expected_rationale = "rationale" + str(i) cur_expected_student_id = "student id" + str(i) + cur_expected_answer students = expected_pool.setdefault(cur_expected_answer, {}) students[cur_expected_student_id] = {} expected_pool[cur_expected_answer] = students offer_answer(pool, cur_expected_answer, cur_expected_rationale, cur_expected_student_id, {'name': 'simple'}, options) self.assertEqual(expected_pool, pool)
def test_simple_algo_insert_max(self): options = ['optionA', 'optionB', 'optionC'] pool = {} expected_pool = {} for i in range(6): for cur_expected_answer in options: cur_expected_rationale = "rationale" + str(i) cur_expected_student_id = "student id" + str( i) + cur_expected_answer students = expected_pool.setdefault(cur_expected_answer, {}) students[cur_expected_student_id] = {} expected_pool[cur_expected_answer] = students offer_answer(pool, cur_expected_answer, cur_expected_rationale, cur_expected_student_id, {'name': 'simple'}, options) self.assertEqual(expected_pool, pool)
def test_offer_answer_invalid_algo(self): options = ['optionA', 'optionB', 'optionC'] with self.assertRaises(UnknownChooseAnswerAlgorithm): offer_answer({}, {}, 'rationale', 'student_id', {'name': 'invalid'}, options)