Search in sources :

Example 6 with IntegerValue

use of uk.ac.ed.ph.jqtiplus.value.IntegerValue in project openolat by klemens.

the class AssessmentRenderFunctionsTest method valueContains_multipleAlienValues.

@Test
public void valueContains_multipleAlienValues() {
    Value identifierValues = MultipleValue.createMultipleValue(new IntegerValue(6), new IntegerValue(7));
    Assert.assertFalse(AssessmentRenderFunctions.valueContains(identifierValues, Identifier.parseString("6")));
    Assert.assertFalse(AssessmentRenderFunctions.valueContains(identifierValues, Identifier.parseString("noid")));
}
Also used : IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) Test(org.junit.Test)

Example 7 with IntegerValue

use of uk.ac.ed.ph.jqtiplus.value.IntegerValue in project openolat by klemens.

the class AssessmentRenderFunctionsTest method valueContains_orderedAlienValues.

@Test
public void valueContains_orderedAlienValues() {
    Value identifierValues = OrderedValue.createOrderedValue(new IntegerValue(6), new IntegerValue(7));
    Assert.assertFalse(AssessmentRenderFunctions.valueContains(identifierValues, Identifier.parseString("7")));
    Assert.assertFalse(AssessmentRenderFunctions.valueContains(identifierValues, Identifier.parseString("noid")));
}
Also used : IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) NullValue(uk.ac.ed.ph.jqtiplus.value.NullValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) Test(org.junit.Test)

Example 8 with IntegerValue

use of uk.ac.ed.ph.jqtiplus.value.IntegerValue in project openolat by klemens.

the class CorrectResponsesUtil method getCorrectIntegerResponses.

public static final List<Integer> getCorrectIntegerResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Integer> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IntegerValue) {
                IntegerValue identifierValue = (IntegerValue) value;
                correctAnswers.add(identifierValue.intValue());
            }
        } else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                for (SingleValue sValue : multiValue.getAll()) {
                    if (sValue instanceof IntegerValue) {
                        IntegerValue identifierValue = (IntegerValue) value;
                        correctAnswers.add(identifierValue.intValue());
                    }
                }
            }
        }
    }
    return correctAnswers;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 9 with IntegerValue

use of uk.ac.ed.ph.jqtiplus.value.IntegerValue in project OpenOLAT by OpenOLAT.

the class CorrectResponsesUtil method getCorrectIntegerResponses.

public static final List<Integer> getCorrectIntegerResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Integer> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.SINGLE)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.SINGLE, values);
            if (value instanceof IntegerValue) {
                IntegerValue identifierValue = (IntegerValue) value;
                correctAnswers.add(identifierValue.intValue());
            }
        } else if (correctResponse.getCardinality().isOneOf(Cardinality.MULTIPLE)) {
            Value value = FieldValue.computeValue(Cardinality.MULTIPLE, correctResponse.getFieldValues());
            if (value instanceof MultipleValue) {
                MultipleValue multiValue = (MultipleValue) value;
                for (SingleValue sValue : multiValue.getAll()) {
                    if (sValue instanceof IntegerValue) {
                        IntegerValue identifierValue = (IntegerValue) value;
                        correctAnswers.add(identifierValue.intValue());
                    }
                }
            }
        }
    }
    return correctAnswers;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 10 with IntegerValue

use of uk.ac.ed.ph.jqtiplus.value.IntegerValue in project OpenOLAT by OpenOLAT.

the class AssessmentItemFactory method appendVariableBaseValue.

/*
		<variable identifier="SCORE" />
		<baseValue baseType="float">4</baseValue>
	 */
/**
 * @param var
 * @param value
 * @param responseIdentifier
 * @param parentExpression
 * @param reverse if true, reverse the order, first baseValue and then variable
 */
private static void appendVariableBaseValue(ModalFeedbackCondition.Variable var, String value, Identifier responseIdentifier, Expression parentExpression, boolean reverse) {
    Variable variable = new Variable(parentExpression);
    BaseValue bValue = new BaseValue(parentExpression);
    if (reverse) {
        parentExpression.getExpressions().add(bValue);
        parentExpression.getExpressions().add(variable);
    } else {
        parentExpression.getExpressions().add(variable);
        parentExpression.getExpressions().add(bValue);
    }
    switch(var) {
        case score:
            bValue.setBaseTypeAttrValue(BaseType.FLOAT);
            bValue.setSingleValue(new FloatValue(Double.parseDouble(value)));
            variable.setIdentifier(QTI21Constants.SCORE_CLX_IDENTIFIER);
            break;
        case attempts:
            bValue.setBaseTypeAttrValue(BaseType.INTEGER);
            bValue.setSingleValue(new IntegerValue(Integer.parseInt(value)));
            variable.setIdentifier(QTI21Constants.NUM_ATTEMPTS_CLX_IDENTIFIER);
            break;
        case response:
            bValue.setBaseTypeAttrValue(BaseType.IDENTIFIER);
            bValue.setSingleValue(new IdentifierValue(Identifier.parseString(value)));
            variable.setIdentifier(ComplexReferenceIdentifier.parseString(responseIdentifier.toString()));
            break;
    }
}
Also used : Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseValue(uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue)

Aggregations

IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)10 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)8 Value (uk.ac.ed.ph.jqtiplus.value.Value)8 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)6 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)6 Test (org.junit.Test)4 FloatValue (uk.ac.ed.ph.jqtiplus.value.FloatValue)4 NullValue (uk.ac.ed.ph.jqtiplus.value.NullValue)4 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)2 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)2 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)2 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)2 ItemVariable (uk.ac.ed.ph.jqtiplus.node.result.ItemVariable)2 OutcomeVariable (uk.ac.ed.ph.jqtiplus.node.result.OutcomeVariable)2 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)2 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)2 BooleanValue (uk.ac.ed.ph.jqtiplus.value.BooleanValue)2