예제 #1
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)      
예제 #2
0
파일: tests.py 프로젝트: cbwheadon/maths
 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))
예제 #3
0
파일: tests.py 프로젝트: cbwheadon/maths
 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)
예제 #4
0
 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)                   
예제 #5
0
 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)