Commit 02c96ccf authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated tests

parent 61e15399
......@@ -6,6 +6,7 @@ import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.streamunits._ast.ASTComponentStreamUnits;
import de.monticore.lang.monticar.streamunits._ast.ASTNamedStreamUnits;
import de.monticore.lang.monticar.streamunits._ast.ASTPrecisionNumber;
import de.monticore.lang.monticar.streamunits._symboltable.ComponentStreamUnitsSymbol;
import de.monticore.lang.monticar.streamunits._symboltable.NamedStreamUnitsSymbol;
......@@ -17,6 +18,48 @@ public class TestConverter {
public static FileContent generateMainTestFile(ComponentStreamUnitsSymbol symbol, ExpandedComponentInstanceSymbol instanceSymbol) {
FileContent fileContent = new FileContent();
fileContent.setFileName("main_" + GeneralHelperMethods.getTargetLanguageComponentName(symbol.getFullName()) + ".cpp");
String fileContentString = "";
fileContentString += getDefaultContent(symbol);
ASTComponentStreamUnits ast = (ASTComponentStreamUnits) symbol.getAstNode().get();
int executionCounter = 0;
int executionAmount = ast.getNamedStreamUnitss().get(0).getStream().getPrecisionNumbers().size();
while (executionCounter < executionAmount) {
for (ASTNamedStreamUnits astNamedStreamUnit : ast.getNamedStreamUnitss()) {
fileContentString += getFileContentStringFor(instanceSymbol, astNamedStreamUnit, executionCounter);
}
fileContentString += "testInstance.execute();\n";
for (ASTNamedStreamUnits astNamedStreamUnit : ast.getNamedStreamUnitss()) {
String portName = astNamedStreamUnit.getName();
if (!instanceSymbol.getPort(portName).get().isIncoming()) {
if (astNamedStreamUnit.getStream().getPrecisionNumbers().size() > 0) {
ASTPrecisionNumber precisionNumber = astNamedStreamUnit.getStream().getPrecisionNumbers().get(executionCounter);
if (precisionNumber.getPrecision().isPresent()) {
fileContentString += "if(testInstance." + portName + ">" +"("+ precisionNumber.getUnitNumber().getNumber().get()+"-"+precisionNumber.getPrecision().get().getUnitNumber().getNumber().get() +")";
fileContentString += "&& testInstance." + portName + "<" +"("+ precisionNumber.getUnitNumber().getNumber().get()+"+"+precisionNumber.getPrecision().get().getUnitNumber().getNumber().get() +")";
fileContentString += "){";
fileContentString += "printf(\"Mismatch at executionStep " + executionCounter + "\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
} else {
fileContentString += "if(testInstance." + portName + "!=" + precisionNumber.getUnitNumber().getNumber().get() + "){";
fileContentString += "printf(\"Mismatch at executionStep " + executionCounter + "\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
}
}
}
}
++executionCounter;
}
fileContentString += "octave_quit();\n";
fileContentString += "printf(\"Execution ended successfully!\\n\");\n";
fileContentString += "}\n";
fileContent.setFileContent(fileContentString);
return fileContent;
}
public static String getDefaultContent(ComponentStreamUnitsSymbol symbol) {
String fileContentString = "";
fileContentString += "#ifndef M_PI\n" +
"#define M_PI 3.14159265358979323846\n" +
......@@ -32,34 +75,18 @@ public class TestConverter {
fileContentString += GeneralHelperMethods.getTargetLanguageComponentName(symbol.getPackageName() + "." + Character.toLowerCase(ast.getComponentName().charAt(0)) + ast.getComponentName().substring(1));
fileContentString += " testInstance;\n";
fileContentString += "testInstance.init();\n";
return fileContentString;
}
int executionCounter = 0;
for (ASTNamedStreamUnits astNamedStreamUnit : ast.getNamedStreamUnitss()) {
String portName = astNamedStreamUnit.getName();
if (instanceSymbol.getPort(portName).get().isIncoming()) {
if (astNamedStreamUnit.getStream().getPrecisionNumbers().size() > 0) {
fileContentString += "testInstance." + portName + "=" + astNamedStreamUnit.getStream().getPrecisionNumbers().get(executionCounter).getUnitNumber().getNumber().get() + ";";
}
}
}
fileContentString += "testInstance.execute();\n";
for (ASTNamedStreamUnits astNamedStreamUnit : ast.getNamedStreamUnitss()) {
String portName = astNamedStreamUnit.getName();
if (!instanceSymbol.getPort(portName).get().isIncoming()) {
if (astNamedStreamUnit.getStream().getPrecisionNumbers().size() > 0) {
fileContentString += "if(testInstance." + portName + "!=" + astNamedStreamUnit.getStream().getPrecisionNumbers().get(executionCounter).getUnitNumber().getNumber().get() + "){";
fileContentString += "printf(\"Mismatch at executionStep "+executionCounter+"\");\n";
fileContentString += "octave_quit();\n";
fileContentString += "}\n";
}
public static String getFileContentStringFor(ExpandedComponentInstanceSymbol instanceSymbol, ASTNamedStreamUnits astNamedStreamUnit, int executionCounter) {
String fileContentString = "";
String portName = astNamedStreamUnit.getName();
if (instanceSymbol.getPort(portName).get().isIncoming()) {
if (astNamedStreamUnit.getStream().getPrecisionNumbers().size() > 0) {
fileContentString += "testInstance." + portName + "=" + astNamedStreamUnit.getStream().getPrecisionNumbers().get(executionCounter).getUnitNumber().getNumber().get() + ";";
}
}
fileContentString+= "octave_quit();\n";
fileContentString+= "printf(\"Execution ended successfully!\\n\");\n";
fileContentString += "}\n";
fileContent.setFileContent(fileContentString);
return fileContent;
return fileContentString;
}
}
......@@ -8,8 +8,17 @@ int main(int argc, char** argv)
Helper::init();
test_math_sumCommandTest testInstance;
testInstance.init();
testInstance.execute();
if(testInstance.out1!=6/1){printf("Mismatch at executionStep 0");
testInstance.in1=0/1;testInstance.execute();
if(testInstance.out1>(6/1-1/1)&& testInstance.out1<(6/1+1/1)){printf("Mismatch at executionStep 0");
octave_quit();
}
testInstance.in1=1/1;testInstance.execute();
if(testInstance.out1!=7/1){printf("Mismatch at executionStep 1");
octave_quit();
}
testInstance.in1=2/1;testInstance.execute();
if(testInstance.out1!=8/1){printf("Mismatch at executionStep 2");
octave_quit();
}
octave_quit();
printf("Execution ended successfully!\n");
......
......@@ -8,6 +8,7 @@
#include "octave/builtin-defun-decls.h"
class test_math_sumCommandTest{
public:
double in1;
double out1;
RowVector CONSTANTCONSTANTVECTOR0;
void init()
......@@ -21,7 +22,7 @@ void execute()
{
RowVector mat = CONSTANTCONSTANTVECTOR0;
double a = (Helper::getDoubleFromOctaveListFirstResult(Fsum(Helper::convertToOctaveValueList(mat),1)));
out1 = a;
out1 = a+in1;
}
};
......
package test.math;
component SumCommandTest{
ports out Q(0:100) out1;
ports in Q(0:10) in1,
out Q(0:100) out1;
implementation Math{
Q^{1, 3} mat = [1 2 3];
Q a = sum(mat);
out1 = a;
out1 = a+in1;
}
}
\ No newline at end of file
package test.math;
stream SumCommandTestStream for SumCommandTest{
out1: 6 tick 6 tick 6;
in1: 0 tick 1 tick 2;
out1: 6 +/- 1 tick 7 tick 8;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment