Search in sources :

Example 1 with NumericalMultiplyDivideExpression

use of org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testSingleTransitionTimeTrigger.

/**
 * If a time trigger is defined for a transition then an event must be
 * introduced into the execution flow.
 */
@SuppressWarnings("unused")
@Test
public void testSingleTransitionTimeTrigger() {
    Statechart sc = _createStatechart("test");
    Scope scope = _createInterfaceScope("interface", sc);
    VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
    Region r = _createRegion("main", sc);
    State s = _createState("s", r);
    Transition t = _createTransition(s, s);
    ReactionTrigger tr1 = _createReactionTrigger(t);
    _createTimeEventSpec(TimeEventType.AFTER, _createValue(1), TimeUnit.SECOND, tr1);
    AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) t.getEffect());
    ExecutionFlow flow = sequencer.transform(sc);
    // assert definition of time event
    Scope timerScope = flow.getScopes().get(1);
    assertTrue(timerScope.getDeclarations().get(0) instanceof TimeEvent);
    TimeEvent te = (TimeEvent) timerScope.getDeclarations().get(0);
    // assert that the reaction check checks the time event
    assertEquals(1, flow.getStates().size());
    ExecutionState _s = flow.getStates().get(0);
    assertEquals(s.getName(), _s.getSimpleName());
    If _if = (If) SCTTestUtil.flattenSequenceStepsAsList(flow.getStates().get(0).getReactSequence()).get(0);
    ElementReferenceExpression _ere = (ElementReferenceExpression) _if.getCheck().getCondition();
    assertSame(te, _ere.getReference());
    // assert the scheduling of the time event during state entry
    assertNotNull(_s.getEntryAction());
    Sequence entryAction = (Sequence) _s.getEntryAction();
    ScheduleTimeEvent ste = (ScheduleTimeEvent) entryAction.getSteps().get(0);
    assertSame(te, ste.getTimeEvent());
    NumericalMultiplyDivideExpression multiply = (NumericalMultiplyDivideExpression) ste.getTimeValue();
    assertIntLiteral(1, ((PrimitiveValueExpression) multiply.getLeftOperand()).getValue());
    assertIntLiteral(1000, ((PrimitiveValueExpression) multiply.getRightOperand()).getValue());
    assertEquals(MultiplicativeOperator.MUL, multiply.getOperator());
    // assert the unscheduling of the time events during state exit
    assertNotNull(_s.getExitAction());
    Sequence exitAction = (Sequence) _s.getExitAction();
    UnscheduleTimeEvent ute = (UnscheduleTimeEvent) exitAction.getSteps().get(0);
    assertSame(te, ute.getTimeEvent());
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Sequence(org.yakindu.sct.model.sexec.Sequence) ScheduleTimeEvent(org.yakindu.sct.model.sexec.ScheduleTimeEvent) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) AssignmentExpression(org.yakindu.base.expressions.expressions.AssignmentExpression) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) SGraphTestFactory._createTransition(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition) UnscheduleTimeEvent(org.yakindu.sct.model.sexec.UnscheduleTimeEvent) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) TimeEvent(org.yakindu.sct.model.sexec.TimeEvent) UnscheduleTimeEvent(org.yakindu.sct.model.sexec.UnscheduleTimeEvent) ScheduleTimeEvent(org.yakindu.sct.model.sexec.ScheduleTimeEvent) If(org.yakindu.sct.model.sexec.If) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) Test(org.junit.Test)

Example 2 with NumericalMultiplyDivideExpression

use of org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression in project statecharts by Yakindu.

the class NumericalMultiplyDivideExpressionItemProvider method getText.

/**
 * This returns the label text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public String getText(Object object) {
    MultiplicativeOperator labelValue = ((NumericalMultiplyDivideExpression) object).getOperator();
    String label = labelValue == null ? null : labelValue.toString();
    return label == null || label.length() == 0 ? getString("_UI_NumericalMultiplyDivideExpression_type") : getString("_UI_NumericalMultiplyDivideExpression_type") + " " + label;
}
Also used : NumericalMultiplyDivideExpression(org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression) MultiplicativeOperator(org.yakindu.base.expressions.expressions.MultiplicativeOperator)

Aggregations

NumericalMultiplyDivideExpression (org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression)2 Test (org.junit.Test)1 AssignmentExpression (org.yakindu.base.expressions.expressions.AssignmentExpression)1 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 MultiplicativeOperator (org.yakindu.base.expressions.expressions.MultiplicativeOperator)1 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)1 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)1 If (org.yakindu.sct.model.sexec.If)1 ScheduleTimeEvent (org.yakindu.sct.model.sexec.ScheduleTimeEvent)1 Sequence (org.yakindu.sct.model.sexec.Sequence)1 TimeEvent (org.yakindu.sct.model.sexec.TimeEvent)1 UnscheduleTimeEvent (org.yakindu.sct.model.sexec.UnscheduleTimeEvent)1 Region (org.yakindu.sct.model.sgraph.Region)1 Scope (org.yakindu.sct.model.sgraph.Scope)1 State (org.yakindu.sct.model.sgraph.State)1 Statechart (org.yakindu.sct.model.sgraph.Statechart)1 Transition (org.yakindu.sct.model.sgraph.Transition)1 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)1 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)1 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)1