Пример #1
0
 /**
  * Test test "normalizePercentTimeTo100Percent()" in Assignments.class.inc.
  */
 public function testnormalizePercentTimeTo100Percent()
 {
     // Input parameter is an array of lessons for one student.
     // Returns normalized array of lessons totalling 100%.
     // Create a three lesson array of lessons.
     // Reset myArray to origninal values.
     $this->resetMyArray();
     $ac_class_instance = new AssignmentsClass();
     $temp_student_id = 'abcdefg';
     // Insure no previous lessons for this student.
     $ac_class_instance->delRowsByStudentId($temp_student_id);
     // Add three new lessons.
     $this->myArray['tA_S_ID'] = $temp_student_id;
     $this->myArray['tA_PercentTime'] = 120;
     $ac_class_instance->insertRecord($this->myArray);
     $this->myArray['tA_PercentTime'] = 137;
     $ac_class_instance->insertRecord($this->myArray);
     $this->myArray['tA_PercentTime'] = 20;
     $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);
     // Check Sum of Assigned Time.
     $this->assertTrue($ac_class_instance->getSumOfAssignedTimeFromArray($student_assignments_array) === 277);
     // Now check normalization to 100%.
     $result = $ac_class_instance->normalizePercentTimeTo100Percent($student_assignments_array);
     $total_assigned = 0;
     foreach ($result as $key => $content) {
         $total_assigned = $total_assigned + $content['tA_PercentTime'];
     }
     $this->assertTrue($total_assigned == '100');
     // Wonder why rounding errors don't cause this to fail.
     // Clean up.
     $ac_class_instance->delRowsByStudentId($temp_student_id);
     // Clean Up.
     $ac_class_instance->delRowsByStudentId($this->myArray['tA_S_ID']);
     $ac_class_instance->delRowsByStudentId('abcdefg');
     unset($ac_class_instance);
     $this->resetMyArray();
 }