def test_user_item_bank_update(self): user = User.objects.create_user("john", "*****@*****.**", "johnpassword") user.save() # create structures cat_test = CatTest() cat_test.name = "Short Test" cat_test.save() domain = Domain.objects.get(pk=1) item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.items = 6 user_cat_test.right = 4 user_cat_test.time_taken = 240 user_cat_test.save() user_item_bank.update(user_cat_test) self.assertEquals(user_item_bank.tests, 1) self.assertEquals(user_item_bank.questions, 6) self.assertEquals(user_item_bank.correct, 4) self.assertEquals(user_item_bank.time_taken, 240) self.assertEquals(user_item_bank.time_taken_str, "0:04:00")
def test_create_and_save(self): cat_test = CatTest() cat_test.name = "short" cat_test.save() user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012,03,06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.time_taken = 12 user_cat_test.save() uct = UserCatTest.objects.all()[0] self.assertEquals(uct.user,user) self.assertEquals(uct.item_bank,item_bank) self.assertEquals(uct.cat_test,cat_test) self.assertEquals(uct.time_taken,12)
def test_create_and_save(self): cat_test = CatTest() cat_test.name = "short" cat_test.save() user = User.objects.create_user("john", "*****@*****.**", "johnpassword") user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012, 03, 06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.create_date = datetime.datetime(2012, 03, 06) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() uct = UserCatTest.objects.all()[0] self.assertEquals(uct.user, user) self.assertEquals(uct.item_bank, item_bank) self.assertEquals(uct.cat_test, cat_test)
def test_start_old_cat_view(self): #test that if a user has done more than one test the right one is being updated user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() self.client.login(username='******', password='******') #create structures cat_test = CatTest() cat_test.name = "Short Test" cat_test.save() domain = Domain.objects.get(pk=1) item_bank = ItemBank() item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.items = 6 user_cat_test.save() user_cat_test = UserCatTest() response = self.client.get('/start/', {'item_bank_id': item_bank.id, 'cat_test_id':cat_test.id}) ucts = UserCatTest.objects.filter(user=user) self.assertEquals(len(ucts),2) ucts = ucts.order_by('-id') self.assertEquals(ucts[0].items,0)
def test_simAbility(self): cat_test = CatTest() cat_test.name = "short" cat_test.max_items = 10 cat_test.save() user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012,03,06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() grd = Grade.objects.get(name="A") thresh = Threshold() thresh.grade = grd thresh.item_bank = item_bank thresh.ability = -1 thresh.save() user_item_bank.probabilities() probs = UserItemBankProbabilities.objects.filter(user_item_bank=user_item_bank) self.assertEquals(len(probs),1) ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() #Make three questions for i in range(1,4): ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() #Find first question user_cat_test.nextQuestion() user_cat_test.simAbility() self.assertEquals(round(user_cat_test.ability,3),-0.337) self.assertEquals(round(user_cat_test.stand_dev,3),0.885) probs = UserItemBankProbabilities.objects.filter(user_item_bank=user_item_bank)[0] self.assertEquals(round(probs.probability,0),77.0) user_cat_test.nextQuestion() user_cat_test.simAbility() self.assertEquals(round(user_cat_test.ability,3),-0.813) self.assertEquals(round(user_cat_test.stand_dev,3),0.829)
def test_endTest(self): cat_test = CatTest() cat_test.name = "short" cat_test.max_items = 10 cat_test.save() user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012,03,06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.items = 10 user_cat_test.save() end_test = user_cat_test.endTest() self.assertEquals(end_test,True) user_cat_test.items = 9 user_cat_test.save() end_test = user_cat_test.endTest() self.assertEquals(end_test,False) user_cat_test.items = 5 user_cat_test.stand_dev = 0.1 user_cat_test.save() end_test = user_cat_test.endTest() self.assertEquals(end_test,True) user_cat_test.items = 5 user_cat_test.stand_dev = 2 user_cat_test.save() end_test = user_cat_test.endTest() self.assertEquals(end_test,False) user_cat_test.items = 2 user_cat_test.stand_dev = 0.1 user_cat_test.save() end_test = user_cat_test.endTest() self.assertEquals(end_test,False)
def test_create_and_save(self): cat_test = CatTest() cat_test.name = "short" cat_test.save() user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012,03,06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() cat_test_item = CatTestItem() cat_test_item.user_cat_test = user_cat_test cat_test_item.item_bank_question = ibq cat_test_item.time_taken = 12 cat_test_item.save() answer = FractionWithConstant() answer.const = 1 answer.denom = 2 answer.num = 3 answer.save() ctifa = CatTestItemFractionAnswer() ctifa.cat_test_item = cat_test_item ctifa.fraction = answer ctifa.save() ctifa = CatTestItemFractionAnswer.objects.filter(cat_test_item = cat_test_item)[0] self.assertEquals(ctifa.fraction,answer)
def test_display_user_cat_test(self): #Test the post functionality of the question view user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() self.client.login(username='******', password='******') #create structures cat_test = CatTest() cat_test.name = "Short Test" cat_test.save() domain = Domain.objects.get(pk=1) item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() #Create a threshold grd = Grade.objects.get(name="A") thresh = Threshold() thresh.grade = grd thresh.item_bank = item_bank thresh.ability = -1 thresh.init_prob =50 thresh.save() user_item_bank.probabilities() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() response = self.client.get('/end/') self.assertIn('Ability: 0',response.content) user_item_bank = UserItemBank.objects.get(pk=1) self.assertEqual(user_item_bank.tests,1) #Should show probabilities self.assertIn('50%',response.content)
def start_test(request): #check for log in if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login/?next=%s' % request.path) user = request.user #Get post info if request.method == 'GET': item_bank_id = request.GET['item_bank_id'] cat_test_id = request.GET['cat_test_id'] #Retrieve item bank item_bank = ItemBank.objects.get(pk=item_bank_id) cat_test = CatTest.objects.get(pk=cat_test_id) uib = UserItemBank.objects.get(user=user,item_bank=item_bank) #New user_cat_test user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.ability = uib.ability user_cat_test.stand_dev = uib.ability_stand_dev user_cat_test.save() #Create cat_test for user with info from item bank return render_to_response('start_test.html', {"item_bank": item_bank,"cat_test":cat_test})
def test_updateAbility(self): cat_test = CatTest() cat_test.name = "short" cat_test.max_items = 10 cat_test.save() user = User.objects.create_user("john", "*****@*****.**", "johnpassword") user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012, 03, 06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.create_date = datetime.datetime(2012, 03, 06) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() # First question right test_pattern = [1, 1, 0] test_ability = [0, 0, math.log(2)] test_difficulty = [2, 1, -2.0 / 3.0] test_stand_err = [2, 2, 1.5] test_items = [1, 2, 3] test_hardness = [0, 0, 0] test_right = [1, 2, 2] # Make three questions for i in range(1, 4): ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() # Find first question user_cat_test.nextQuestion() user_cat_test.updateAbility(1) self.assertEquals(user_cat_test.right, 1) self.assertEquals(user_cat_test.items, 1) self.assertEquals(user_cat_test.difficulty, 2) self.assertEquals(user_cat_test.hardness, 0) self.assertEquals(user_cat_test.ability, 0) # Second question right user_cat_test.nextQuestion() user_cat_test.updateAbility(1) self.assertEquals(user_cat_test.right, 2) self.assertEquals(user_cat_test.items, 2) self.assertEquals(user_cat_test.difficulty, 1) self.assertEquals(user_cat_test.hardness, 0) self.assertEquals(user_cat_test.ability, 0) # Third question wrong user_cat_test.nextQuestion() user_cat_test.updateAbility(0) self.assertEquals(user_cat_test.right, 2) self.assertEquals(user_cat_test.items, 3) self.assertEquals(user_cat_test.difficulty, -2.0 / 3.0) self.assertEquals(user_cat_test.hardness, 0) self.assertEquals(user_cat_test.ability, math.log(2))
def test_nextQuestion(self): cat_test = CatTest() cat_test.name = "short" cat_test.max_items = 10 cat_test.save() user = User.objects.create_user("john", "*****@*****.**", "johnpassword") user.save() domain = Domain() domain.name = "Number" domain.create_date = datetime.datetime(2012, 03, 06) domain.save() item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.create_date = datetime.datetime(2012, 03, 06) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() q = user_cat_test.nextQuestion() # One item in bank, one taken self.assertEquals(isinstance(q, CatTestItem), True) q = user_cat_test.nextQuestion() # One item in bank, try to take another, should return None self.assertEquals(isinstance(q, CatTestItem), False) # Add more questions and see if they are repeated for i in range(1, 11): ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() for i in range(1, 11): q = user_cat_test.nextQuestion() print q.item_bank_question.id # Add a question of perfect difficulty and see if it is chosen amongst others for i in range(1, 11): ibq = ItemBankQuestion() ibq.item_bank = item_bank ibq.save() user_cat_test.difficulty = 2 user_cat_test.stand_err = 0.1 hibq = ItemBankQuestion() hibq.item_bank = item_bank hibq.difficulty = 2 hibq.save() q = user_cat_test.nextQuestion() self.assertEquals(q.item_bank_question, hibq) # Make ability different to all questions and make sure one is chosen user_cat_test.difficulty = 2 user_cat_test.stand_err = 0.1 q = user_cat_test.nextQuestion() self.assertEquals(isinstance(q, CatTestItem), True)
def test_question_view_w_login(self): #Test the post functionality of the question view user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() self.client.login(username='******', password='******') #create structures cat_test = CatTest() cat_test.name = "Short Test" cat_test.save() domain = Domain.objects.get(pk=1) item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() #Give the test some questions #Create fraction question bank fqb = FractionQuestionBank() oper = Oper.objects.get(pk=1) n = 20 st = 0 en = 10 name = "Test Bank" negatives_allowed = True fqb.generate(name,st,en,negatives_allowed,oper,n) #Fill item bank from fraction question bank item_bank.fill(fqb,"fractions") response = self.client.get('/question/') self.assertEqual(response.status_code, 200) #Test that is has been rendered with a template self.assertTemplateUsed(response, 'question.html') #Question needs to know how to display itself self.assertIn('Fractions',response.content) #Fractions pulls in a fractions template self.assertIn('Fraction Question',response.content) #Increments question self.assertIn('Questions completed: 0',response.content) #Displays the correct sign for a fraction question self.assertIn('+',response.content) #Test item_bank usage has been incremented cat_test_item = CatTestItem.objects.filter(user_cat_test=user_cat_test) self.assertEquals(len(cat_test_item),1) cat_test_item = cat_test_item.order_by('-id')[0] self.assertEquals(cat_test_item.item_bank_question.usage,1) #Correct answer to question ibfq = ItemBankFractionQuestion.objects.filter(item_bank_question=cat_test_item.item_bank_question) answer = ibfq[0].fraction_bank_question.question.answer #Test post triggers marking process response = self.client.post('/question/', {'const': answer.const, 'num': answer.num, 'denom': answer.denom, 'time': 12}) user_cat_test = UserCatTest.objects.get(user=user) self.assertEqual(user_cat_test.items,1) self.assertEqual(round(user_cat_test.ability,2),0.28) self.assertEqual(round(user_cat_test.stand_dev,2),0.91) #Check that a response has now been saved to user_cat_test cti = CatTestItem.objects.filter(user_cat_test=user_cat_test) self.assertEqual(len(cti),1) #Check response has been saved to cti self.assertEqual(cti[0].correct,1) self.assertEqual(cti[0].time_taken,12) #Try another cat_test_item = user_cat_test.nextQuestion() cat_test_item = CatTestItem.objects.filter(user_cat_test=user_cat_test) cat_test_item = cat_test_item.order_by('-id')[0] ibfq = ItemBankFractionQuestion.objects.filter(item_bank_question=cat_test_item.item_bank_question) answer = ibfq[0].fraction_bank_question.question.answer #Test post triggers marking process response = self.client.post('/question/', {'const': answer.const, 'num': answer.num, 'denom': answer.denom, 'time': 22}) user_cat_test = UserCatTest.objects.get(user=user) self.assertEqual(user_cat_test.items,2) self.assertEqual(round(user_cat_test.ability,2),0.75) self.assertEqual(round(user_cat_test.stand_dev,2),0.82) #Check that a response has now been saved to user_cat_test cti = CatTestItem.objects.filter(user_cat_test=user_cat_test) cti = cti.order_by('-id') self.assertEqual(len(cti),2) #Check response has been saved to cti self.assertEqual(cti[0].correct,1) self.assertEqual(cti[0].time_taken,22) #Try another cat_test_item = user_cat_test.nextQuestion() #Test post triggers marking process response = self.client.post('/question/', {'const': answer.const, 'num': answer.num, 'denom': answer.denom, 'time': 3}) user_cat_test = UserCatTest.objects.get(user=user) self.assertEqual(user_cat_test.items,3) self.assertEqual(round(user_cat_test.ability,2),0.76) self.assertEqual(round(user_cat_test.stand_dev,2),0.71) #Check that a response has now been saved to user_cat_test cti = CatTestItem.objects.filter(user_cat_test=user_cat_test) cti = cti.order_by('-id') self.assertEqual(len(cti),3) #Check response has been saved to cti self.assertEqual(cti[0].correct,0) self.assertEqual(cti[0].time_taken,3)
def test_feedback(self): #Test the post functionality of the question view user = User.objects.create_user('john', '*****@*****.**', 'johnpassword') user.save() self.client.login(username='******', password='******') #create structures cat_test = CatTest() cat_test.name = "Short Test" cat_test.save() domain = Domain.objects.get(pk=1) item_bank = ItemBank() item_bank.name = "Fractions" item_bank.topic = "Addition" item_bank.domain = domain item_bank.template = ItemBankTemplate.objects.get(pk=1) item_bank.question_type = QuestionType.objects.get(pk=1) item_bank.save() user_item_bank = UserItemBank() user_item_bank.user = user user_item_bank.item_bank = item_bank user_item_bank.save() #Create a threshold grd = Grade.objects.get(name="A") thresh = Threshold() thresh.grade = grd thresh.item_bank = item_bank thresh.ability = -1 thresh.save() user_item_bank.probabilities() user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() #Give the test some questions #Create fraction question bank fqb = FractionQuestionBank() oper = Oper.objects.get(pk=1) n = 20 st = 0 en = 10 name = "Test Bank" negatives_allowed = True fqb.generate(name,st,en,negatives_allowed,oper,n) #Fill item bank from fraction question bank item_bank.fill(fqb,"fractions") user_cat_test = UserCatTest() user_cat_test.user = user user_cat_test.item_bank = item_bank user_cat_test.cat_test = cat_test user_cat_test.save() cat_test_item = user_cat_test.nextQuestion() #Correct answer to question ibfq = ItemBankFractionQuestion.objects.filter(item_bank_question=cat_test_item.item_bank_question) answer = ibfq[0].fraction_bank_question.question.answer #Test post triggers marking process response = self.client.post('/question/', {'const': answer.const+1, 'num': answer.num+1, 'denom': answer.denom+1, 'time': 12}) print answer.const, answer.num, answer.denom response = self.client.get('/feedback/') #First question right #Should say right or wrong self.assertIn('Wrong!',response.content) #Should give user's answer self.assertIn(str(answer.const+1),response.content) #Should give user's answer self.assertIn(str(answer.num+1),response.content) #Should give user's answer self.assertIn(str(answer.denom+1),response.content) #Should give right answer self.assertIn(str(answer.const),response.content) self.assertIn(str(answer.num),response.content) self.assertIn(str(answer.denom),response.content) #Should show user's time self.assertIn('12',response.content) #Should show probabilities self.assertIn('%',response.content)