/** * @depends testTemplateConditionSimpleIf1 */ public function testTemplateConditionSimpleIf2() { $rule = $this->createComponentFromXml(' <templateCondition> <templateIf> <baseValue baseType="boolean">true</baseValue> <setTemplateValue identifier="TPL1"> <baseValue baseType="integer">1</baseValue> </setTemplateValue> <setDefaultValue identifier="RSP1"> <baseValue baseType="identifier">Choice1</baseValue> </setDefaultValue> <setCorrectResponse identifier="RSP1"> <baseValue baseType="identifier">Choice2</baseValue> </setCorrectResponse> </templateIf> </templateCondition> '); $state = new State(); $state->setVariable(new TemplateVariable('TPL1', Cardinality::SINGLE, BaseType::INTEGER)); $state->setVariable(new ResponseVariable('RSP1', Cardinality::SINGLE, BaseType::IDENTIFIER)); $processor = new TemplateConditionProcessor($rule); $processor->setState($state); $processor->process(); $this->assertEquals(1, $state['TPL1']->getValue()); $this->assertEquals('Choice1', $state->getVariable('RSP1')->getDefaultValue()->getValue()); $this->assertEquals('Choice2', $state->getVariable('RSP1')->getCorrectResponse()->getValue()); }
public function testMultipleComplexTyping() { $variableDeclaration = $this->createComponentFromXml(' <responseDeclaration identifier="response1" baseType="pair" cardinality="multiple"> <mapping defaultValue="1"> <mapEntry mapKey="A B" mappedValue="1.5"/> <mapEntry mapKey="C D" mappedValue="2.5"/> </mapping> </responseDeclaration> '); $variable = ResponseVariable::createFromDataModel($variableDeclaration); $mapResponseExpr = $this->createComponentFromXml('<mapResponse identifier="response1"/>'); $mapResponseProcessor = new MapResponseProcessor($mapResponseExpr); $state = new State(); $state->setVariable($variable); $mapResponseProcessor->setState($state); // No value could be tried to be matched. $result = $mapResponseProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(0.0, $result->getValue()); $state['response1'] = new MultipleContainer(BaseType::PAIR, array(new Pair('A', 'B'))); $result = $mapResponseProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(1.5, $result->getValue()); $state['response1'][] = new Pair('C', 'D'); $result = $mapResponseProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(4, $result->getValue()); // mapEntries must be taken into account only once, as per QTI 2.1 spec. $state['response1'][] = new Pair('C', 'D'); $result = $mapResponseProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result); $this->assertEquals(4, $result->getValue()); // 2.5 taken into account only once! }
public function testSimple() { $variableExpr = $this->createComponentFromXml('<variable identifier="var1"/>'); // single cardinality test. $var1 = new OutcomeVariable('var1', Cardinality::SINGLE, BaseType::INTEGER, new Integer(1337)); $state = new State(array($var1)); $this->assertInstanceOf('qtism\\runtime\\common\\OutcomeVariable', $state->getVariable('var1')); $variableProcessor = new VariableProcessor($variableExpr); $this->assertTrue($variableProcessor->process() === null); // State is raw. $variableProcessor->setState($state); // State is populated with var1. $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result); $this->assertEquals(1337, $result->getValue()); // multiple cardinality test. $val = new OrderedContainer(BaseType::INTEGER, array(new Integer(10), new Integer(12))); $var2 = new OutcomeVariable('var2', Cardinality::ORDERED, BaseType::INTEGER, $val); $state->setVariable($var2); $variableExpr = $this->createComponentFromXml('<variable identifier="var2"/>'); $variableProcessor->setExpression($variableExpr); $result = $variableProcessor->process(); $this->assertInstanceOf('qtism\\runtime\\common\\OrderedContainer', $result); $this->assertEquals(10, $result[0]->getValue()); $this->assertEquals(12, $result[1]->getValue()); }
public function testUnknownVariableRef() { $expression = $this->createFakeExpression(RoundingMode::SIGNIFICANT_FIGURES, 'var1'); $operands = new OperandsCollection(array(new QtiFloat(3.175), new QtiFloat(3.183))); $processor = new EqualRoundedProcessor($expression, $operands); $state = new State(); $state->setVariable(new OutcomeVariable('varX', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(3))); $processor->setState($state); $this->setExpectedException('qtism\\runtime\\expressions\\ExpressionProcessingException'); $result = $processor->process(); $this->assertSame(true, $result->getValue()); }
public function testVariableReferenceNotInteger() { $expression = $this->createFakeExpression('variable1'); $operands = new OperandsCollection(); $operands[] = new OrderedContainer(BaseType::INTEGER, array(new QtiInteger(1), new QtiInteger(2), new QtiInteger(3), new QtiInteger(4), new QtiInteger(5))); $processor = new IndexProcessor($expression, $operands); $state = new State(); $state->setVariable(new OutcomeVariable('variable1', Cardinality::SINGLE, BaseType::POINT, new QtiPoint(1, 2))); $processor->setState($state); $this->setExpectedException('qtism\\runtime\\expressions\\ExpressionProcessingException'); $result = $processor->process(); }
public function testResponseProcessingMatchCorrect() { $outcomeProcessing = $this->createComponentFromXml(' <!-- I known that this outcomeProcessing is not well written but this is just for a testing purpose. --> <outcomeProcessing> <outcomeCondition> <outcomeIf> <match> <variable identifier="t"/> <baseValue baseType="boolean">true</baseValue> </match> <setOutcomeValue identifier="SCORE"> <!-- 20/20 !!! --> <baseValue baseType="float">20</baseValue> </setOutcomeValue> </outcomeIf> </outcomeCondition> <outcomeCondition> <outcomeIf> <match> <variable identifier="t"/> <baseValue baseType="boolean">false</baseValue> </match> <setOutcomeValue identifier="SCORE"> <!-- 0/20 !!! --> <baseValue baseType="float">0</baseValue> </setOutcomeValue> </outcomeIf> </outcomeCondition> </outcomeProcessing> '); $outcomeVariable = new OutcomeVariable('SCORE', Cardinality::SINGLE, BaseType::FLOAT); $context = new State(array($outcomeVariable)); $engine = new OutcomeProcessingEngine($outcomeProcessing, $context); $engine->process(); // SCORE is still NULL because the 't' variable was not provided to the context. $this->assertSame(null, $context['SCORE']); $context->setVariable(new OutcomeVariable('t', Cardinality::SINGLE, BaseType::BOOLEAN, new Boolean(true))); $this->assertTrue($context['t']->getValue()); // After processing, the $context['SCORE'] value must be 20.0. $engine->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $context['SCORE']); $this->assertEquals(20.0, $context['SCORE']->getValue()); $context['t'] = new Boolean(false); // After processing, the $context['SCORE'] value must switch to 0.0. $engine->process(); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $context['SCORE']); $this->assertEquals(0.0, $context['SCORE']->getValue()); }
/** * Checks whether or not $value: * * * is an instance of OutcomeVariable * * has a 'duration' QTI baseType. * * has 'single' QTI cardinality. * * @throws \InvalidArgumentException If one or more of the conditions above are not respected. */ protected function checkType($value) { parent::checkType($value); if (!$value instanceof OutcomeVariable) { $className = get_class($value); $msg = "The DurationStore only aims at storing OutcomeVariable objects, {$className} object given."; throw new InvalidArgumentException($msg); } if (($bt = $value->getBaseType()) !== BaseType::DURATION) { $baseTypeName = BaseType::getNameByConstant($bt); $msg = "The DurationStore only aims at storing OutcomeVariable objects with a 'duration' baseType, "; $msg .= "'{$baseTypeName}' baseType given "; $id = $value->getIdentifier(); $msg .= "for variable '{$id}'."; throw new InvalidArgumentException($msg); } if (($bt = $value->getCardinality()) !== Cardinality::SINGLE) { $cardinalityName = Cardinality::getNameByConstant($bt); $msg = "The DurationStore only aims at storing OutcomeVariable objects with a 'single' cardinality, "; $msg .= "'{$cardinalityName}' cardinality given "; $id = $value->getIdentifier(); $msg .= "for variable '{$id}'."; throw new InvalidArgumentException($msg); } }
public function testGetAllVariables() { $state = new State(); $this->assertEquals(0, count($state->getAllVariables())); $state->setVariable(new ResponseVariable('RESPONSE1', Cardinality::SINGLE, BaseType::INTEGER, new Integer(25))); $this->assertEquals(1, count($state->getAllVariables())); $state->setVariable(new OutcomeVariable('SCORE1', Cardinality::SINGLE, BaseType::BOOLEAN, new Boolean(true))); $this->assertEquals(2, count($state->getAllVariables())); unset($state['RESPONSE1']); $this->assertEquals(1, count($state->getAllVariables())); $this->assertInstanceOf('qtism\\runtime\\common\\VariableCollection', $state->getAllVariables()); }
public function testResponseProcessingExitResponse() { $responseProcessing = $this->createComponentFromXml(' <responseProcessing> <setOutcomeValue identifier="OUTCOME"> <baseValue baseType="integer">1</baseValue> </setOutcomeValue> <exitResponse/> <!-- Should never be executed! --> <setOutcomeValue identifier="OUTCOME"> <baseValue baseType="integer">2</baseValue> </setOutcomeValue> </responseProcessing> '); $state = new State(); $state->setVariable(new OutcomeVariable('OUTCOME', Cardinality::SINGLE, BaseType::INTEGER)); $engine = new ResponseProcessingEngine($responseProcessing); $engine->setContext($state); $engine->process(); $this->assertEquals(1, $state['OUTCOME']->getValue()); }
/** * Create a new AssessmentTestSession object. * * @param AssessmentTest $assessmentTest The AssessmentTest object which represents the assessmenTest the context belongs to. * @param AbstractSessionManager $sessionManager The manager to be used to create new AssessmentItemSession objects. * @param Route $route The sequence of items that has to be taken for the session. */ public function __construct(AssessmentTest $assessmentTest, AbstractSessionManager $sessionManager, Route $route) { parent::__construct(); $this->setAssessmentTest($assessmentTest); $this->setSessionManager($sessionManager); $this->setRoute($route); $this->setAssessmentItemSessionStore(new AssessmentItemSessionStore()); $this->setLastOccurenceUpdate(new SplObjectStorage()); $this->setPendingResponseStore(new PendingResponseStore()); $durationStore = new DurationStore(); $this->setDurationStore($durationStore); // Take the outcomeDeclaration objects of the global scope. // Instantiate them with their defaults. foreach ($this->getAssessmentTest()->getOutcomeDeclarations() as $globalOutcome) { $variable = OutcomeVariable::createFromDataModel($globalOutcome); $variable->applyDefaultValue(); $this->setVariable($variable); } $this->setSessionId('no_session_id'); $this->setState(AssessmentTestSessionState::INITIAL); }
public function testIsCorrect() { $itemSession = self::instantiateBasicAdaptiveAssessmentItem(); $this->assertEquals(AssessmentItemSessionState::NOT_SELECTED, $itemSession->getState()); // The item session is in NOT_SELECTED mode, then false is returned directly. $this->assertFalse($itemSession->isCorrect()); $itemSession->beginItemSession(); $itemSession->beginAttempt(); // No response given, false is returned. $this->assertFalse($itemSession->isCorrect()); $state = new State(); $state->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA'))); $itemSession->endAttempt($state); // Wrong answer ('ChoiceB' is the correct one), the session is not correct. $this->assertEquals('incomplete', $itemSession['completionStatus']->getValue()); $this->assertFalse($itemSession->isCorrect()); $state['RESPONSE'] = new Identifier('ChoiceB'); $itemSession->beginAttempt(); $itemSession->endAttempt($state); // Correct answer, the session is correct! $this->assertTrue($itemSession->isCorrect()); $this->assertEquals('completed', $itemSession['completionStatus']->getValue()); }
/** * Get the OutcomeVariable objects contained in the AssessmentItemSession. * * @param boolean $builtIn Whether to include the built-in OutcomeVariable 'completionStatus'. * @return \qtism\runtime\common\State A State object composed exclusively with OutcomeVariable objects. */ public function getOutcomeVariables($builtIn = true) { $state = new State(); $data = $this->getDataPlaceHolder(); foreach ($data as $id => $var) { if ($var instanceof OutcomeVariable && ($builtIn === true || $id !== 'completionStatus')) { $state->setVariable($var); } } return $state; }
/** * @dataProvider testOutcomeConditionComplexProvider * * @param integer $t * @param integer $tt * @param string $expectedX * @param string $expectedY * @param string $expectedZ */ public function testOutcomeConditionComplex($t, $tt, $expectedX, $expectedY, $expectedZ) { $rule = $this->createComponentFromXml(' <outcomeCondition> <outcomeIf> <equal> <variable identifier="t"/> <baseValue baseType="integer">1</baseValue> </equal> <outcomeCondition> <outcomeIf> <equal> <variable identifier="tt"/> <baseValue baseType="integer">1</baseValue> </equal> <setOutcomeValue identifier="x"> <baseValue baseType="string">A</baseValue> </setOutcomeValue> </outcomeIf> <outcomeElse> <setOutcomeValue identifier="x"> <baseValue baseType="string">B</baseValue> </setOutcomeValue> </outcomeElse> </outcomeCondition> <setOutcomeValue identifier="y"> <baseValue baseType="string">C</baseValue> </setOutcomeValue> </outcomeIf> <outcomeElseIf> <equal> <variable identifier="t"/> <baseValue baseType="integer">2</baseValue> </equal> <setOutcomeValue identifier="y"> <baseValue baseType="string">A</baseValue> </setOutcomeValue> <setOutcomeValue identifier="z"> <baseValue baseType="string">B</baseValue> </setOutcomeValue> </outcomeElseIf> <outcomeElseIf> <equal> <variable identifier="t"/> <baseValue baseType="integer">3</baseValue> </equal> <setOutcomeValue identifier="x"> <baseValue baseType="string">V</baseValue> </setOutcomeValue> </outcomeElseIf> <outcomeElse> <setOutcomeValue identifier="x"> <baseValue baseType="string">Z</baseValue> </setOutcomeValue> </outcomeElse> </outcomeCondition> '); $state = new State(); $state->setVariable(new OutcomeVariable('t', Cardinality::SINGLE, BaseType::INTEGER, $t)); $state->setVariable(new OutcomeVariable('tt', Cardinality::SINGLE, BaseType::INTEGER, $tt)); $state->setVariable(new OutcomeVariable('x', Cardinality::SINGLE, BaseType::STRING)); $state->setVariable(new OutcomeVariable('y', Cardinality::SINGLE, BaseType::STRING)); $state->setVariable(new OutcomeVariable('z', Cardinality::SINGLE, BaseType::STRING)); $processor = new OutcomeConditionProcessor($rule); $processor->setState($state); $processor->process(); $this->check($expectedX, $state['x']); $this->check($expectedY, $state['y']); $this->check($expectedZ, $state['z']); }
/** * Read a PendingResponse object from the current binary stream. * * @param AssessmentTestSeeker $seeker An AssessmentTestSeeker object in order to know tree position for involved QTI Components. * @return PendingResponses A PendingResponses object. * @throws QtiBinaryStreamAccessException */ public function readPendingResponses(AssessmentTestSeeker $seeker) { try { // Read the state. $state = new State(); $varCount = $this->readTinyInt(); for ($i = 0; $i < $varCount; $i++) { $responseDeclaration = $seeker->seekComponent('responseDeclaration', $this->readShort()); $responseVariable = ResponseVariable::createFromDataModel($responseDeclaration); $this->readVariableValue($responseVariable); $state->setVariable($responseVariable); } // Read the assessmentItemRef. $itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort()); // Read the occurence number. $occurence = $this->readTinyInt(); return new PendingResponses($state, $itemRef, $occurence); } catch (BinaryStreamAccessException $e) { $msg = "An error occured while reading some pending responses."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e); } catch (OutOfBoundsException $e) { $msg = "A QTI component was not found in the assessmentTest tree structure."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e); } }
<?php use qtism\common\datatypes\String; use qtism\common\enums\BaseType; use qtism\common\enums\Cardinality; use qtism\runtime\common\TemplateVariable; use qtism\runtime\common\State; use qtism\data\storage\xml\XmlDocument; use qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine; require_once dirname(__FILE__) . '/../../qtism/qtism.php'; $doc = new XmlDocument(); $doc->load('../samples/rendering/printedvariable_1.xml'); $renderer = new XhtmlRenderingEngine(); $state = new State(); $state->setVariable(new TemplateVariable('TPL_H', Cardinality::SINGLE, BaseType::STRING, new String('Bubble Gum'))); $state->setVariable(new TemplateVariable('TPL_He', Cardinality::SINGLE, BaseType::STRING, new String('Bacta'))); $state->setVariable(new TemplateVariable('TPL_C', Cardinality::SINGLE, BaseType::STRING, new String('Cola'))); $state->setVariable(new TemplateVariable('TPL_O', Cardinality::SINGLE, BaseType::STRING, new String('Meat'))); $state->setVariable(new TemplateVariable('TPL_N', Cardinality::SINGLE, BaseType::STRING, new String('Potatoes'))); $state->setVariable(new TemplateVariable('TPL_Cl', Cardinality::SINGLE, BaseType::STRING, new String('Candies'))); if (isset($argv[1]) && trim(strtolower($argv[1])) === 'context_aware') { $renderer->setPrintedVariablePolicy(XhtmlRenderingEngine::CONTEXT_AWARE); $renderer->setState($state); } else { if (isset($argv[1]) && trim(strtolower($argv[1])) === 'template_oriented') { $renderer->setPrintedVariablePolicy(XhtmlRenderingEngine::TEMPLATE_ORIENTED); $renderer->setState($state); } else { $renderer->setPrintedVariablePolicy(XhtmlRenderingEngine::CONTEXT_STATIC); } }
public function testNumberResponded() { $session = $this->getTestSession(); $overallResponded = self::getNumberResponded(); $includeMathResponded = self::getNumberResponded('', new IdentifierCollection(array('mathematics'))); $processor = new NumberRespondedProcessor($overallResponded); $processor->setState($session); // Nothing responded yet. $this->assertEquals(0, $processor->process()->getValue()); $processor->setExpression($includeMathResponded); $this->assertEquals(0, $processor->process()->getValue()); // Q01 $session->beginAttempt(); $responses = new State(); // Correct! $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('ChoiceA'))); $session->endAttempt($responses); $processor->setExpression($overallResponded); $this->assertEquals(1, $processor->process()->getValue()); $processor->setExpression($includeMathResponded); $this->assertEquals(1, $processor->process()->getValue()); $session->moveNext(); // Q02 $responses->reset(); $session->beginAttempt(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::MULTIPLE, BaseType::PAIR, new MultipleContainer(BaseType::PAIR, array(new QtiPair('A', 'P'), new QtiPair('D', 'L'))))); $session->endAttempt($responses); $this->assertEquals(3, $session['Q02.SCORE']->getValue()); // just for fun... $processor->setExpression($overallResponded); $this->assertEquals(2, $processor->process()->getValue()); $processor->setExpression($includeMathResponded); $this->assertEquals(1, $processor->process()->getValue()); $session->moveNext(); // Q03 $session->beginAttempt(); $session->skip(); $processor->setExpression($overallResponded); $this->assertEquals(2, $processor->process()->getValue()); $session->moveNext(); // Q04 $responses->reset(); $session->beginAttempt(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::MULTIPLE, BaseType::DIRECTED_PAIR, new MultipleContainer(BaseType::DIRECTED_PAIR, array(new QtiDirectedPair('W', 'G1'), new QtiDirectedPair('Su', 'G2'))))); $session->endAttempt($responses); $this->assertEquals(3, $session['Q04.SCORE']->getValue()); $this->assertEquals(3, $processor->process()->getValue()); $session->moveNext(); // Q05 $session->beginAttempt(); $session->skip(); $this->assertEquals(3, $processor->process()->getValue()); $session->moveNext(); // Q06 $responses->reset(); $session->beginAttempt(); $responses->setVariable(new ResponseVariable('answer', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('A'))); $session->endAttempt($responses); $this->assertEquals(4, $processor->process()->getValue()); $session->moveNext(); // Q07.1 $responses->reset(); $session->beginAttempt(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::POINT, new QtiPoint(100, 100))); $session->endAttempt($responses); $this->assertEquals(1, $session['Q07.1.SCORE']->getValue()); $this->assertEquals(5, $processor->process()->getValue()); $session->moveNext(); // Q07.2 $responses->reset(); $session->beginAttempt(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::POINT, new QtiPoint(10, 10))); $session->endAttempt($responses); $this->assertEquals(0, $session['Q07.2.SCORE']->getValue()); $this->assertEquals(6, $processor->process()->getValue()); $session->moveNext(); // Q07.3 $responses->reset(); $session->beginAttempt(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::POINT, new QtiPoint(102, 113))); $session->endAttempt($responses); $this->assertEquals(1, $session['Q07.3.SCORE']->getValue()); $this->assertEquals(7, $processor->process()->getValue()); $session->moveNext(); }
public function printedVariableProvider() { $state = new State(); $state->setVariable(new OutcomeVariable('nullValue', Cardinality::SINGLE, BaseType::BOOLEAN, null)); // Scalar values. $state->setVariable(new OutcomeVariable('nonEmptyString', Cardinality::SINGLE, BaseType::STRING, new QtiString('Non Empty String'))); $state->setVariable(new OutcomeVariable('emptyString', Cardinality::SINGLE, BaseType::STRING, new QtiString(''))); $state->setVariable(new TemplateVariable('positiveInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(25))); $state->setVariable(new TemplateVariable('zeroInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(0))); $state->setVariable(new TemplateVariable('negativeInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(-25))); $state->setVariable(new TemplateVariable('positiveFloat', Cardinality::SINGLE, BaseType::FLOAT, new QtiFloat(25.3455322345))); $state->setVariable(new OutcomeVariable('zeroFloat', Cardinality::SINGLE, BaseType::FLOAT, new QtiFloat(0.0))); $state->setVariable(new OutcomeVariable('negativeFloat', Cardinality::SINGLE, BaseType::FLOAT, new QtiFloat(-53000.0))); $state->setVariable(new OutcomeVariable('false', Cardinality::SINGLE, BaseType::BOOLEAN, new QtiBoolean(false))); $state->setVariable(new OutcomeVariable('true', Cardinality::SINGLE, BaseType::BOOLEAN, new QtiBoolean(true))); $state->setVariable(new OutcomeVariable('URI', Cardinality::SINGLE, BaseType::URI, new QtiUri('http://qtism.taotesting.com'))); $state->setVariable(new TemplateVariable('zeroIntOrIdentifier', Cardinality::SINGLE, BaseType::INT_OR_IDENTIFIER, new QtiIntOrIdentifier(0))); $state->setVariable(new TemplateVariable('positiveIntOrIdentifier', Cardinality::SINGLE, BaseType::INT_OR_IDENTIFIER, new QtiIntOrIdentifier(25))); $state->setVariable(new TemplateVariable('zeroIntOrIdentifier', Cardinality::SINGLE, BaseType::INT_OR_IDENTIFIER, new QtiIntOrIdentifier(0))); $state->setVariable(new OutcomeVariable('identifierIntOrIdentifier', Cardinality::SINGLE, BaseType::INT_OR_IDENTIFIER, new QtiIntOrIdentifier('woot'))); $state->setVariable(new TemplateVariable('negativeIntOrIdentifier', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(-25))); $state->setVariable(new OutcomeVariable('duration', Cardinality::SINGLE, BaseType::DURATION, new QtiDuration('PT3M26S'))); $state->setVariable(new OutcomeVariable('pair', Cardinality::SINGLE, BaseType::PAIR, new QtiPair('A', 'B'))); $state->setVariable(new OutcomeVariable('directedPair', Cardinality::SINGLE, BaseType::DIRECTED_PAIR, new QtiDirectedPair('B', 'C'))); $state->setVariable(new OutcomeVariable('identifier', Cardinality::SINGLE, BaseType::IDENTIFIER, new QtiIdentifier('woot'))); // -- Multiple containers. $state->setVariable(new TemplateVariable('multipleIntegerSingle', Cardinality::MULTIPLE, BaseType::INTEGER, new MultipleContainer(BaseType::INTEGER, array(new QtiInteger(10))))); $state->setVariable(new TemplateVariable('multipleInteger', Cardinality::MULTIPLE, BaseType::INTEGER, new MultipleContainer(BaseType::INTEGER, array(new QtiInteger(10), new QtiInteger(20), new QtiInteger(-1))))); $state->setVariable(new OutcomeVariable('multipleFloat', Cardinality::MULTIPLE, BaseType::FLOAT, new MultipleContainer(BaseType::FLOAT, array(new QtiFloat(10.0), new QtiFloat(20.0), new QtiFloat(-1.0))))); $state->setVariable(new OutcomeVariable('multipleString', Cardinality::MULTIPLE, BaseType::STRING, new MultipleContainer(BaseType::STRING, array(new QtiString('Ta'), new QtiString('Daaa'), new QtiString('h'), new QtiString(''))))); $state->setVariable(new OutcomeVariable('multipleBoolean', Cardinality::MULTIPLE, BaseType::BOOLEAN, new MultipleContainer(BaseType::BOOLEAN, array(new QtiBoolean(true), new QtiBoolean(false), new QtiBoolean(true), new QtiBoolean(true))))); $state->setVariable(new OutcomeVariable('multipleURI', Cardinality::MULTIPLE, BaseType::URI, new MultipleContainer(BaseType::URI, array(new QtiUri('http://www.taotesting.com'), new QtiUri('http://www.rdfabout.com'))))); $state->setVariable(new OutcomeVariable('multipleIdentifier', Cardinality::MULTIPLE, BaseType::IDENTIFIER, new MultipleContainer(BaseType::IDENTIFIER, array(new QtiIdentifier('9thing'), new QtiIdentifier('woot-woot'))))); $state->setVariable(new TemplateVariable('multipleDuration', Cardinality::MULTIPLE, BaseType::DURATION, new MultipleContainer(BaseType::DURATION, array(new QtiDuration('PT0S'), new QtiDuration('PT3M'))))); $state->setVariable(new OutcomeVariable('multiplePair', Cardinality::MULTIPLE, BaseType::PAIR, new MultipleContainer(BaseType::PAIR, array(new QtiPair('A', 'B'), new QtiPair('C', 'D'), new QtiPair('E', 'F'))))); $state->setVariable(new OutcomeVariable('multipleDirectedPair', Cardinality::MULTIPLE, BaseType::DIRECTED_PAIR, new MultipleContainer(BaseType::DIRECTED_PAIR, array(new QtiDirectedPair('A', 'B'), new QtiDirectedPair('C', 'D'), new QtiDirectedPair('E', 'F'))))); $state->setVariable(new OutcomeVariable('multipleIntOrIdentifier', Cardinality::MULTIPLE, BaseType::INT_OR_IDENTIFIER, new MultipleContainer(BaseType::INT_OR_IDENTIFIER, array(new QtiIntOrIdentifier('woot'), new QtiIntOrIdentifier(25), new QtiIntOrIdentifier(0), new QtiIntOrIdentifier(-25))))); $state->setVariable(new OutcomeVariable('multipleEmpty', Cardinality::MULTIPLE, BaseType::INTEGER, new MultipleContainer(BaseType::INTEGER))); $state->setVariable(new TemplateVariable('multipleContainsNull', Cardinality::MULTIPLE, BaseType::INTEGER, new MultipleContainer(BaseType::INTEGER, array(new QtiInteger(-10), null, null)))); // -- Ordered containers, no value for the 'index' attribute. $state->setVariable(new TemplateVariable('orderedInteger', Cardinality::ORDERED, BaseType::INTEGER, new OrderedContainer(BaseType::INTEGER, array(new QtiInteger(10), new QtiInteger(20), new QtiInteger(-1))))); $state->setVariable(new OutcomeVariable('orderedFloat', Cardinality::ORDERED, BaseType::FLOAT, new OrderedContainer(BaseType::FLOAT, array(new QtiFloat(10.0), new QtiFloat(20.0), new QtiFloat(-1.0))))); $state->setVariable(new OutcomeVariable('orderedString', Cardinality::ORDERED, BaseType::STRING, new OrderedContainer(BaseType::STRING, array(new QtiString('Ta'), new QtiString('Daaa'), new QtiString('h'), new QtiString(''))))); $state->setVariable(new OutcomeVariable('orderedBoolean', Cardinality::ORDERED, BaseType::BOOLEAN, new OrderedContainer(BaseType::BOOLEAN, array(new QtiBoolean(true), new QtiBoolean(false), new QtiBoolean(true), new QtiBoolean(true))))); $state->setVariable(new OutcomeVariable('orderedURI', Cardinality::ORDERED, BaseType::URI, new OrderedContainer(BaseType::URI, array(new QtiUri('http://www.taotesting.com'), new QtiUri('http://www.rdfabout.com'))))); $state->setVariable(new OutcomeVariable('orderedIdentifier', Cardinality::ORDERED, BaseType::IDENTIFIER, new OrderedContainer(BaseType::IDENTIFIER, array(new QtiIdentifier('9thing'), new QtiIdentifier('woot-woot'))))); $state->setVariable(new TemplateVariable('orderedDuration', Cardinality::ORDERED, BaseType::DURATION, new OrderedContainer(BaseType::DURATION, array(new QtiDuration('PT0S'), new QtiDuration('PT3M'))))); $state->setVariable(new OutcomeVariable('orderedPair', Cardinality::ORDERED, BaseType::PAIR, new OrderedContainer(BaseType::PAIR, array(new QtiPair('A', 'B'), new QtiPair('C', 'D'), new QtiPair('E', 'F'))))); $state->setVariable(new OutcomeVariable('orderedDirectedPair', Cardinality::ORDERED, BaseType::DIRECTED_PAIR, new OrderedContainer(BaseType::DIRECTED_PAIR, array(new QtiDirectedPair('A', 'B'), new QtiDirectedPair('C', 'D'), new QtiDirectedPair('E', 'F'))))); $state->setVariable(new OutcomeVariable('orderedIntOrIdentifier', Cardinality::ORDERED, BaseType::INT_OR_IDENTIFIER, new OrderedContainer(BaseType::INT_OR_IDENTIFIER, array(new QtiIntOrIdentifier('woot'), new QtiIntOrIdentifier(25), new QtiIntOrIdentifier(0), new QtiIntOrIdentifier(-25))))); $state->setVariable(new TemplateVariable('orderedEmpty', Cardinality::ORDERED, BaseType::INTEGER, new OrderedContainer(BaseType::INTEGER))); $state->setVariable(new TemplateVariable('orderedContainsNull', Cardinality::ORDERED, BaseType::INTEGER, new OrderedContainer(BaseType::INTEGER, array(null, null, new QtiInteger(10))))); // -- Ordered containers, value for the 'index' attribute set. $state->setVariable(new TemplateVariable('orderedIndexedInteger', Cardinality::ORDERED, BaseType::INTEGER, new OrderedContainer(BaseType::INTEGER, array(new QtiInteger(10), new QtiInteger(20), new QtiInteger(-1))))); // The field is extracted from a variable ref. $state->setVariable(new OutcomeVariable('fieldVariableRefInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(1))); // Set up a wrong variable reference for 'index' value. $state->setVariable(new OutcomeVariable('fieldVariableRefString', Cardinality::SINGLE, BaseType::STRING, new QtiString('index'))); $state->setVariable(new OutcomeVariable('orderedIndexedFloat', Cardinality::ORDERED, BaseType::FLOAT, new OrderedContainer(BaseType::FLOAT, array(new QtiFloat(10.0), new QtiFloat(20.0), new QtiFloat(-1.0))))); $state->setVariable(new OutcomeVariable('orderedIndexedString', Cardinality::ORDERED, BaseType::STRING, new OrderedContainer(BaseType::STRING, array(new QtiString('Ta'), new QtiString('Daaa'), new QtiString('h'), new QtiString(''))))); $state->setVariable(new OutcomeVariable('orderedIndexedBoolean', Cardinality::ORDERED, BaseType::BOOLEAN, new OrderedContainer(BaseType::BOOLEAN, array(new QtiBoolean(true), new QtiBoolean(false), new QtiBoolean(true), new QtiBoolean(true))))); $state->setVariable(new OutcomeVariable('orderedIndexedURI', Cardinality::ORDERED, BaseType::URI, new OrderedContainer(BaseType::URI, array(new QtiUri('http://www.taotesting.com'), new QtiUri('http://www.rdfabout.com'))))); $state->setVariable(new OutcomeVariable('orderedIndexedIdentifier', Cardinality::ORDERED, BaseType::IDENTIFIER, new OrderedContainer(BaseType::IDENTIFIER, array(new QtiIdentifier('9thing'), new QtiIdentifier('woot-woot'))))); $state->setVariable(new TemplateVariable('orderedIndexedDuration', Cardinality::ORDERED, BaseType::DURATION, new OrderedContainer(BaseType::DURATION, array(new QtiDuration('PT0S'), new QtiDuration('PT3M'))))); $state->setVariable(new OutcomeVariable('orderedIndexedPair', Cardinality::ORDERED, BaseType::PAIR, new OrderedContainer(BaseType::PAIR, array(new QtiPair('A', 'B'), new QtiPair('C', 'D'), new QtiPair('E', 'F'))))); $state->setVariable(new OutcomeVariable('orderedIndexedDirectedPair', Cardinality::ORDERED, BaseType::DIRECTED_PAIR, new OrderedContainer(BaseType::DIRECTED_PAIR, array(new QtiDirectedPair('A', 'B'), new QtiDirectedPair('C', 'D'), new QtiDirectedPair('E', 'F'))))); $state->setVariable(new OutcomeVariable('orderedIndexedIntOrIdentifier', Cardinality::ORDERED, BaseType::INT_OR_IDENTIFIER, new OrderedContainer(BaseType::INT_OR_IDENTIFIER, array(new QtiIntOrIdentifier('woot'), new QtiIntOrIdentifier(25), new QtiIntOrIdentifier(0), new QtiIntOrIdentifier(-25))))); // -- Record containers. $state->setVariable(new OutcomeVariable('recordSingle', Cardinality::RECORD, -1, new RecordContainer(array('a' => new QtiFloat(25.3))))); $state->setVariable(new OutcomeVariable('recordMultiple', Cardinality::RECORD, -1, new RecordContainer(array('a' => new QtiInteger(-3), 'b' => new QtiFloat(3.3), 'c' => new QtiBoolean(true), 'd' => new QtiBoolean(false), 'e' => new QtiString('string'), 'f' => new QtiUri('http://www.rdfabout.com'), 'g' => new QtiDuration('PT3M'), 'h' => new QtiPair('A', 'B'), 'i' => new QtiDirectedPair('C', 'D'))))); $state->setVariable(new TemplateVariable('recordEmpty', Cardinality::RECORD, -1, new RecordContainer())); $state->setVariable(new OutcomeVariable('recordContainsNull', Cardinality::RECORD, -1, new RecordContainer(array('a' => new QtiInteger(-3), 'b' => null, 'c' => new QtiBoolean(true))))); // -- Power form. $state->setVariable(new OutcomeVariable('powerFormScalarPositiveInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(250))); $state->setVariable(new OutcomeVariable('powerFormScalarZeroInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(0))); $state->setVariable(new OutcomeVariable('powerFormScalarNegativeInteger', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(-23))); $state->setVariable(new OutcomeVariable('powerFormScalarPositiveFloat', Cardinality::SINGLE, BaseType::FLOAT, new QtiFloat(250.35))); $state->setVariable(new OutcomeVariable('powerFormScalarZeroFloat', Cardinality::SINGLE, BaseType::FLOAT, new QtiFloat(0.0))); $state->setVariable(new OutcomeVariable('powerFormScalarNegativeFloat', Cardinality::SINGLE, BaseType::FLOAT, new QtiFloat(-23.0))); // -- IMS NumberFormatting. See http://www.imsglobal.org/question/qtiv2p1/imsqti_implv2p1.html#section10017 $state->setVariable(new OutcomeVariable('integerMinus987', Cardinality::SINGLE, BaseType::INTEGER, new QtiInteger(-987))); return array(array('', 'nonExistingVariable', $state), array('', 'nullValue', $state), array('Non Empty String', 'nonEmptyString', $state), array('', 'emptyString', $state), array('25', 'positiveInteger', $state), array('0', 'zeroInteger', $state), array('-25', 'negativeInteger', $state), array('2.534553e+1', 'positiveFloat', $state), array('0.000000e+0', 'zeroFloat', $state), array('-5.300000e+4', 'negativeFloat', $state), array('false', 'false', $state), array('true', 'true', $state), array('http://qtism.taotesting.com', 'URI', $state), array('25', 'positiveIntOrIdentifier', $state), array('0', 'zeroIntOrIdentifier', $state), array('-25', 'negativeIntOrIdentifier', $state), array('woot', 'identifierIntOrIdentifier', $state), array('206', 'duration', $state), array('A B', 'pair', $state), array('B C', 'directedPair', $state), array('woot', 'identifier', $state), array('10', 'multipleIntegerSingle', $state), array('10;20;-1', 'multipleInteger', $state), array('1.000000e+1;2.000000e+1;-1.000000e+0', 'multipleFloat', $state), array('Ta;Daaa;h;', 'multipleString', $state), array('true;false;true;true', 'multipleBoolean', $state), array('http://www.taotesting.com;http://www.rdfabout.com', 'multipleURI', $state), array('9thing;woot-woot', 'multipleIdentifier', $state), array('0;180', 'multipleDuration', $state), array('A B;C D;E F', 'multiplePair', $state), array('woot;25;0;-25', 'multipleIntOrIdentifier', $state), array('', 'multipleEmpty', $state), array('-10;null;null', 'multipleContainsNull', $state), array('10;20;-1', 'orderedInteger', $state), array('1.000000e+1;2.000000e+1;-1.000000e+0', 'orderedFloat', $state), array('Ta;Daaa;h;', 'orderedString', $state), array('true;false;true;true', 'orderedBoolean', $state), array('http://www.taotesting.com;http://www.rdfabout.com', 'orderedURI', $state), array('9thing;woot-woot', 'orderedIdentifier', $state), array('0;180', 'orderedDuration', $state), array('A B;C D;E F', 'orderedPair', $state), array('woot;25;0;-25', 'orderedIntOrIdentifier', $state), array('null;null;10', 'orderedContainsNull', $state), array('10', 'orderedIndexedInteger', $state, '', false, 10, 0), array('20', 'orderedIndexedInteger', $state, '', false, 10, 1), array('-1', 'orderedIndexedInteger', $state, '', false, 10, 2), array('10;20;-1', 'orderedIndexedInteger', $state, '', false, 10, 3), array('20', 'orderedIndexedInteger', $state, '', false, 10, 'fieldVariableRefInteger'), array('10;20;-1', 'orderedIndexedInteger', $state, '', false, 10, 'XRef'), array('10;20;-1', 'orderedIndexedInteger', $state, '', false, 10, 'fieldVariableRefString'), array('1.000000e+1', 'orderedIndexedFloat', $state, '', false, 10, 0), array('2.000000e+1', 'orderedIndexedFloat', $state, '', false, 10, 1), array('-1.000000e+0', 'orderedIndexedFloat', $state, '', false, 10, 2), array('Ta', 'orderedIndexedString', $state, '', false, 10, 0), array('Daaa', 'orderedIndexedString', $state, '', false, 10, 1), array('h', 'orderedIndexedString', $state, '', false, 10, 2), array('', 'orderedIndexedString', $state, '', false, 10, 3), array('true', 'orderedIndexedBoolean', $state, '', false, 10, 0), array('false', 'orderedIndexedBoolean', $state, '', false, 10, 1), array('true', 'orderedIndexedBoolean', $state, '', false, 10, 2), array('true', 'orderedIndexedBoolean', $state, '', false, 10, 3), array('http://www.taotesting.com', 'orderedIndexedURI', $state, '', false, 10, 0), array('http://www.rdfabout.com', 'orderedIndexedURI', $state, '', false, 10, 1), array('9thing', 'orderedIndexedIdentifier', $state, '', false, 10, 0), array('woot-woot', 'orderedIndexedIdentifier', $state, '', false, 10, 1), array('0', 'orderedIndexedDuration', $state, '', false, 10, 0), array('180', 'orderedIndexedDuration', $state, '', false, 10, 1), array('A B', 'orderedIndexedPair', $state, '', false, 10, 0), array('C D', 'orderedIndexedPair', $state, '', false, 10, 1), array('E F', 'orderedIndexedPair', $state, '', false, 10, 2), array('A B', 'orderedIndexedDirectedPair', $state, '', false, 10, 0), array('C D', 'orderedIndexedDirectedPair', $state, '', false, 10, 1), array('E F', 'orderedIndexedDirectedPair', $state, '', false, 10, 2), array('woot', 'orderedIndexedIntOrIdentifier', $state, '', false, 10, 0), array('25', 'orderedIndexedIntOrIdentifier', $state, '', false, 10, 1), array('0', 'orderedIndexedIntOrIdentifier', $state, '', false, 10, 2), array('-25', 'orderedIndexedIntOrIdentifier', $state, '', false, 10, 3), array('250', 'powerFormScalarPositiveInteger', $state, '', true), array('0', 'powerFormScalarZeroInteger', $state, '', true), array('-23', 'powerFormScalarNegativeInteger', $state, '', true), array('2.503500 x 10²', 'powerFormScalarPositiveFloat', $state, '', true), array('0.000000 x 10⁰', 'powerFormScalarZeroFloat', $state, '', true), array('-2.300000 x 10¹', 'powerFormScalarNegativeFloat', $state, '', true), array('a=2.530000e+1', 'recordSingle', $state), array('a=-3;b=3.300000e+0;c=true;d=false;e=string;f=http://www.rdfabout.com;g=180;h=A B;i=C D', 'recordMultiple', $state), array('', 'recordEmpty', $state), array('a=-3;b=null;c=true', 'recordContainsNull', $state), array('bla', 'positiveInteger', $state, 'bla'), array(' yeah', 'positiveInteger', $state, '%-P yeah'), array('25', 'positiveInteger', $state, '%s'), array('Integer as string:25', 'positiveInteger', $state, 'Integer as string:%s'), array('Preceding with zeros: 0000000025', 'positiveInteger', $state, 'Preceding with zeros: %010d'), array('Preceding with zeros (signed): +000000025', 'positiveInteger', $state, 'Preceding with zeros (signed): %+010i'), array('Preceding with blanks: 25', 'positiveInteger', $state, 'Preceding with blanks: %10d'), array('31', 'positiveInteger', $state, '%#o'), array('31', 'positiveFloat', $state, '%+o'), array('-987', 'integerMinus987', $state, '%i')); }
/** * Action called when a QTI Item embedded in a QTI Test submit responses. * */ public function storeItemVariableSet() { if ($this->beforeAction()) { // --- Deal with provided responses. $jsonPayload = taoQtiCommon_helpers_Utils::readJsonPayload(); $responses = new State(); $currentItem = $this->getTestSession()->getCurrentAssessmentItemRef(); $currentOccurence = $this->getTestSession()->getCurrentAssessmentItemRefOccurence(); if ($currentItem === false) { $msg = "Trying to store item variables but the state of the test session is INITIAL or CLOSED.\n"; $msg .= "Session state value: " . $this->getTestSession()->getState() . "\n"; $msg .= "Session ID: " . $this->getTestSession()->getSessionId() . "\n"; $msg .= "JSON Payload: " . mb_substr(json_encode($jsonPayload), 0, 1000); common_Logger::e($msg); } $filler = new taoQtiCommon_helpers_PciVariableFiller($currentItem); if (is_array($jsonPayload)) { foreach ($jsonPayload as $id => $response) { try { $var = $filler->fill($id, $response); // Do not take into account QTI File placeholders. if (taoQtiCommon_helpers_Utils::isQtiFilePlaceHolder($var) === false) { $responses->setVariable($var); } } catch (OutOfRangeException $e) { common_Logger::d("Could not convert client-side value for variable '{$id}'."); } catch (OutOfBoundsException $e) { common_Logger::d("Could not find variable with identifier '{$id}' in current item."); } } } else { common_Logger::e('Invalid json payload'); } $displayFeedback = $this->getTestSession()->getCurrentSubmissionMode() !== SubmissionMode::SIMULTANEOUS; $stateOutput = new taoQtiCommon_helpers_PciStateOutput(); try { common_Logger::i('Responses sent from the client-side. The Response Processing will take place.'); $this->getTestSession()->endAttempt($responses, true); // Return the item session state to the client side. $itemSession = $this->getTestSession()->getAssessmentItemSessionStore()->getAssessmentItemSession($currentItem, $currentOccurence); foreach ($itemSession->getAllVariables() as $var) { $stateOutput->addVariable($var); } $itemCompilationDirectory = $this->getDirectory($this->getRequestParameter('itemDataPath')); $jsonReturn = array('success' => true, 'displayFeedback' => $displayFeedback, 'itemSession' => $stateOutput->getOutput(), 'feedbacks' => array()); if ($displayFeedback === true) { $jsonReturn['feedbacks'] = QtiRunner::getFeedbacks($itemCompilationDirectory, $itemSession); } echo json_encode($jsonReturn); } catch (AssessmentTestSessionException $e) { $this->handleAssessmentTestSessionException($e); } $this->afterAction(false); } }
public function marshallStateProvider() { $returnValue = array(); // empty state. $state = new State(); $json = json_encode(array()); $returnValue[] = array($state, $json); // simple state. $state = new State(array(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA')))); $json = json_encode(array('RESPONSE' => array('base' => array('identifier' => 'ChoiceA')))); $returnValue[] = array($state, $json); // complex state 1. $state = new State(); $state->setVariable(new ResponseVariable('RESPONSE1', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA'))); $state->setVariable(new ResponseVariable('RESPONSE2', Cardinality::SINGLE, BaseType::DURATION)); $state->setVariable(new ResponseVariable('RESPONSE3', Cardinality::RECORD, -1, new RecordContainer(array('A' => new Identifier('A'), 'B' => new Identifier('B'))))); $json = json_encode(array('RESPONSE1' => array('base' => array('identifier' => 'ChoiceA')), 'RESPONSE2' => array('base' => null), 'RESPONSE3' => array('record' => array(array('name' => 'A', 'base' => array('identifier' => 'A')), array('name' => 'B', 'base' => array('identifier' => 'B')))))); $returnValue[] = array($state, $json); // complex state 2. $state = new State(); $state->setVariable(new OutcomeVariable('OUTCOME1', Cardinality::MULTIPLE, BaseType::FLOAT, new MultipleContainer(BaseType::FLOAT, array(new Float(0.0), new Float(10.1))))); $state->setVariable(new ResponseVariable('RESPONSE1', Cardinality::ORDERED, BaseType::POINT, new OrderedContainer(BaseType::POINT, array(new Point(10, 20))))); $json = json_encode(array('OUTCOME1' => array('list' => array('float' => array(0.0, 10.1))), 'RESPONSE1' => array('list' => array('point' => array(array(10, 20)))))); $returnValue[] = array($state, $json); return $returnValue; }
public function testNoSecondVariableRef() { $expression = $this->createFakeExpression(ToleranceMode::ABSOLUTE, array('t0', 't1')); $operands = new OperandsCollection(array(new Integer(10), new Float(9.9))); $processor = new EqualProcessor($expression, $operands); $state = new State(); $state->setVariable(new OutcomeVariable('t0', Cardinality::SINGLE, BaseType::FLOAT, new Float(0.1))); $processor->setState($state); $result = $processor->process(); $this->assertTrue($result->getValue()); $operands = new OperandsCollection(array(new Integer(10), new Float(9.800000000000001))); $processor->setOperands($operands); $result = $processor->process(); $this->assertFalse($result->getValue()); }
public function testMaxReferenceWrongBaseType() { $expression = $this->createFakeExpression(3, 'max'); $max = new OutcomeVariable('max', Cardinality::SINGLE, BaseType::FLOAT, new Float(4.5356)); $operands = new OperandsCollection(array(new Boolean(true), new Boolean(true), new Boolean(true), null)); $state = new State(); $state->setVariable($max); $processor = new AnyNProcessor($expression, $operands); $processor->setState($state); $this->setExpectedException('qtism\\runtime\\expressions\\ExpressionProcessingException'); $result = $processor->process(); }
public function testLinearAnswerAll() { $doc = new XmlCompactDocument(); $doc->load(self::samplesDir() . 'custom/runtime/scenario_basic_nonadaptive_linear_singlesection.xml'); $sessionManager = new SessionManager(); $assessmentTestSession = $sessionManager->createAssessmentTestSession($doc->getDocumentComponent()); $assessmentTestSession->beginTestSession(); // Q01 - Correct Response = 'ChoiceA'. $this->assertEquals('Q01', $assessmentTestSession->getCurrentAssessmentItemRef()->getIdentifier()); $this->assertFalse($assessmentTestSession->isCurrentAssessmentItemInteracting()); $assessmentTestSession->beginAttempt(); $this->assertTrue($assessmentTestSession->isCurrentAssessmentItemInteracting()); $responses = new State(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceA'))); $assessmentTestSession->endAttempt($responses); $assessmentTestSession->moveNext(); $this->assertFalse($assessmentTestSession->isCurrentAssessmentItemInteracting()); // Q02 - Correct Response = 'ChoiceB'. $this->assertEquals('Q02', $assessmentTestSession->getCurrentAssessmentItemRef()->getIdentifier()); $assessmentTestSession->beginAttempt(); $responses = new State(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceC'))); // -> incorrect x) $assessmentTestSession->endAttempt($responses); $assessmentTestSession->moveNext(); // Q03 - Correct Response = 'ChoiceC'. $this->assertEquals('Q03', $assessmentTestSession->getCurrentAssessmentItemRef()->getIdentifier()); $assessmentTestSession->beginAttempt(); $responses = new State(); $responses->setVariable(new ResponseVariable('RESPONSE', Cardinality::SINGLE, BaseType::IDENTIFIER, new Identifier('ChoiceC'))); $assessmentTestSession->endAttempt($responses); $assessmentTestSession->moveNext(); // Check the final state of the test session. // - Q01 $this->assertEquals('ChoiceA', $assessmentTestSession['Q01.RESPONSE']->getValue()); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $assessmentTestSession['Q01.SCORE']); $this->assertEquals(1.0, $assessmentTestSession['Q01.SCORE']->getValue()); $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $assessmentTestSession['Q01.numAttempts']); $this->assertEquals(1, $assessmentTestSession['Q01.numAttempts']->getValue()); // - Q02 $this->assertEquals('ChoiceC', $assessmentTestSession['Q02.RESPONSE']->getValue()); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $assessmentTestSession['Q02.SCORE']); $this->assertEquals(0.0, $assessmentTestSession['Q02.SCORE']->getValue()); $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $assessmentTestSession['Q02.numAttempts']); $this->assertEquals(1, $assessmentTestSession['Q02.numAttempts']->getValue()); // - Q03 $this->assertEquals('ChoiceC', $assessmentTestSession['Q03.RESPONSE']->getValue()); $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $assessmentTestSession['Q03.SCORE']); $this->assertEquals(1.0, $assessmentTestSession['Q03.SCORE']->getValue()); $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $assessmentTestSession['Q03.numAttempts']); $this->assertEquals(1, $assessmentTestSession['Q03.numAttempts']->getValue()); $this->assertEquals(AssessmentTestSessionState::CLOSED, $assessmentTestSession->getState()); }