<commit_before>/*******************************************************************************
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0 which accompany this distribution.
*
* The Apache License is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
*******************************************************************************/
package org.openscore.lang.compiler.scorecompiler;

import org.openscore.lang.compiler.SlangTextualKeys;
import org.openscore.lang.entities.ForLoopStatement;
import org.openscore.lang.entities.ResultNavigation;
import org.openscore.lang.entities.ScoreLangConstants;
import org.openscore.lang.entities.bindings.Input;
import org.openscore.lang.entities.bindings.Output;
import org.openscore.lang.entities.bindings.Result;
import junit.framework.Assert;
import org.openscore.api.ExecutionStep;
import org.junit.Before;
import org.junit.Test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

public class ExecutionStepFactoryTest {

    private ExecutionStepFactory factory;

    @Before
    public void init() {
        factory = new ExecutionStepFactory();
    }

    @Test
    public void testCreateStartStep() throws Exception {
        ExecutionStep startStep = factory.createStartStep(1L, new HashMap<String, Serializable>(), new ArrayList<Input>(),"coolStep");
        Assert.assertNotNull("step should not be null", startStep);
        Assert.assertEquals("coolStep",startStep.getActionData().get(ScoreLangConstants.NODE_NAME_KEY));
    }

    @Test
    public void testCreateStartStepPutInputsUnderTheRightKey() throws Exception {
        ArrayList<Input> execInputs = new ArrayList<>();
        ExecutionStep startStep = factory.createStartStep(1L, new HashMap<String, Serializable>(), execInputs,"");
        Assert.assertNotNull("inputs key is null", startStep.getActionData().get(ScoreLangConstants.EXECUTABLE_INPUTS_KEY));
        Assert.assertSame("inputs are not set under their key", execInputs, startStep.getActionData().get(ScoreLangConstants.EXECUTABLE_INPUTS_KEY));
    }

    @Test
    public void testCreateStartStepPutForUnderTheRightKey() throws Exception {
//        ForLoopStatement statement = new ForLoopStatement("1", "2");
//        HashMap<String, Serializable> preTaskData = new HashMap<>();
//        preTaskData.put(SlangTextualKeys.FOR_KEY, statement);
//        ExecutionStep startStep = factory.createBeginTaskStep(1L, new ArrayList<Input>(), preTaskData, "", "");
//        ForLoopStatement actualStatement = (ForLoopStatement) startStep.getActionData()
//                                 .get(ScoreLangConstants.LOOP_KEY);
//        Assert.assertNotNull("for key is null", actualStatement);
//        Assert.assertSame("inputs are not set under their key", statement, actualStatement);
    }

    @Test
    public void testCreateFinishTakStep(){
        ExecutionStep finishTaskStep = factory.createFinishTaskStep(
                1L,
                new HashMap<String, Serializable>(),
                new HashMap<String, ResultNavigation>(),
                "taskName");
        Assert.assertTrue(finishTaskStep.getActionData().containsKey(ScoreLangConstants.PREVIOUS_STEP_ID_KEY));<commit_msg>update test<commit_after>/*******************************************************************************
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0 which accompany this distribution.
*
* The Apache License is available at
* http://www.apache.org/licenses/LICENSE-2.0
*
*******************************************************************************/
package org.openscore.lang.compiler.scorecompiler;

import org.openscore.lang.compiler.SlangTextualKeys;
import org.openscore.lang.entities.ForLoopStatement;
import org.openscore.lang.entities.ListForLoopStatement;
import org.openscore.lang.entities.ResultNavigation;
import org.openscore.lang.entities.ScoreLangConstants;
import org.openscore.lang.entities.bindings.Input;
import org.openscore.lang.entities.bindings.Output;
import org.openscore.lang.entities.bindings.Result;
import junit.framework.Assert;
import org.openscore.api.ExecutionStep;
import org.junit.Before;
import org.junit.Test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

public class ExecutionStepFactoryTest {

    private ExecutionStepFactory factory;

    @Before
    public void init() {
        factory = new ExecutionStepFactory();
    }

    @Test
    public void testCreateStartStep() throws Exception {
        ExecutionStep startStep = factory.createStartStep(1L, new HashMap<String, Serializable>(), new ArrayList<Input>(),"coolStep");
        Assert.assertNotNull("step should not be null", startStep);
        Assert.assertEquals("coolStep",startStep.getActionData().get(ScoreLangConstants.NODE_NAME_KEY));
    }

    @Test
    public void testCreateStartStepPutInputsUnderTheRightKey() throws Exception {
        ArrayList<Input> execInputs = new ArrayList<>();
        ExecutionStep startStep = factory.createStartStep(1L, new HashMap<String, Serializable>(), execInputs,"");
        Assert.assertNotNull("inputs key is null", startStep.getActionData().get(ScoreLangConstants.EXECUTABLE_INPUTS_KEY));
        Assert.assertSame("inputs are not set under their key", execInputs, startStep.getActionData().get(ScoreLangConstants.EXECUTABLE_INPUTS_KEY));
    }

    @Test
    public void testCreateStartStepPutForUnderTheRightKey() throws Exception {
        ForLoopStatement statement = new ListForLoopStatement("1", "2");
        HashMap<String, Serializable> preTaskData = new HashMap<>();
        preTaskData.put(SlangTextualKeys.FOR_KEY, statement);
        ExecutionStep startStep = factory.createBeginTaskStep(1L, new ArrayList<Input>(), preTaskData, "", "");
        ForLoopStatement actualStatement = (ForLoopStatement) startStep.getActionData()
                                 .get(ScoreLangConstants.LOOP_KEY);
        Assert.assertNotNull("for key is null", actualStatement);
        Assert.assertSame("inputs are not set under their key", statement, actualStatement);
    }

    @Test
    public void testCreateFinishTakStep(){
        ExecutionStep finishTaskStep = factory.createFinishTaskStep(
                1L,
                new HashMap<String, Serializable>(),
                new HashMap<String, ResultNavigation>(),
                "taskName");
        Assert.assertTrue(finishTaskStep.getActionData().containsKey(ScoreLangConstants.PREVIOUS_STEP_ID_KEY));
{'fraction_non_alphanumeric': 0.142899364563322, 'fraction_numerical': 0.0041377272055563765, 'mean_word_length': 4.388535031847134, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '836427', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1723, 'n_words': 388}