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);
}
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")));
}
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);
}
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);
}
Aggregations