Skip to content

Commit

Permalink
Added the possibility to count item occurences in different ways.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Apr 22, 2016
1 parent f7c2cee commit f7df238
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "qtism/qtism",
"description": "OAT QTI Software Module Library",
"type": "library",
"version": "0.9.27",
"version": "0.9.28",
"authors": [
{
"name": "Open Assessment Technologies S.A.",
Expand Down
47 changes: 35 additions & 12 deletions qtism/runtime/tests/AssessmentTestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
*/
class AssessmentTestSession extends State {

const ROUTECOUNT_ALL = 0;
const ROUTECOUNT_EXCLUDENORESPONSE = 1;

/**
* A unique ID for this AssessmentTestSession.
*
Expand Down Expand Up @@ -1863,19 +1866,39 @@ public function getAssessmentItemSessions($identifier) {
* @param IdentifierCollection $excludeCategories The optional item categories to be excluded from the subset.
* @return AssessmentItemRefCollection A collection of AssessmentItemRef objects that match all the given criteria.
*/
public function getItemSubset($sectionIdentifier = '', IdentifierCollection $includeCategories = null, IdentifierCollection $excludeCategories = null) {
return $this->getRoute()->getAssessmentItemRefsSubset($sectionIdentifier, $includeCategories, $excludeCategories);
}
public function getItemSubset($sectionIdentifier = '', IdentifierCollection $includeCategories = null, IdentifierCollection $excludeCategories = null) {
return $this->getRoute()->getAssessmentItemRefsSubset($sectionIdentifier, $includeCategories, $excludeCategories);
}

/**
* Get the number of items in the current Route. In other words, the total number
* of item occurences the candidate can take during the test.
*
* @return integer
*/
public function getRouteCount() {
return $this->getRoute()->count();
}
/**
* Get the number of items in the current Route. In other words, the total number
* of item occurences the candidate can take during the test.
*
* The $mode parameter can take two values:
*
* * AssessmentTestSession::ROUTECOUNT_ALL: consider all item occurences of the test
* * AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE: consider only item occurences containing at least one response declaration.
*
* @param integer $mode AssessmentTestSession::ROUTECOUNT_ALL | AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE
* @return integer
*/
public function getRouteCount($mode = self::ROUTECOUNT_ALL)
{
if ($mode === self::ROUTECOUNT_ALL) {

return $this->getRoute()->count();
} else {
$i = 0;

foreach ($this->getRoute()->getAssessmentItemRefs() as $assessmentItemRef) {
if (count($assessmentItemRef->getResponseDeclarations()) > 0) {
$i++;
}
}

return $i;
}
}

/**
* Get the map of last occurence updates.
Expand Down
25 changes: 25 additions & 0 deletions test/qtism/runtime/tests/AssessmentTestSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use qtism\common\enums\Cardinality;
use qtism\common\enums\BaseType;
use qtism\runtime\common\ResponseVariable;
use qtism\runtime\tests\AssessmentTestSession;
use qtism\runtime\tests\AssessmentTestSessionState;
use qtism\runtime\tests\AssessmentTestSessionException;
use qtism\common\datatypes\Point;
Expand Down Expand Up @@ -1460,4 +1461,28 @@ public function testSuspendResume() {
// Q02.
$this->assertEquals('Q02', $assessmentTestSession->getCurrentAssessmentItemRef()->getIdentifier());
}

public function testGetRouteCountAllWithResponseDeclaration() {
$doc = new XmlCompactDocument();
$doc->load(self::samplesDir() . 'custom/runtime/route_count/all_with_responsedeclaration.xml');
$manager = new SessionManager();
$session = $manager->createAssessmentTestSession($doc->getDocumentComponent());
$session->beginTestSession();

$this->assertEquals(3, $session->getRouteCount());
$this->assertEquals(3, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_ALL));
$this->assertEquals(3, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE));
}

public function testGetRouteCountMissingResponseDeclaration() {
$doc = new XmlCompactDocument();
$doc->load(self::samplesDir() . 'custom/runtime/route_count/missing_responsedeclaration.xml');
$manager = new SessionManager();
$session = $manager->createAssessmentTestSession($doc->getDocumentComponent());
$session->beginTestSession();

$this->assertEquals(3, $session->getRouteCount());
$this->assertEquals(3, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_ALL));
$this->assertEquals(2, $session->getRouteCount(AssessmentTestSession::ROUTECOUNT_EXCLUDENORESPONSE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<assessmentTest xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.taotesting.com/xsd/qticompact_v1p0.xsd"
identifier="linear_route_count" title="Linear Route Count">
<testPart identifier="P01" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S01" title="Section1" visible="true">
<assessmentItemRef identifier="Q01" href="./Q01.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>

<assessmentItemRef identifier="Q02" href="./Q02.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>

<assessmentItemRef identifier="Q03" href="./Q03.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>
</assessmentSection>
</testPart>
</assessmentTest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<assessmentTest xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.taotesting.com/xsd/qticompact_v1p0.xsd"
identifier="linear_route_count" title="Linear Route Count">
<testPart identifier="P01" navigationMode="linear" submissionMode="individual">
<assessmentSection identifier="S01" title="Section1" visible="true">
<assessmentItemRef identifier="Q01" href="./Q01.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>

<assessmentItemRef identifier="Q02" href="./Q02.xml" timeDependent="false"/>

<assessmentItemRef identifier="Q03" href="./Q03.xml" timeDependent="false">
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier"/>
</assessmentItemRef>
</assessmentSection>
</testPart>
</assessmentTest>

0 comments on commit f7df238

Please sign in to comment.