Beispiel #1
0
 /**
  * Test "testselectALesson()" in Assignments.class.inc
  *
  * A *description*, that can span multiple lines, to go _in-depth_ into the details of this element
  * and to provide some background information or textual references.
  *
  * @return void
  */
 public function testselectALesson()
 {
     // Construct a fake student.  Populate with three lessons.
     // Run about 100 selections and test that a lesson is returned in the
     // correct ratio.
     $this->testbuildArray();
     // Reset myArray to origninal values.
     $classInstance = new tutor\src\classes\AssignmentsClass();
     $tempStudent = 'abcdefg';
     $classInstance->delRowsByStudentId($tempStudent);
     // Insure no previous lessons for this student.
     $this->myArray['tA_S_ID'] = $tempStudent;
     $this->myArray['tA_PercentTime'] = 120;
     $this->myArray['tG_AssignmentName'] = 'abc';
     $classInstance->insertRecord($this->myArray);
     $this->myArray['tA_PercentTime'] = 137;
     $this->myArray['tG_AssignmentName'] = 'def';
     $classInstance->insertRecord($this->myArray);
     $this->myArray['tA_PercentTime'] = 20;
     $this->myArray['tG_AssignmentName'] = 'ghi';
     $classInstance->insertRecord($this->myArray);
     // We should now have 3 assignments for this student.  Let's check.
     $studentAssignmentsArray = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent);
     $this->assertTrue(count($studentAssignmentsArray) === 3);
     $this->assertTrue($classInstance->getSumOfAssignedTimeFromArray($studentAssignmentsArray, time()) === 277);
     $allLessonArray = $classInstance->getCurrentStudentAssignmentsInAnArray($tempStudent);
     $this->assertTrue(is_array($allLessonArray));
     $this->assertTrue(count($allLessonArray) == 3);
     $totalAbc = 0;
     $totalDef = 0;
     $totalGhi = 0;
     for ($i = 0; $i < 100; $i++) {
         // Trying to select a lesson many times and
         // Checking for frequency.
         $lastLessonId = '';
         $selectedLesson = $classInstance->selectALesson($allLessonArray, $lastLessonId);
         // Should return array containing one lesson.
         if (is_array($selectedLesson) === TRUE) {
             if ($selectedLesson['tG_AssignmentName'] === 'abc') {
                 $totalAbc++;
             }
             if ($selectedLesson['tG_AssignmentName'] === 'def') {
                 $totalDef++;
             }
             if ($selectedLesson['tG_AssignmentName'] === 'ghi') {
                 $totalGhi++;
             }
         } else {
             die(__LINE__ . ' acTest should have been an array.');
         }
     }
     //end for
     $this->assertTrue($totalAbc > 30);
     $this->assertTrue($totalDef > 30);
     $this->assertTrue($totalAbc > 1);
     // Clean Up.
     $classInstance->delRowsByStudentId($tempStudent);
     $classInstance->delRowsByStudentId($this->myArray['tA_S_ID']);
     // Insure no previous lessons for this student.
     $classInstance->delRowsByStudentId('abcdefg');
 }