コード例 #1
0
    public function testWithRecord()
    {
        $expr = $this->createComponentFromXml('<mapResponsePoint identifier="response1"/>');
        $variableDeclaration = $this->createComponentFromXml('
			<responseDeclaration identifier="response1" cardinality="record">
	            <areaMapping lowerBound="1" upperBound="5">
					<areaMapEntry shape="rect" coords="0,0,20,10" mappedValue="4"/>
					<areaMapEntry shape="circle" coords="5,5,5" mappedValue="2"/>
				</areaMapping>
	        </responseDeclaration>
		');
        $variable = ResponseVariable::createFromDataModel($variableDeclaration);
        $processor = new MapResponsePointProcessor($expr);
        $processor->setState(new State(array($variable)));
        $this->setExpectedException('qtism\\runtime\\expressions\\ExpressionProcessingException', 'The MapResponsePoint expression cannot be applied to RECORD variables.', ExpressionProcessingException::WRONG_VARIABLE_CARDINALITY);
        $result = $processor->process();
    }
    public function testUpperBoundOverflow()
    {
        $expr = $this->createComponentFromXml('<mapResponsePoint identifier="response1"/>');
        $variableDeclaration = $this->createComponentFromXml('
			<responseDeclaration identifier="response1" baseType="point" cardinality="single">
				<areaMapping lowerBound="1" upperBound="5">
					<areaMapEntry shape="rect" coords="0,0,20,10" mappedValue="4"/>
					<areaMapEntry shape="circle" coords="5,5,5" mappedValue="2"/>
				</areaMapping>
			</responseDeclaration>
		');
        $variable = ResponseVariable::createFromDataModel($variableDeclaration);
        $processor = new MapResponsePointProcessor($expr);
        $variable->setValue(new Point(3, 3));
        // inside everything.
        $processor->setState(new State(array($variable)));
        $result = $processor->process();
        $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
        $this->assertEquals(5, $result->getValue());
    }