Search in sources :

Example 6 with TemplateDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration in project openolat by klemens.

the class AssessmentItemChecker method checkSetCorrectResponse.

/**
 * responseDeclaration -> float
 *
 * templateVraiable -> integer
 *
 * setCorrectResponse
 *   -> variable -> integer doesn't match float -> issue
 * @param item
 * @return
 */
private static boolean checkSetCorrectResponse(AssessmentItem item) {
    boolean allOk = true;
    List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
    for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
        Identifier responseIdentifier = setCorrectResponse.getIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        BaseType baseType = responseDeclaration.getBaseType();
        Expression expression = setCorrectResponse.getExpression();
        if (expression instanceof Variable) {
            Variable variable = (Variable) expression;
            ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
            Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
            TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
            if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
                templateDeclaration.setBaseType(baseType);
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) SetCorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 7 with TemplateDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration in project openolat by klemens.

the class AssessmentItemCheckerTest method checkAndCorrect_hottextOpenOLAT.

@Test
public void checkAndCorrect_hottextOpenOLAT() throws URISyntaxException {
    URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/openolat/hottext-score-all-11-4-0.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    boolean ok = AssessmentItemChecker.checkAndCorrect(assessmentItem);
    Assert.assertTrue(ok);
    TemplateDeclaration templateDeclaration = assessmentItem.getTemplateDeclaration(Identifier.assumedLegal("SOLUTION1"));
    Assert.assertNull(templateDeclaration);
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) URL(java.net.URL) Test(org.junit.Test)

Example 8 with TemplateDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration in project openolat by klemens.

the class AssessmentItemCheckerTest method checkAndCorrect_wrongType.

@Test
public void checkAndCorrect_wrongType() throws URISyntaxException {
    URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/onyx/set-correct-response-wrong-type-5-11.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    boolean ok = AssessmentItemChecker.checkAndCorrect(assessmentItem);
    Assert.assertFalse(ok);
    TemplateDeclaration solutionDeclaration = assessmentItem.getTemplateDeclaration(Identifier.assumedLegal("solution"));
    Assert.assertEquals(BaseType.FLOAT, solutionDeclaration.getBaseType());
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) URL(java.net.URL) Test(org.junit.Test)

Example 9 with TemplateDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration in project openolat by klemens.

the class AssessmentItemCheckerTest method checkAndCorrect_rightType.

@Test
public void checkAndCorrect_rightType() throws URISyntaxException {
    URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/umpc/addition.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    boolean ok = AssessmentItemChecker.checkAndCorrect(assessmentItem);
    Assert.assertTrue(ok);
    TemplateDeclaration solutionDeclaration = assessmentItem.getTemplateDeclaration(Identifier.assumedLegal("SOLUTION1"));
    Assert.assertEquals(BaseType.FLOAT, solutionDeclaration.getBaseType());
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) URL(java.net.URL) Test(org.junit.Test)

Example 10 with TemplateDeclaration

use of uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration in project OpenOLAT by OpenOLAT.

the class AssessmentItemCheckerTest method checkAndCorrect_notTemplateDeclaration.

@Test
public void checkAndCorrect_notTemplateDeclaration() throws URISyntaxException {
    URL itemUrl = OnyxToAssessmentItemBuilderTest.class.getResource("resources/ims/template_image.xml");
    AssessmentItem assessmentItem = loadAssessmentItem(itemUrl);
    boolean ok = AssessmentItemChecker.checkAndCorrect(assessmentItem);
    Assert.assertTrue(ok);
    TemplateDeclaration templateDeclaration = assessmentItem.getTemplateDeclaration(Identifier.assumedLegal("SOLUTION1"));
    Assert.assertNull(templateDeclaration);
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) URL(java.net.URL) Test(org.junit.Test)

Aggregations

TemplateDeclaration (uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration)16 URL (java.net.URL)8 Test (org.junit.Test)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)8 OutcomeDeclaration (uk.ac.ed.ph.jqtiplus.node.outcome.declaration.OutcomeDeclaration)4 Value (uk.ac.ed.ph.jqtiplus.value.Value)4 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)2 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)2 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)2 SetCorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse)2 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)2 BaseType (uk.ac.ed.ph.jqtiplus.value.BaseType)2 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)2