Пример #1
0
 /**
  * Test "testselectOneLesson()" in Assignments.class.inc.
  */
 public function testselectOneLesson()
 {
     // Construct a fake student.  Populate with three lessons.
     // Run about 100 selections and test that a lesson is returned in the
     // correct ratio.
     $this->resetMyArray();
     // Reset myArray to origninal values.
     $ac_class_instance = new AssignmentsClass();
     $temp_student_id = 'abcdefg';
     $ac_class_instance->delRowsByStudentId($temp_student_id);
     // Insure no previous lessons for this student.
     $this->myArray['tA_S_ID'] = $temp_student_id;
     $this->myArray['tA_PercentTime'] = 120;
     $this->myArray['tG_AssignmentName'] = 'abc';
     $ac_class_instance->insertRecord($this->myArray);
     $this->myArray['tA_PercentTime'] = 137;
     $this->myArray['tG_AssignmentName'] = 'def';
     $ac_class_instance->insertRecord($this->myArray);
     $this->myArray['tA_PercentTime'] = 20;
     $this->myArray['tG_AssignmentName'] = 'ghi';
     $ac_class_instance->insertRecord($this->myArray);
     // We should now have 3 assignments for this student.  Let's check.
     $student_assignments_array = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id);
     $this->assertTrue(count($student_assignments_array) === 3);
     $this->assertTrue($ac_class_instance->getSumOfAssignedTimeFromArray($student_assignments_array, time()) === 277);
     $all_lesson_array = $ac_class_instance->getCurrentStudentAssignmentsInAnArray($temp_student_id);
     $this->assertTrue(is_array($all_lesson_array));
     $this->assertTrue(count($all_lesson_array) == 3);
     $total_abc = 0;
     $total_def = 0;
     $total_ghi = 0;
     for ($i = 0; $i < 100; $i++) {
         // Trying to select a lesson many times and
         // Checking for frequency.
         $last_lesson_id = '';
         $selected_lesson = $ac_class_instance->selectOneLesson($all_lesson_array, $last_lesson_id);
         // Should return array containing one lesson.
         if (is_array($selected_lesson) === TRUE) {
             if ($selected_lesson['tG_AssignmentName'] === 'abc') {
                 $total_abc++;
             }
             if ($selected_lesson['tG_AssignmentName'] === 'def') {
                 $total_def++;
             }
             if ($selected_lesson['tG_AssignmentName'] === 'ghi') {
                 $total_ghi++;
             }
         } else {
             die(__LINE__ . ' acTest should have been an array.');
         }
     }
     //end for
     $this->assertTrue($total_abc > 30);
     $this->assertTrue($total_def > 30);
     $this->assertTrue($total_abc > 1);
     // Clean Up.
     $ac_class_instance->delRowsByStudentId($temp_student_id);
     $ac_class_instance->delRowsByStudentId($this->myArray['tA_S_ID']);
     // Insure no previous lessons for this student.
     $ac_class_instance->delRowsByStudentId('abcdefg');
     $this->resetMyArray();
 }