/** * Test test "normalizePercentTimeTo100Percent()" 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 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->testbuildArray(); $classInstance = new tutor\src\classes\AssignmentsClass(); $tempStudent = 'abcdefg'; // Insure no previous lessons for this student. $classInstance->delRowsByStudentId($tempStudent); // Add three new lessons. $this->myArray['tA_S_ID'] = $tempStudent; $this->myArray['tA_PercentTime'] = 120; $classInstance->insertRecord($this->myArray); $this->myArray['tA_PercentTime'] = 137; $classInstance->insertRecord($this->myArray); $this->myArray['tA_PercentTime'] = 20; $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); // Check Sum of Assigned Time. $this->assertTrue($classInstance->getSumOfAssignedTimeFromArray($studentAssignmentsArray) === 277); // Now check normalization to 100%. $result = $classInstance->normalizePercentTimeTo100Percent($studentAssignmentsArray); $totalAssigned = 0; foreach ($result as $key => $content) { $totalAssigned = $totalAssigned + $content['tA_PercentTime']; } $this->assertTrue($totalAssigned == '100'); // Wonder why rounding errors don't cause this to fail. // Clean up. $classInstance->delRowsByStudentId($tempStudent); // Clean Up. $classInstance->delRowsByStudentId($this->myArray['tA_S_ID']); $classInstance->delRowsByStudentId('abcdefg'); unset($classInstance); }