Search in sources :

Example 6 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method testIsNotInUserPropertyFunction.

@Test
public void testIsNotInUserPropertyFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "isNotInUserProperty(\"firstName\", \"stcondit\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isNotInUserProperty(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isNotInUserProperty(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isNotInUserProperty(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "isNotInUserProperty(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isNotInUserProperty(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isNotInUserProperty(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "isNotInUserProperty(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 7 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method testUserPropertyStartswithFunction.

@Test
public void testUserPropertyStartswithFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "userPropertyStartswith(\"firstName\", \"firs\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyStartswith(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 8 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class ConditionTest method testUserPropertyEndswithFunction.

@Test
public void testUserPropertyEndswithFunction() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "userPropertyEndswith(\"firstName\", \"ondition\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(condition, result);
    condition = "userPropertyEndswith(\"firstName\", \"\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyEndswith(\"firstName\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyEndswith(\"firstName\", \"firstcondition\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyEndswith(\"firstName\", \"someThing\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyEndswith(\"firstName\", \"firstconditiongugus\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyEndswith(\"firstName\", \"gugusfirstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
    condition = "userPropertyEndswith(\"lastName\", \"firstcondition\")";
    result = interpreter.evaluateCondition(condition);
    Assert.assertFalse(condition, result);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Example 9 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project openolat by klemens.

the class STCourseNode method getUserScoreEvaluation.

/**
 * the structure node does not have a score itself, but calculates the
 * score/passed info by evaluating the configured expression in the the
 * (condition)interpreter.
 *
 * @see org.olat.course.nodes.AssessableCourseNode#getUserScoreEvaluation(org.olat.course.run.userview.UserCourseEnvironment)
 */
@Override
public AssessmentEvaluation getUserScoreEvaluation(UserCourseEnvironment userCourseEnv) {
    Float score = null;
    Boolean passed = null;
    if (scoreCalculator == null) {
        // this is a not-computable course node at the moment (no scoring/passing rules defined)
        return null;
    }
    String scoreExpressionStr = scoreCalculator.getScoreExpression();
    String passedExpressionStr = scoreCalculator.getPassedExpression();
    ConditionInterpreter ci = userCourseEnv.getConditionInterpreter();
    if (scoreExpressionStr != null) {
        score = new Float(ci.evaluateCalculation(scoreExpressionStr));
    }
    if (passedExpressionStr != null) {
        passed = new Boolean(ci.evaluateCondition(passedExpressionStr));
    }
    return new AssessmentEvaluation(score, passed);
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) AssessmentEvaluation(org.olat.course.run.scoring.AssessmentEvaluation)

Example 10 with ConditionInterpreter

use of org.olat.course.condition.interpreter.ConditionInterpreter in project OpenOLAT by OpenOLAT.

the class ConditionTest method simpleExpresion.

@Test
public void simpleExpresion() throws Exception {
    UserCourseEnvironment uce = getUserDemoCourseEnvironment();
    ConditionInterpreter interpreter = new ConditionInterpreter(uce);
    String condition = "now >= date(\"03.07.2012 08:26\")";
    boolean result = interpreter.evaluateCondition(condition);
    Assert.assertTrue(result);
    Collection<Object> tokens = interpreter.getParsedTokens(condition);
    Assert.assertNotNull(tokens);
    Assert.assertFalse(tokens.isEmpty());
}
Also used : ConditionInterpreter(org.olat.course.condition.interpreter.ConditionInterpreter) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Test(org.junit.Test)

Aggregations

ConditionInterpreter (org.olat.course.condition.interpreter.ConditionInterpreter)22 Test (org.junit.Test)20 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)20 AssessmentEvaluation (org.olat.course.run.scoring.AssessmentEvaluation)2