/** * Question creation test * @param * @return */ public function t_e_stCreation() { global $ilDB; include_once './Modules/TestQuestionPool/classes/class.assSingleChoice.php'; $insert_id = ilassSingleChoiceTest::createSampleQuestion(); $this->assertGreaterThan(0, $insert_id); if ($insert_id > 0) { $sc = new assSingleChoice(); $sc->loadFromDb($insert_id); $this->assertEquals($sc->getPoints(), 1); $this->assertEquals($sc->getTitle(), "unit test single choice question"); $this->assertEquals($sc->getComment(), "unit test single choice question comment"); $this->assertEquals($sc->getAuthor(), "Helmut Schottmüller"); $this->assertEquals($sc->getQuestion(), "<p>is a <strong>unit test</strong> required?</p>"); $this->assertEquals(count($sc->getAnswers()), 2); $result = $sc->delete($insert_id); $this->assertEquals($result, true); } }
/** * Calculate points * * This function calculates the points for a given answer. * Better would be to re-use from T&A here in the future. * When this code has been written this has not been possible yet. * * @param * @return */ static function calculatePoints($a_type, $a_id, $a_choice) { global $ilLog; switch ($a_type) { case "assSingleChoice": include_once "./Modules/TestQuestionPool/classes/class.assSingleChoice.php"; $q = new assSingleChoice(); $q->loadFromDb($a_id); $points = 0; foreach ($q->getAnswers() as $key => $answer) { if (isset($a_choice[0]) && $key == $a_choice[0]) { $points += $answer->getPoints(); } } break; case "assMultipleChoice": include_once "./Modules/TestQuestionPool/classes/class.assMultipleChoice.php"; $q = new assMultipleChoice(); $q->loadFromDb($a_id); $points = 0; foreach ($q->getAnswers() as $key => $answer) { if (is_array($a_choice) && in_array($key, $a_choice)) { $points += $answer->getPoints(); } else { $points += $answer->getPointsUnchecked(); } } break; case "assClozeTest": include_once "./Modules/TestQuestionPool/classes/class.assClozeTest.php"; $q = new assClozeTest(); $q->loadFromDb($a_id); $points = 0; foreach ($q->getGaps() as $id => $gap) { $choice = $a_choice[$id]; switch ($gap->getType()) { case CLOZE_TEXT: $gappoints = 0; for ($order = 0; $order < $gap->getItemCount(); $order++) { $answer = $gap->getItem($order); $gotpoints = $q->getTextgapPoints($answer->getAnswertext(), $choice, $answer->getPoints()); if ($gotpoints > $gappoints) { $gappoints = $gotpoints; } } $points += $gappoints; //$ilLog->write("ct: ".$gappoints); break; case CLOZE_NUMERIC: $gappoints = 0; for ($order = 0; $order < $gap->getItemCount(); $order++) { $answer = $gap->getItem($order); $gotpoints = $q->getNumericgapPoints($answer->getAnswertext(), $choice, $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound()); if ($gotpoints > $gappoints) { $gappoints = $gotpoints; } } $points += $gappoints; //$ilLog->write("cn: ".$gappoints); break; case CLOZE_SELECT: for ($order = 0; $order < $gap->getItemCount(); $order++) { $answer = $gap->getItem($order); if ($choice == $answer->getOrder()) { $answerpoints = $answer->getPoints(); $points += $answerpoints; //$ilLog->write("cs: ".$answerpoints); } } break; } } break; case "assMatchingQuestion": include_once "./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php"; $q = new assMatchingQuestion(); $q->loadFromDb($a_id); $points = 0; for ($i = 0; $i < $q->getMatchingPairCount(); $i++) { $pair = $q->getMatchingPair($i); if (is_array($a_choice) && in_array($pair->definition->identifier . "-" . $pair->term->identifier, $a_choice)) { $points += $pair->points; } } break; case "assOrderingQuestion": include_once "./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php"; $q = new assOrderingQuestion(); $q->loadFromDb($a_id); $points = 0; $cnt = 1; $right = true; foreach ($q->getAnswers() as $answer) { if ($a_choice[$cnt - 1] != $cnt) { $right = false; } $cnt++; } if ($right) { $points = $q->getPoints(); } break; case "assImagemapQuestion": include_once "./Modules/TestQuestionPool/classes/class.assImagemapQuestion.php"; $q = new assImagemapQuestion(); $q->loadFromDb($a_id); $points = 0; foreach ($q->getAnswers() as $key => $answer) { if (is_array($a_choice) && in_array($key, $a_choice)) { $points += $answer->getPoints(); } } break; } if ($points < 0) { $points = 0; } return (int) $points; }