Commit b285f373 authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

added new tests

parent 5c0a8614
Pipeline #59373 passed with stage
in 2 minutes and 30 seconds
......@@ -92,7 +92,7 @@ public class BluePrintCPP extends BluePrint {
if (number == -1) {
//if(resolutionDeclarationSymbol.getNameToResolve().equals(nameToResolve))
{
Log.info(resolutionDeclarationSymbol.getNameToResolve(), "Fixed");
Log.info(resolutionDeclarationSymbol.getNameToResolve()+"set number to "+numberToSet+"; oldValue: "+number, "Fixed");
InstanceInformation.setInstanceNumberInASTSubComponent(subComponent, nameToResolve, numberToSet);
break;
}/*else{
......
......@@ -27,6 +27,7 @@ import de.monticore.lang.monticar.struct._symboltable.StructLanguage;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.GlobalScope;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.logging.Log;
import java.nio.file.Paths;
import java.util.Arrays;
......@@ -67,6 +68,7 @@ public class AbstractSymtab {
mp.addEntry(Paths.get(m));
}
LogConfig.init();//TODO comment for debug output
GlobalScope scope = new GlobalScope(mp, fam);
de.monticore.lang.monticar.Utils.addBuiltInTypes(scope);
return scope;
......
......@@ -102,4 +102,32 @@ public class BasicMathGenerationArmadilloTest extends AbstractSymtabTest {
String restPath = "armadillo/testMath/l0/";
testFilesAreEqual(files, restPath);
}
@Test
public void sampleComponentTest() throws IOException{
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.custom.sampleComponentInst", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/test/custom/l0");
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/test/custom/l0/";
testFilesAreEqual(files, restPath);
}
@Test
public void samplePacmanMain() throws IOException{
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("test.custom.pacmanSampleGame", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/test/custom/l0");
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/test/custom/l0/";
testFilesAreEqual(files, restPath);
}
}
#ifndef HELPERA_H
#define HELPERA_H
#include <iostream>
#include "armadillo.h"
#include <stdarg.h>
#include <initializer_list>
using namespace arma;
class HelperA{
public:
static mat getEigenVectors(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenVectors;
}
static vec getEigenValues(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenValues;
}
static mat getKMeansClusters(mat A, int k){
mat clusters;
kmeans(clusters,A.t(),k,random_subset,20,true);
/*printf("cluster centroid calculation done\n");
std::ofstream myfile;
myfile.open("data after cluster.txt");
myfile << A;
myfile.close();
std::ofstream myfile2;
myfile2.open("cluster centroids.txt");
myfile2 << clusters;
myfile2.close();*/
mat indexedData=getKMeansClustersIndexData(A.t(), clusters);
/*std::ofstream myfile3;
myfile3.open("data after index.txt");
myfile3 << indexedData;
myfile3.close();
*/
return indexedData;
}
static mat getKMeansClustersIndexData(mat A, mat centroids){
mat result=mat(A.n_cols, 1);
for(int i=0;i<A.n_cols;++i){
result(i, 0) = getIndexForClusterCentroids(A, i, centroids);
}
return result;
}
static int getIndexForClusterCentroids(mat A, int colIndex, mat centroids){
int index=1;
double lowestDistance=getEuclideanDistance(A, colIndex, centroids, 0);
for(int i=1;i<centroids.n_cols;++i){
double curDistance=getEuclideanDistance(A, colIndex, centroids, i);
if(curDistance<lowestDistance){
lowestDistance=curDistance;
index=i+1;
}
}
return index;
}
static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){
double distance=0;
for(int i=0;i<A.n_rows;++i){
double elementA=A(i,colIndexA);
double elementB=B(i,colIndexB);
double diff=elementA-elementB;
distance+=diff*diff;
}
return sqrt(distance);
}
static mat getSqrtMat(mat A){
cx_mat result=sqrtmat(A);
return real(result);
}
static mat getSqrtMatDiag(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = sqrt(curVal);
}
return A;
}
static mat invertDiagMatrix(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = 1/curVal;
}
return A;
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME
#define TEST_CUSTOM_PACMANSAMPLEGAME
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "test_custom_pacmanSampleGame_main.h"
using namespace arma;
class test_custom_pacmanSampleGame{
public:
test_custom_pacmanSampleGame_main main;
void init()
{
main.init();
}
void execute()
{
main.execute();
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "test_custom_pacmanSampleGame_main_needsInit.h"
#include "test_custom_pacmanSampleGame_main_pacmanInit.h"
#include "test_custom_pacmanSampleGame_main_stateSaver.h"
#include "test_custom_pacmanSampleGame_main_pacmanInputControl.h"
#include "test_custom_pacmanSampleGame_main_stubby.h"
#include "test_custom_pacmanSampleGame_main_pacmanWorldManager.h"
using namespace arma;
class test_custom_pacmanSampleGame_main{
public:
test_custom_pacmanSampleGame_main_needsInit needsInit;
test_custom_pacmanSampleGame_main_pacmanInit pacmanInit;
test_custom_pacmanSampleGame_main_stateSaver stateSaver;
test_custom_pacmanSampleGame_main_pacmanInputControl pacmanInputControl;
test_custom_pacmanSampleGame_main_stubby stubby;
test_custom_pacmanSampleGame_main_pacmanWorldManager pacmanWorldManager;
void init()
{
needsInit.init();
pacmanInit.init();
stateSaver.init();
pacmanInputControl.init();
stubby.init();
pacmanWorldManager.init();
}
void execute()
{
needsInit.execute();
pacmanInit.exec = needsInit.out1;
pacmanInit.execute();
pacmanInputControl.execute();
stubby.moveDown = pacmanInputControl.moveDown;
stubby.moveUp = pacmanInputControl.moveUp;
stubby.moveLeft = pacmanInputControl.moveLeft;
stubby.moveRight = pacmanInputControl.moveRight;
stubby.execute();
stateSaver.needsInit = needsInit.out1;
stateSaver.positionX = pacmanWorldManager.pacmanNextPositionX;
stateSaver.positionY = pacmanWorldManager.pacmanNextPositionY;
stateSaver.pacmanPositionX = pacmanWorldManager.pacmanNextPositionX;
stateSaver.pacmanPositionY = pacmanWorldManager.pacmanNextPositionY;
stateSaver.execute();
pacmanWorldManager.needsInit = needsInit.out1;
pacmanWorldManager.moveDown = pacmanInputControl.moveDown;
pacmanWorldManager.moveUp = pacmanInputControl.moveUp;
pacmanWorldManager.moveLeft = pacmanInputControl.moveLeft;
pacmanWorldManager.moveRight = pacmanInputControl.moveRight;
pacmanWorldManager.pacmanPositionX = stateSaver.pacmanPositionX;
pacmanWorldManager.pacmanPositionY = stateSaver.pacmanPositionY;
pacmanWorldManager.execute();
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_NEEDSINIT
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_NEEDSINIT
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_needsInit{
public:
bool out1;
double lastVal;
void init()
{
lastVal=true;
}
void execute()
{
out1 = lastVal;
lastVal = 0;
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANINIT
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANINIT
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanInit{
public:
bool exec;
void init()
{
}
void execute()
{
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANINPUTCONTROL
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANINPUTCONTROL
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanInputControl{
public:
bool moveDown;
bool moveUp;
bool moveLeft;
bool moveRight;
void init()
{
}
void execute()
{
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanWorldManager{
const int tilesMaxX = 16;
const int tilesMaxY = 16;
public:
bool needsInit;
bool moveUp;
bool moveDown;
bool moveLeft;
bool moveRight;
int pacmanPositionX;
int pacmanPositionY;
imat world;
int pacmanNextPositionX;
int pacmanNextPositionY;
test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler pacmanWorldHandler;
void init()
{
world=imat(tilesMaxX,tilesMaxY);
pacmanWorldHandler.init();
}
void execute()
{
pacmanWorldHandler.moveUp = moveUp;
pacmanWorldHandler.moveDown = moveDown;
pacmanWorldHandler.moveLeft = moveLeft;
pacmanWorldHandler.moveRight = moveRight;
pacmanWorldHandler.pacmanPositionX = pacmanPositionX;
pacmanWorldHandler.pacmanPositionY = pacmanPositionY;
pacmanWorldHandler.world = world;
pacmanWorldHandler.execute();
pacmanNextPositionX = pacmanWorldHandler.pacmanNextPositionX;
pacmanNextPositionY = pacmanWorldHandler.pacmanNextPositionY;
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler{
const int tilesMaxX = 16;
const int tilesMaxY = 16;
public:
bool moveUp;
bool moveDown;
bool moveLeft;
bool moveRight;
int pacmanPositionX;
int pacmanPositionY;
imat world;
int pacmanNextPositionX;
int pacmanNextPositionY;
test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler movementHandler;
void init()
{
world=imat(tilesMaxX,tilesMaxY);
movementHandler.init();
}
void execute()
{
movementHandler.moveUp = moveUp;
movementHandler.moveDown = moveDown;
movementHandler.moveLeft = moveLeft;
movementHandler.moveRight = moveRight;
movementHandler.pacmanPositionX = pacmanPositionX;
movementHandler.pacmanPositionY = pacmanPositionY;
movementHandler.world = world;
movementHandler.execute();
pacmanNextPositionX = movementHandler.pacmanNextPositionX;
pacmanNextPositionY = movementHandler.pacmanNextPositionY;
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementPositionCalculator.h"
#include "test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementCollisionChecker.h"
#include "test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_controller.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler{
const int tilesMaxX = 16;
const int tilesMaxY = 16;
public:
bool moveUp;
bool moveDown;
bool moveLeft;
bool moveRight;
int pacmanPositionX;
int pacmanPositionY;
int pacmanPositionMaxX;
int pacmanPositionMaxY;
imat world;
int pacmanNextPositionX;
int pacmanNextPositionY;
test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementPositionCalculator pacmanMovementPositionCalculator;
test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementCollisionChecker pacmanMovementCollisionChecker;
test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_controller controller;
void init()
{
world=imat(tilesMaxX,tilesMaxY);
pacmanMovementPositionCalculator.init();
pacmanMovementCollisionChecker.init();
controller.init();
}
void execute()
{
pacmanMovementPositionCalculator.moveUp = moveUp;
pacmanMovementPositionCalculator.moveDown = moveDown;
pacmanMovementPositionCalculator.moveLeft = moveLeft;
pacmanMovementPositionCalculator.moveRight = moveRight;
pacmanMovementPositionCalculator.pacmanPositionX = pacmanPositionX;
pacmanMovementPositionCalculator.pacmanPositionY = pacmanPositionY;
pacmanMovementPositionCalculator.execute();
pacmanMovementCollisionChecker.world = world;
pacmanMovementCollisionChecker.pacmanPositionX = pacmanPositionX;
pacmanMovementCollisionChecker.pacmanPositionY = pacmanPositionY;
pacmanMovementCollisionChecker.pacmanPossibleNextPositionX = pacmanMovementPositionCalculator.pacmanNextPositionX;
pacmanMovementCollisionChecker.pacmanPossibleNextPositionY = pacmanMovementPositionCalculator.pacmanNextPositionY;
pacmanMovementCollisionChecker.execute();
controller.pacmanPositionX = pacmanMovementCollisionChecker.pacmanChosenNextPositionX;
controller.pacmanPositionY = pacmanMovementCollisionChecker.pacmanChosenNextPositionY;
controller.execute();
pacmanNextPositionX = pacmanMovementCollisionChecker.pacmanChosenNextPositionX;
pacmanNextPositionY = pacmanMovementCollisionChecker.pacmanChosenNextPositionY;
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER_CONTROLLER
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER_CONTROLLER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_controller{
public:
int pacmanPositionX;
int pacmanPositionY;
void init()
{
}
void execute()
{
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER_PACMANMOVEMENTCOLLISIONCHECKER
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER_PACMANMOVEMENTCOLLISIONCHECKER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementCollisionChecker{
const int tilesMaxX = 16;
const int tilesMaxY = 16;
public:
int pacmanNextPossibleTilePosition;
int pacmanOldTilePosition;
imat world;
int pacmanPositionX;
int pacmanPositionY;
int pacmanPossibleNextPositionX;
int pacmanPossibleNextPositionY;
bool canMove;
int pacmanChosenNextPositionX;
int pacmanChosenNextPositionY;
void init()
{
world=imat(tilesMaxX,tilesMaxY);
}
void execute()
{
int value = 1;
value = world(pacmanPossibleNextPositionX-1, pacmanPossibleNextPositionY-1) ;
if(((value == 1))){
canMove = 0;
pacmanChosenNextPositionX = pacmanPositionX;
pacmanChosenNextPositionY = pacmanPositionY;
}
else {
canMove = 1;
pacmanChosenNextPositionX = pacmanPossibleNextPositionX;
pacmanChosenNextPositionY = pacmanPossibleNextPositionY;
}
}
};
#endif
#ifndef TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER_PACMANMOVEMENTPOSITIONCALCULATOR
#define TEST_CUSTOM_PACMANSAMPLEGAME_MAIN_PACMANWORLDMANAGER_PACMANWORLDHANDLER_MOVEMENTHANDLER_PACMANMOVEMENTPOSITIONCALCULATOR
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class test_custom_pacmanSampleGame_main_pacmanWorldManager_pacmanWorldHandler_movementHandler_pacmanMovementPositionCalculator{
const int tilesMaxX = 16;
const int tilesMaxY = 16;
public:
bool moveUp;
bool moveDown;
bool moveLeft;
bool moveRight;
int pacmanPositionX;
int pacmanPositionY;
int pacmanPositionMaxX;
int pacmanPositionMaxY;