Search in sources :

Example 6 with IScriptTaskInputs

use of de.invesdwin.context.integration.script.IScriptTaskInputs in project invesdwin-context-matlab by subes.

the class InputsAndResultsTestDecimal method testDecimal.

public void testDecimal() {
    // putDecimal
    final Decimal putDecimal = new Decimal("123.123");
    // putDecimalVector
    final Decimal[] putDecimalVector = new Decimal[3];
    for (int i = 0; i < putDecimalVector.length; i++) {
        putDecimalVector[i] = Decimal.valueOf((i + 1) + "." + (i + 1));
    }
    // putDecimalVectorAsList
    final List<Decimal> putDecimalVectorAsList = Arrays.asList(putDecimalVector);
    // putDecimalMatrix
    final Decimal[][] putDecimalMatrix = new Decimal[4][];
    for (int row = 0; row < putDecimalMatrix.length; row++) {
        final Decimal[] vector = new Decimal[3];
        for (int col = 0; col < vector.length; col++) {
            vector[col] = Decimal.valueOf((row + 1) + "." + (col + 1));
        }
        putDecimalMatrix[row] = vector;
    }
    // putDecimalMatrixAsList
    final List<List<Decimal>> putDecimalMatrixAsList = new ArrayList<List<Decimal>>(putDecimalMatrix.length);
    for (final Decimal[] vector : putDecimalMatrix) {
        putDecimalMatrixAsList.add(Arrays.asList(vector));
    }
    new AScriptTaskMatlab<Void>() {

        @Override
        public void populateInputs(final IScriptTaskInputs inputs) {
            inputs.putDecimal("putDecimal", putDecimal);
            inputs.putDecimalVector("putDecimalVector", putDecimalVector);
            inputs.putDecimalVectorAsList("putDecimalVectorAsList", putDecimalVectorAsList);
            inputs.putDecimalMatrix("putDecimalMatrix", putDecimalMatrix);
            inputs.putDecimalMatrixAsList("putDecimalMatrixAsList", putDecimalMatrixAsList);
        }

        @Override
        public void executeScript(final IScriptTaskEngine engine) {
            engine.eval(new ClassPathResource(InputsAndResultsTestDecimal.class.getSimpleName() + ".m", InputsAndResultsTestDecimal.class));
        }

        @Override
        public Void extractResults(final IScriptTaskResults results) {
            // getDecimal
            final Decimal getDecimal = results.getDecimal("getDecimal");
            Assertions.assertThat(putDecimal).isEqualTo(getDecimal);
            // getDecimalVector
            final Decimal[] getDecimalVector = results.getDecimalVector("getDecimalVector");
            Assertions.assertThat(putDecimalVector).isEqualTo(getDecimalVector);
            // getDecimalVectorAsList
            final List<Decimal> getDecimalVectorAsList = results.getDecimalVectorAsList("getDecimalVectorAsList");
            Assertions.assertThat(putDecimalVectorAsList).isEqualTo(getDecimalVectorAsList);
            // getDecimalMatrix
            final Decimal[][] getDecimalMatrix = results.getDecimalMatrix("getDecimalMatrix");
            Assertions.assertThat(putDecimalMatrix).isEqualTo(getDecimalMatrix);
            // getDecimalMatrixAsList
            final List<List<Decimal>> getDecimalMatrixAsList = results.getDecimalMatrixAsList("getDecimalMatrixAsList");
            Assertions.assertThat(putDecimalMatrixAsList).isEqualTo(getDecimalMatrixAsList);
            return null;
        }
    }.run(runner);
}
Also used : ArrayList(java.util.ArrayList) IScriptTaskEngine(de.invesdwin.context.integration.script.IScriptTaskEngine) ClassPathResource(org.springframework.core.io.ClassPathResource) IScriptTaskInputs(de.invesdwin.context.integration.script.IScriptTaskInputs) IScriptTaskResults(de.invesdwin.context.integration.script.IScriptTaskResults) Decimal(de.invesdwin.util.math.decimal.Decimal) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with IScriptTaskInputs

use of de.invesdwin.context.integration.script.IScriptTaskInputs in project invesdwin-context-matlab by subes.

the class InputsAndResultsTestDecimal method testDecimal.

