Search in sources :

Example 76 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class TreeNamingServiceTest method statechartNamingBaseTest.

@Test
public void statechartNamingBaseTest() {
    Statechart toTest = getNamingServiceStatechart();
    List<String> names = new ArrayList<>();
    List<String> expectedNames = new ArrayList<>(Arrays.asList("main_region_StateA", "main_region_StateB", "second_region_StateA", "third_region_StateA", "second_region_StateA_AnotherRegion_StateA", "second_region_StateA_AnotherRegion_StateB", "third_region_StateA_AnotherRegion_StateA", "third_region_StateA_AnotherRegion_StateB"));
    ExecutionFlow flow = optimizer.transform(sequencer.transform(toTest));
    executionflowNamingService.setMaxLength(0);
    executionflowNamingService.setSeparator('_');
    executionflowNamingService.initializeNamingService(flow);
    statechartNamingService.setMaxLength(0);
    statechartNamingService.setSeparator('_');
    statechartNamingService.initializeNamingService(toTest);
    for (ExecutionState state : flow.getStates()) {
        String name = executionflowNamingService.getShortName(state);
        assertEquals(names.contains(name), false);
        assertEquals(name, statechartNamingService.getShortName(state));
        names.add(name);
    }
    stringListsEqual(expectedNames, names);
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) ArrayList(java.util.ArrayList) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test)

Example 77 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class TreeNamingServiceTest method testDefaultNamingServiceState_NoDoubles.

@Test
public void testDefaultNamingServiceState_NoDoubles() {
    for (Statechart statechart : statecharts) {
        // Transform statechart
        ExecutionFlow flow = sequencer.transform(statechart);
        flow = optimizer.transform(flow);
        List<String> names = new ArrayList<>();
        executionflowNamingService.setMaxLength(15);
        executionflowNamingService.setSeparator('_');
        // Initialize naming services for statechart and ExecutionFlow
        executionflowNamingService.initializeNamingService(flow);
        for (ExecutionState state : flow.getStates()) {
            String name = executionflowNamingService.getShortName(state);
            assertEquals(names.contains(name), false);
            names.add(name);
        }
    }
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ArrayList(java.util.ArrayList) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test)

Example 78 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class TreeNamingServiceTest method optimizerCombinationsTest.

@Test
public void optimizerCombinationsTest() {
    Statechart toTest = null;
    for (Statechart statechart : statecharts) {
        if (statechart.getName().equals("DeepEntry")) {
            toTest = statechart;
        }
    }
    assertEquals(true, toTest != null);
    ExecutionFlow flow = sequencer.transform(toTest);
    executionflowNamingService.setMaxLength(0);
    executionflowNamingService.setSeparator('_');
    for (int i = 0; i < (1 << 9); i++) {
        optimizer.inlineReactions((i & (1)) != 0);
        optimizer.inlineExitActions((i & (1 << 1)) != 0);
        optimizer.inlineEntryActions((i & (1 << 2)) != 0);
        optimizer.inlineEnterSequences((i & (1 << 3)) != 0);
        optimizer.inlineExitSequences((i & (1 << 4)) != 0);
        optimizer.inlineChoices((i & (1 << 5)) != 0);
        optimizer.inlineEntries((i & (1 << 6)) != 0);
        optimizer.inlineEnterRegion((i & (1 << 7)) != 0);
        optimizer.inlineExitRegion((i & (1 << 8)) != 0);
        ExecutionFlow optimizedflow = optimizer.transform(flow);
        List<String> names = new ArrayList<>();
        executionflowNamingService.initializeNamingService(optimizedflow);
        for (ExecutionState state : flow.getStates()) {
            String name = executionflowNamingService.getShortName(state);
            assertEquals(names.contains(name), false);
            names.add(name);
        }
    }
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ArrayList(java.util.ArrayList) Statechart(org.yakindu.sct.model.sgraph.Statechart) Test(org.junit.Test)

Example 79 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class TreeNamingServiceTest method nameLengthTest.

private void nameLengthTest(int maxLength) {
    int num_statecharts = statecharts.size();
    long cumulated_time = 0L;
    for (Statechart statechart : statecharts) {
        // Transform statechart
        ExecutionFlow flow = sequencer.transform(statechart);
        flow = optimizer.transform(flow);
        List<String> names = new ArrayList<>();
        executionflowNamingService.setMaxLength(maxLength);
        executionflowNamingService.setSeparator('_');
        long t0 = System.currentTimeMillis();
        executionflowNamingService.initializeNamingService(flow);
        cumulated_time += System.currentTimeMillis() - t0;
        for (ExecutionState state : flow.getStates()) {
            String name = executionflowNamingService.getShortName(state);
            assertEquals(names.contains(name), false);
            assertEquals(true, name.length() <= maxLength);
            names.add(name);
        }
    }
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) ArrayList(java.util.ArrayList) Statechart(org.yakindu.sct.model.sgraph.Statechart)

Example 80 with Statechart

use of org.yakindu.sct.model.sgraph.Statechart in project statecharts by Yakindu.

the class TreeNamingServiceTest method getNamingServiceStatechart.

private Statechart getNamingServiceStatechart() {
    Statechart toTest = null;
    for (Statechart statechart : statecharts) {
        if (statechart.getName().equals("namingTest")) {
            toTest = statechart;
        }
    }
    assertEquals(true, toTest != null);
    return toTest;
}
Also used : Statechart(org.yakindu.sct.model.sgraph.Statechart)

Aggregations

Statechart (org.yakindu.sct.model.sgraph.Statechart)132 Test (org.junit.Test)89 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)65 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)63 Region (org.yakindu.sct.model.sgraph.Region)59 State (org.yakindu.sct.model.sgraph.State)59 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)57 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)57 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)51 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)48 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)48 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)47 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)47 Sequence (org.yakindu.sct.model.sexec.Sequence)40 Entry (org.yakindu.sct.model.sgraph.Entry)30 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 Reaction (org.yakindu.sct.model.sexec.Reaction)25 Scope (org.yakindu.sct.model.sgraph.Scope)25 EnterState (org.yakindu.sct.model.sexec.EnterState)21