Search in sources :

Example 6 with Decimal

use of de.invesdwin.util.math.decimal.Decimal in project invesdwin-context-matlab by subes.

the class InputsAndResultsTestPercent method testPercent.

public void testPercent() {
    // putPercent
    final Percent putPercent = new Percent(123.123D, PercentScale.RATE);
    // putPercentVector
    final Percent[] putPercentVector = new Percent[3];
    for (int i = 0; i < putPercentVector.length; i++) {
        putPercentVector[i] = new Percent(new Decimal((i + 1) + "." + (i + 1)), PercentScale.RATE);
    }
    // putPercentVectorAsList
    final List<Percent> putPercentVectorAsList = Arrays.asList(putPercentVector);
    // putPercentMatrix
    final Percent[][] putPercentMatrix = new Percent[4][];
    for (int row = 0; row < putPercentMatrix.length; row++) {
        final Percent[] vector = new Percent[3];
        for (int col = 0; col < vector.length; col++) {
            vector[col] = new Percent(new Decimal((row + 1) + "." + (col + 1)), PercentScale.RATE);
        }
        putPercentMatrix[row] = vector;
    }
    // putPercentMatrixAsList
    final List<List<Percent>> putPercentMatrixAsList = new ArrayList<List<Percent>>(putPercentMatrix.length);
    for (final Percent[] vector : putPercentMatrix) {
        putPercentMatrixAsList.add(Arrays.asList(vector));
    }
    new AScriptTaskMatlab<Void>() {

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

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

        @Override
        public Void extractResults(final IScriptTaskResults results) {
            // getPercent
            final Percent getPercent = results.getDecimal("getPercent", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercent).isEqualTo(getPercent);
            // getPercentVector
            final Percent[] getPercentVector = results.getDecimalVector("getPercentVector", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentVector).isEqualTo(getPercentVector);
            // getPercentVectorAsList
            final List<Percent> getPercentVectorAsList = results.getDecimalVectorAsList("getPercentVectorAsList", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentVectorAsList).isEqualTo(getPercentVectorAsList);
            // getPercentMatrix
            final Percent[][] getPercentMatrix = results.getDecimalMatrix("getPercentMatrix", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentMatrix).isEqualTo(getPercentMatrix);
            // getPercentMatrixAsList
            final List<List<Percent>> getPercentMatrixAsList = results.getDecimalMatrixAsList("getPercentMatrixAsList", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentMatrixAsList).isEqualTo(getPercentMatrixAsList);
            return null;
        }
    }.run(runner);
}
Also used : Percent(de.invesdwin.util.math.decimal.scaled.Percent) 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 Decimal

use of de.invesdwin.util.math.decimal.Decimal in project invesdwin-context-matlab by subes.

the class MainTest method test.

@Test
public void test() throws IOException {
    final String providedInstanceProperty = "-D" + ProvidedScriptTaskRunnerMatlab.PROVIDED_INSTANCE_KEY + "=" + JavaOctaveScriptTaskRunnerMatlab.class.getName();
    final String inputFile = new ClassPathResource(MainTest.class.getSimpleName() + "_input.csv", MainTest.class).getFile().getAbsolutePath();
    final String outputFile = new File(ContextProperties.TEMP_DIRECTORY, MainTest.class.getSimpleName() + "_output.csv").getAbsolutePath();
    Main.main(new String[] { providedInstanceProperty, "-i", inputFile, "-o", outputFile });
    final List<String> optimalFStrs = Files.readLines(new File(outputFile), Charset.defaultCharset());
    final List<Decimal> optimalFs = new ArrayList<Decimal>();
    for (final String optimalFStr : optimalFStrs) {
        optimalFs.add(new Decimal(optimalFStr).round(3));
    }
    Assertions.assertThat(optimalFs).isEqualTo(Arrays.asList(new Decimal("0.052"), new Decimal("0.213")));
}
Also used : Decimal(de.invesdwin.util.math.decimal.Decimal) JavaOctaveScriptTaskRunnerMatlab(de.invesdwin.context.matlab.runtime.javaoctave.JavaOctaveScriptTaskRunnerMatlab) ArrayList(java.util.ArrayList) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 8 with Decimal

use of de.invesdwin.util.math.decimal.Decimal 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 9 with Decimal

use of de.invesdwin.util.math.decimal.Decimal 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

Decimal (de.invesdwin.util.math.decimal.Decimal)9 ClassPathResource (org.springframework.core.io.ClassPathResource)6 IScriptTaskEngine (de.invesdwin.context.integration.script.IScriptTaskEngine)5 IScriptTaskInputs (de.invesdwin.context.integration.script.IScriptTaskInputs)5 IScriptTaskResults (de.invesdwin.context.integration.script.IScriptTaskResults)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Percent (de.invesdwin.util.math.decimal.scaled.Percent)3 ATest (de.invesdwin.context.test.ATest)2 Test (org.junit.Test)2 JavaOctaveScriptTaskRunnerMatlab (de.invesdwin.context.matlab.runtime.javaoctave.JavaOctaveScriptTaskRunnerMatlab)1 TimedDecimal (de.invesdwin.util.math.decimal.TimedDecimal)1 FDate (de.invesdwin.util.time.fdate.FDate)1 File (java.io.File)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 LinkedHashSet (java.util.LinkedHashSet)1 Ignore (org.junit.Ignore)1 Test (org.junit.jupiter.api.Test)1