use of de.invesdwin.context.integration.script.IScriptTaskInputs in project invesdwin-context-matlab by subes.
the class HelloWorldScript method testHelloWorld.
public void testHelloWorld() {
final AScriptTaskMatlab<String> script = new AScriptTaskMatlab<String>() {
@Override
public void populateInputs(final IScriptTaskInputs inputs) {
inputs.putString("hello", "World");
}
@Override
public void executeScript(final IScriptTaskEngine engine) {
// execute this script inline:
// engine.eval("world = strcat({'Hello '}, hello, '!')");
// or run it from a file:
engine.eval(new ClassPathResource(HelloWorldScript.class.getSimpleName() + ".m", getClass()));
}
@Override
public String extractResults(final IScriptTaskResults results) {
return results.getString("world");
}
};
final String result = script.run(runner);
Assertions.assertThat(result).isEqualTo("Hello World!");
}
use of de.invesdwin.context.integration.script.IScriptTaskInputs in project invesdwin-context-matlab by subes.
the class HelloWorldScript method testHelloWorld.
public void testHelloWorld() {
final AScriptTaskMatlab<String> script = new AScriptTaskMatlab<String>() {
@Override
public void populateInputs(final IScriptTaskInputs inputs) {
inputs.putString("hello", "World");
}
@Override
public void executeScript(final IScriptTaskEngine engine) {
// execute this script inline:
// engine.eval("world = strcat('Hello ', hello, '!')");
// or run it from a file:
engine.eval(new ClassPathResource(HelloWorldScript.class.getSimpleName() + ".sce", getClass()));
}
@Override
public String extractResults(final IScriptTaskResults results) {
return results.getString("world");
}
};
final String result = script.run(runner);
Assertions.assertThat(result).isEqualTo("Hello World!");
}
use of de.invesdwin.context.integration.script.IScriptTaskInputs 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() + ".sce", 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);
}
use of de.invesdwin.context.integration.script.IScriptTaskInputs in project invesdwin-context-matlab by subes.
the class InputsAndResultsTestEmptyMatrixValue method testEmptyMatrixValue.
// CHECKSTYLE:OFF NCSS
public void testEmptyMatrixValue() {
// CHECKSTYLE:ON
final boolean[][] putBooleanMatrix = new boolean[2][];
for (int i = 0; i < putBooleanMatrix.length; i++) {
putBooleanMatrix[i] = new boolean[0];
}
final List<List<Boolean>> putBooleanMatrixAsList = Booleans.asListMatrix(putBooleanMatrix);
final byte[][] putByteMatrix = new byte[2][];
for (int i = 0; i < putByteMatrix.length; i++) {
putByteMatrix[i] = new byte[0];
}
final List<List<Byte>> putByteMatrixAsList = Bytes.asListMatrix(putByteMatrix);
final char[][] putCharacterMatrix = new char[2][];
for (int i = 0; i < putCharacterMatrix.length; i++) {
putCharacterMatrix[i] = new char[0];
}
final List<List<Character>> putCharacterMatrixAsList = Characters.asListMatrix(putCharacterMatrix);
final Decimal[][] putDecimalMatrix = new Decimal[2][];
for (int i = 0; i < putDecimalMatrix.length; i++) {
putDecimalMatrix[i] = new Decimal[0];
}
final List<List<Decimal>> putDecimalMatrixAsList = Decimal.asListMatrix(putDecimalMatrix);
final double[][] putDoubleMatrix = new double[2][];
for (int i = 0; i < putDoubleMatrix.length; i++) {
putDoubleMatrix[i] = new double[0];
}
final List<List<Double>> putDoubleMatrixAsList = Doubles.asListMatrix(putDoubleMatrix);
final float[][] putFloatMatrix = new float[2][];
for (int i = 0; i < putFloatMatrix.length; i++) {
putFloatMatrix[i] = new float[0];
}
final List<List<Float>> putFloatMatrixAsList = Floats.asListMatrix(putFloatMatrix);
final int[][] putIntegerMatrix = new int[2][];
for (int i = 0; i < putIntegerMatrix.length; i++) {
putIntegerMatrix[i] = new int[0];
}
final List<List<Integer>> putIntegerMatrixAsList = Integers.asListMatrix(putIntegerMatrix);
final long[][] putLongMatrix = new long[2][];
for (int i = 0; i < putLongMatrix.length; i++) {
putLongMatrix[i] = new long[0];
}
final List<List<Long>> putLongMatrixAsList = Longs.asListMatrix(putLongMatrix);
final Percent[][] putPercentMatrix = new Percent[2][];
for (int i = 0; i < putPercentMatrix.length; i++) {
putPercentMatrix[i] = new Percent[0];
}
final List<List<Percent>> putPercentMatrixAsList = Percent.asListMatrix(putPercentMatrix);
final short[][] putShortMatrix = new short[2][];
for (int i = 0; i < putShortMatrix.length; i++) {
putShortMatrix[i] = new short[0];
}
final List<List<Short>> putShortMatrixAsList = Shorts.asListMatrix(putShortMatrix);
final String[][] putStringMatrix = new String[2][];
for (int i = 0; i < putStringMatrix.length; i++) {
putStringMatrix[i] = new String[0];
}
final List<List<String>> putStringMatrixAsList = Strings.asListMatrix(putStringMatrix);
new AScriptTaskMatlab<Void>() {
@Override
public void populateInputs(final IScriptTaskInputs inputs) {
inputs.putBooleanMatrix("putBooleanMatrix", putBooleanMatrix);
inputs.putBooleanMatrixAsList("putBooleanMatrixAsList", putBooleanMatrixAsList);
inputs.putByteMatrix("putByteMatrix", putByteMatrix);
inputs.putByteMatrixAsList("putByteMatrixAsList", putByteMatrixAsList);
inputs.putCharacterMatrix("putCharacterMatrix", putCharacterMatrix);
inputs.putCharacterMatrixAsList("putCharacterMatrixAsList", putCharacterMatrixAsList);
inputs.putDecimalMatrix("putDecimalMatrix", putDecimalMatrix);
inputs.putDecimalMatrixAsList("putDecimalMatrixAsList", putDecimalMatrixAsList);
inputs.putDoubleMatrix("putDoubleMatrix", putDoubleMatrix);
inputs.putDoubleMatrixAsList("putDoubleMatrixAsList", putDoubleMatrixAsList);
inputs.putFloatMatrix("putFloatMatrix", putFloatMatrix);
inputs.putFloatMatrixAsList("putFloatMatrixAsList", putFloatMatrixAsList);
inputs.putIntegerMatrix("putIntegerMatrix", putIntegerMatrix);
inputs.putIntegerMatrixAsList("putIntegerMatrixAsList", putIntegerMatrixAsList);
inputs.putLongMatrix("putLongMatrix", putLongMatrix);
inputs.putLongMatrixAsList("putLongMatrixAsList", putLongMatrixAsList);
inputs.putDecimalMatrix("putPercentMatrix", putPercentMatrix);
inputs.putDecimalMatrixAsList("putPercentMatrixAsList", putPercentMatrixAsList);
inputs.putShortMatrix("putShortMatrix", putShortMatrix);
inputs.putShortMatrixAsList("putShortMatrixAsList", putShortMatrixAsList);
inputs.putStringMatrix("putStringMatrix", putStringMatrix);
inputs.putStringMatrixAsList("putStringMatrixAsList", putStringMatrixAsList);
}
@Override
public void executeScript(final IScriptTaskEngine engine) {
try {
final String script = IOUtils.toString(new ClassPathResource(InputsAndResultsTestEmptyMatrixValue.class.getSimpleName() + ".m", InputsAndResultsTestNull.class).getInputStream(), Charset.defaultCharset());
if (!engine.getResults().getBoolean("exist('OCTAVE_VERSION', 'builtin') > 0")) {
// workaround for matlab and isempty not counting empty cells there
final StringBuilder sb = new StringBuilder();
// we can actually create functions in scripts without separate files: http://de.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html
sb.append("ismatlabempty = @(x) all(cellfun(@isempty, x));\n");
sb.append("\n");
sb.append(script.replace("isempty", "ismatlabempty"));
engine.eval(sb.toString());
} else {
engine.eval(script);
}
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
@Override
public Void extractResults(final IScriptTaskResults results) {
Assertions.checkEquals(putBooleanMatrix, results.getBooleanMatrix("getBooleanMatrix"));
Assertions.checkEquals(putBooleanMatrixAsList, results.getBooleanMatrixAsList("getBooleanMatrixAsList"));
Assertions.checkEquals(putByteMatrix, results.getByteMatrix("getByteMatrix"));
Assertions.checkEquals(putByteMatrixAsList, results.getByteMatrixAsList("getByteMatrixAsList"));
Assertions.checkEquals(putCharacterMatrix, results.getCharacterMatrix("getCharacterMatrix"));
Assertions.checkEquals(putCharacterMatrixAsList, results.getCharacterMatrixAsList("getCharacterMatrixAsList"));
Assertions.checkEquals(putDecimalMatrix, results.getDecimalMatrix("getDecimalMatrix"));
Assertions.checkEquals(putDecimalMatrixAsList, results.getDecimalMatrixAsList("getDecimalMatrixAsList"));
Assertions.checkEquals(putDoubleMatrix, results.getDoubleMatrix("getDoubleMatrix"));
Assertions.checkEquals(putDoubleMatrixAsList, results.getDoubleMatrixAsList("getDoubleMatrixAsList"));
Assertions.checkEquals(putFloatMatrix, results.getFloatMatrix("getFloatMatrix"));
Assertions.checkEquals(putFloatMatrixAsList, results.getFloatMatrixAsList("getFloatMatrixAsList"));
Assertions.checkEquals(putIntegerMatrix, results.getIntegerMatrix("getIntegerMatrix"));
Assertions.checkEquals(putIntegerMatrixAsList, results.getIntegerMatrixAsList("getIntegerMatrixAsList"));
Assertions.checkEquals(putLongMatrix, results.getLongMatrix("getLongMatrix"));
Assertions.checkEquals(putLongMatrixAsList, results.getLongMatrixAsList("getLongMatrixAsList"));
Assertions.checkEquals(putPercentMatrix, results.getDecimalMatrix("getPercentMatrix", Percent.ZERO_PERCENT));
Assertions.checkEquals(putPercentMatrixAsList, results.getDecimalMatrixAsList("getPercentMatrixAsList", Percent.ZERO_PERCENT));
Assertions.checkEquals(putShortMatrix, results.getShortMatrix("getShortMatrix"));
Assertions.checkEquals(putShortMatrixAsList, results.getShortMatrixAsList("getShortMatrixAsList"));
Assertions.checkEquals(putStringMatrix, results.getStringMatrix("getStringMatrix"));
Assertions.checkEquals(putStringMatrixAsList, results.getStringMatrixAsList("getStringMatrixAsList"));
return null;
}
}.run(runner);
}
use of de.invesdwin.context.integration.script.IScriptTaskInputs 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);
}
Aggregations