Skip to content

Commit

Permalink
Merge pull request #310 from oat-sa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
augustas authored Apr 1, 2022
2 parents d7b8a04 + 5125b38 commit 4509d3a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/qtism/runtime/tests/BasicSelection.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ public function select()

if ($withReplacement === false) {
unset($selectionBag[$baseIndex]);
$selectionBag = array_values($selectionBag);
$selectionBagCount--;
$select--;
}
}
}
// reset indexes for remaining selections
$selectionBag = array_values($selectionBag);

for ($i = 0; $i < $select; $i++) {
$selectedIndex = mt_rand(0, $selectionBagCount - 1);
Expand Down
34 changes: 34 additions & 0 deletions test/qtismtest/runtime/tests/BasicSelectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace qtismtest\runtime\tests;

use qtism\data\AssessmentItemRef;
use qtism\data\SectionPart;
use qtism\data\storage\xml\XmlDocument;
use qtism\runtime\tests\BasicSelection;
use qtism\runtime\tests\SelectableRoute;
Expand Down Expand Up @@ -55,6 +57,38 @@ public function testBasicSelection()

$this::assertFalse($routeCheck1 === true && $routeCheck2 === true);
$this::assertTrue($routeCheck1 === true || $routeCheck2 === true);

}

public function testSelectRequired()
{
$doc = new XmlDocument();
$doc->load(self::samplesDir() . 'custom/runtime/selection_ordering/selection_and_ordering.xml');

$testPart = $doc->getDocumentComponent()->getComponentByIdentifier('testPart');

$s04 = $doc->getDocumentComponent()->getComponentByIdentifier('S04', true);
$this::assertEquals('S04', $s04->getIdentifier());

$s04RouteCollection = new SelectableRouteCollection();

/** @var SectionPart $sectionPart */
foreach ($s04->getSectionParts() as $sectionPart) {
$route = new SelectableRoute();
$route->addRouteItem($sectionPart, $s04, $testPart, $doc->getDocumentComponent());
$route->setRequired($sectionPart->isRequired());
$s04RouteCollection->attach($route);
}

$selection = new BasicSelection($s04, $s04RouteCollection);
$selectedRoutes = $selection->select();
$itemRefs = [];
foreach ($selectedRoutes as $r) {
foreach ($r->getAssessmentItemRefs() as $itemRef) {
$itemRefs[] = $itemRef->getIdentifier();
}
}
$this::assertEquals(5, count(array_unique($itemRefs)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@
<assessmentItemRef identifier="Q11" href="./Q11.xml" fixed="false" timeDependent="false"/>
<assessmentItemRef identifier="Q12" href="./Q12.xml" fixed="false" timeDependent="false"/>
</assessmentSection>
<assessmentSection identifier="S04" fixed="false" title="Section S04" visible="true">
<selection select="5"/>
<assessmentItemRef identifier="Q1" required="false" href="./Q1.xml" fixed="false" timeDependent="false" />
<assessmentItemRef identifier="Q2" required="true" href="./Q2.xml" fixed="false" timeDependent="false" />
<assessmentItemRef identifier="Q3" required="false" href="./Q3.xml" fixed="false" timeDependent="false" />
<assessmentItemRef identifier="Q7" required="true" href="./Q7.xml" fixed="false" timeDependent="false" />
<assessmentItemRef identifier="Q8" required="false" href="./Q8.xml" fixed="false" timeDependent="false" />
</assessmentSection>
</testPart>
</assessmentTest>
</assessmentTest>

0 comments on commit 4509d3a

Please sign in to comment.