public void testDecimal() {
    // putDecimal
    final Decimal putDecimal = new Decimal("123.123");
    // putDecimalVector
    final Decimal[] putDecimalVector = new Decimal[3];
    for (int i = 0; i < putDecimalVector.length; i++) {
        putDecimalVector[i] = Decimal.valueOf((i + 1) + "." + (i + 1));
    }
    // putDecimalVectorAsList
    final List<Decimal> putDecimalVectorAsList = Arrays.asList(putDecimalVector);
    // putDecimalMatrix
    final Decimal[][] putDecimalMatrix = new Decimal[4][];
    for (int row = 0; row < putDecimalMatrix.length; row++) {
        final Decimal[] vector = new Decimal[3];
        for (int col = 0; col < vector.length; col++) {
            vector[col] = Decimal.valueOf((row + 1) + "." + (col + 1));
        }
        putDecimalMatrix[row] = vector;
    }
    // putDecimalMatrixAsList
    final List<List<Decimal>> putDecimalMatrixAsList = new ArrayList<List<Decimal>>(putDecimalMatrix.length);
    for (final Decimal[] vector : putDecimalMatrix) {
        putDecimalMatrixAsList.add(Arrays.asList(vector));
    }
    new AScriptTaskMatlab<Void>() {

        @Override
        public void populateInputs(final IScriptTaskInputs inputs) {
            inputs.putDecimal("putDecimal", putDecimal);
            inputs.putDecimalVector("putDecimalVector", putDecimalVector);
            inputs.putDecimalVectorAsList("putDecimalVectorAsList", putDecimalVectorAsList);
            inputs.putDecimalMatrix("putDecimalMatrix", putDecimalMatrix);
            inputs.putDecimalMatrixAsList("putDecimalMatrixAsList", putDecimalMatrixAsList);
        }

        @Override
        public void executeScript(final IScriptTaskEngine engine) {
            engine.eval(new ClassPathResource(InputsAndResultsTestDecimal.class.getSimpleName() + ".sce", InputsAndResultsTestDecimal.class));
        }

        @Override
        public Void extractResults(final IScriptTaskResults results) {
            // getDecimal
            final Decimal getDecimal = results.getDecimal("getDecimal");
            Assertions.assertThat(putDecimal).isEqualTo(getDecimal);
            // getDecimalVector
            final Decimal[] getDecimalVector = results.getDecimalVector("getDecimalVector");
            Assertions.assertThat(putDecimalVector).isEqualTo(getDecimalVector);
            // getDecimalVectorAsList
            final List<Decimal> getDecimalVectorAsList = results.getDecimalVectorAsList("getDecimalVectorAsList");
            Assertions.assertThat(putDecimalVectorAsList).isEqualTo(getDecimalVectorAsList);
            // getDecimalMatrix
            final Decimal[][] getDecimalMatrix = results.getDecimalMatrix("getDecimalMatrix");
            Assertions.assertThat(putDecimalMatrix).isEqualTo(getDecimalMatrix);
            // getDecimalMatrixAsList
            final List<List<Decimal>> getDecimalMatrixAsList = results.getDecimalMatrixAsList("getDecimalMatrixAsList");
            Assertions.assertThat(putDecimalMatrixAsList).isEqualTo(getDecimalMatrixAsList);
            return null;
        }
    }.run(runner);
}
Also used : ArrayList(java.util.ArrayList) IScriptTaskEngine(de.invesdwin.context.integration.script.IScriptTaskEngine) ClassPathResource(org.springframework.core.io.ClassPathResource) IScriptTaskInputs(de.invesdwin.context.integration.script.IScriptTaskInputs) IScriptTaskResults(de.invesdwin.context.integration.script.IScriptTaskResults) Decimal(de.invesdwin.util.math.decimal.Decimal) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

IScriptTaskEngine (de.invesdwin.context.integration.script.IScriptTaskEngine)7 IScriptTaskInputs (de.invesdwin.context.integration.script.IScriptTaskInputs)7 IScriptTaskResults (de.invesdwin.context.integration.script.IScriptTaskResults)7 ClassPathResource (org.springframework.core.io.ClassPathResource)7 Decimal (de.invesdwin.util.math.decimal.Decimal)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 Percent (de.invesdwin.util.math.decimal.scaled.Percent)3 AScriptTaskMatlab (de.invesdwin.context.matlab.runtime.contract.AScriptTaskMatlab)2 IOException (java.io.IOException)1