Remove filesAreEquals tests, use integration test instead

parent 089cc399
......@@ -76,8 +76,6 @@ public class GenerationTest extends AbstractSymtabTest {
middlewareGenerator.add(new CPPGenImpl(), "cpp");
List<File> files = middlewareGenerator.generate(componentInstanceSymbol, taggingResolver);
testFilesAreEqual(files, "CMakeCppOnly/src/", generationTargetPath);
}
@Test
......@@ -102,8 +100,6 @@ public class GenerationTest extends AbstractSymtabTest {
distributedTargetGenerator.add(new RosCppGenImpl(), "roscpp");
List<File> files = distributedTargetGenerator.generate(componentInstanceSymbol, taggingResolver);
testFilesAreEqual(files, "system/src/", generationTargetPath);
}
@Test
......
cmake_minimum_required(VERSION 3.5)
project (default)
set (CMAKE_CXX_STANDARD 11)
add_subdirectory(coordinator/)
add_subdirectory(cpp)
cmake_minimum_required(VERSION 3.5)
project (Coordinator_tests_a_addComp CXX)
set (CMAKE_CXX_STANDARD 11)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(Coordinator_tests_a_addComp Coordinator_tests_a_addComp.cpp)
set_target_properties(Coordinator_tests_a_addComp PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(Coordinator_tests_a_addComp tests_a_addComp Threads::Threads)
target_include_directories(Coordinator_tests_a_addComp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
export(TARGETS Coordinator_tests_a_addComp FILE Coordinator_tests_a_addComp.cmake)
\ No newline at end of file
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
#include <list>
#include "IAdapter_tests_a_addComp.h"
#include "tests_a_addComp.h"
using namespace std;
using namespace chrono;
static int exeMs = 100;
bool parseCommandLineParameters(int argc, char* argv[]){
if(argc == 1){
return true;
}
if(argc == 3 && string(argv[1]) == "-t"){
try{
int tmp = stoi(argv[2]);
if(tmp >= 0){
exeMs = tmp;
return true;
}
}catch(...){
//Ignore
}
}
cout << "Usage: " << argv[0] << " [-h | -t sleepTimeMs]\n";
return false;
}
void startMiddleware(IAdapter_tests_a_addComp& adapter,tests_a_addComp& comp,atomic<bool>& done){
adapter.init(&comp);
done = true;
}
int main(int argc, char* argv[])
{
if(!parseCommandLineParameters(argc,argv)){
return 1;
}
atomic<bool> done(false);
tests_a_addComp comp;
comp.init();
list<IAdapter_tests_a_addComp*> adapters;
list<thread*> threads;
for(auto a : adapters){
threads.push_back(new thread(startMiddleware,ref(*a),ref(comp),ref(done)));
}
cout << "waiting for all middleware to start\n";
this_thread::sleep_for(seconds(3));
cout << "started! Executing every " << exeMs << "ms\n";
time_point<system_clock> start, end;
while(!done){
start = system_clock::now();
comp.execute();
for(auto a : adapters){
(*a).tick();
}
end = system_clock::now();
int elapsedMs = duration_cast<milliseconds>(end-start).count();
int newSleep = exeMs - elapsedMs;
if(newSleep <= 0){
cout << "Cant keep up! "<< (-newSleep) <<"ms late!\n";
}else{
this_thread::sleep_for(milliseconds(newSleep));
}
}
return 0;
}
\ No newline at end of file
#pragma once
#include "tests_a_addComp.h"
class IAdapter_tests_a_addComp{
public:
virtual ~IAdapter_tests_a_addComp(){}
virtual void init(tests_a_addComp* comp) = 0;
virtual void tick() = 0;
};
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(tests_a_addComp LANGUAGES CXX)
#set cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# add dependencies
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional commands
# create static library
include_directories(${INCLUDE_DIRS})
add_library(tests_a_addComp tests_a_addComp.h)
target_include_directories(tests_a_addComp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(tests_a_addComp PUBLIC ${LIBS})
set_target_properties(tests_a_addComp PROPERTIES LINKER_LANGUAGE CXX)
# export cmake project
export(TARGETS tests_a_addComp FILE tests_a_addComp.cmake)
# additional commands end
# Automatically generated file
#
# - Try to find Armadillo
# Once done this will define
# Armadillo_FOUND - System has Armadillo
# Armadillo_INCLUDE_DIRS - The Armadillo include directories
# Armadillo_LIBRARY_DIRS - The library directories needed to use Armadillo
# Armadillo_LIBRARIES - The libraries needed to use Armadillo
find_path(Armadillo_INCLUDE_DIR
NAMES armadillo
PATH_SUFFIXES "include"
PATHS
HINTS $ENV{Armadillo_HOME}
)
find_library(Armadillo_LIBRARY
NAMES armadillo
PATH_SUFFIXES "lib" "lib64" "lib/x86_64-linux-gnu" "examples/lib_win64" "build" "Release"
PATHS
HINTS $ENV{Armadillo_HOME}
)
include(FindPackageHandleStandardArgs)
# if all listed variables are TRUE
find_package_handle_standard_args(
Armadillo
DEFAULT_MSG
Armadillo_INCLUDE_DIR
Armadillo_LIBRARY
)
mark_as_advanced(
Armadillo_INCLUDE_DIR
Armadillo_LIBRARY
)
set(Armadillo_INCLUDE_DIRS ${Armadillo_INCLUDE_DIR})
set(Armadillo_LIBRARIES ${Armadillo_LIBRARY})
\ No newline at end of file
#ifndef TESTS_A_ADDCOMP
#define TESTS_A_ADDCOMP
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class tests_a_addComp{
public:
double in1;
double in2;
double out1;
void init()
{
}
void execute()
{
out1 = in1+in2;
}
};
#endif
cmake_minimum_required(VERSION 3.5)
project (default)
set (CMAKE_CXX_STANDARD 11)
add_subdirectory(rosMsg)
add_subdirectory(ba_system_velocityController_2_)
add_subdirectory(ba_system_stopCommQuality_2_)
add_subdirectory(ba_system_stopCommQuality_1_)
add_subdirectory(ba_system_velocityController_1_)
add_subdirectory(ba_system_collisionDetection)
add_subdirectory(ba_system_intersectionController)
cmake_minimum_required(VERSION 3.5)
project (default)
set (CMAKE_CXX_STANDARD 11)
add_subdirectory(coordinator/)
add_subdirectory(cpp)
add_subdirectory(roscpp)
cmake_minimum_required(VERSION 3.5)
project (Coordinator_ba_system_collisionDetection CXX)
set (CMAKE_CXX_STANDARD 11)
set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
add_executable(Coordinator_ba_system_collisionDetection Coordinator_ba_system_collisionDetection.cpp)
set_target_properties(Coordinator_ba_system_collisionDetection PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(Coordinator_ba_system_collisionDetection RosAdapter_ba_system_collisionDetection ba_system_collisionDetection Threads::Threads)
target_include_directories(Coordinator_ba_system_collisionDetection PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
export(TARGETS Coordinator_ba_system_collisionDetection FILE Coordinator_ba_system_collisionDetection.cmake)
\ No newline at end of file
#include <iostream>
#include <thread>
#include <chrono>
#include <atomic>
#include <list>
#include "IAdapter_ba_system_collisionDetection.h"
#include "RosAdapter_ba_system_collisionDetection.h"
#include "ba_system_collisionDetection.h"
using namespace std;
using namespace chrono;
static int exeMs = 100;
bool parseCommandLineParameters(int argc, char* argv[]){
if(argc == 1){
return true;
}
if(argc == 3 && string(argv[1]) == "-t"){
try{
int tmp = stoi(argv[2]);
if(tmp >= 0){
exeMs = tmp;
return true;
}
}catch(...){
//Ignore
}
}
cout << "Usage: " << argv[0] << " [-h | -t sleepTimeMs]\n";
return false;
}
void startMiddleware(IAdapter_ba_system_collisionDetection& adapter,ba_system_collisionDetection& comp,atomic<bool>& done){
adapter.init(&comp);
done = true;
}
int main(int argc, char* argv[])
{
if(!parseCommandLineParameters(argc,argv)){
return 1;
}
atomic<bool> done(false);
ba_system_collisionDetection comp;
comp.init();
list<IAdapter_ba_system_collisionDetection*> adapters;
adapters.push_back(new RosAdapter_ba_system_collisionDetection());
list<thread*> threads;
for(auto a : adapters){
threads.push_back(new thread(startMiddleware,ref(*a),ref(comp),ref(done)));
}
cout << "waiting for all middleware to start\n";
this_thread::sleep_for(seconds(3));
cout << "started! Executing every " << exeMs << "ms\n";
time_point<system_clock> start, end;
while(!done){
start = system_clock::now();
comp.execute();
for(auto a : adapters){
(*a).tick();
}
end = system_clock::now();
int elapsedMs = duration_cast<milliseconds>(end-start).count();
int newSleep = exeMs - elapsedMs;
if(newSleep <= 0){
cout << "Cant keep up! "<< (-newSleep) <<"ms late!\n";
}else{
this_thread::sleep_for(milliseconds(newSleep));
}
}
return 0;
}
\ No newline at end of file
#pragma once
#include "ba_system_collisionDetection.h"
class IAdapter_ba_system_collisionDetection{
public:
virtual ~IAdapter_ba_system_collisionDetection(){}
virtual void init(ba_system_collisionDetection* comp) = 0;
virtual void tick() = 0;
};
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
project(ba_system_collisionDetection LANGUAGES CXX)
#set cmake module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# add dependencies
find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional commands
# create static library
include_directories(${INCLUDE_DIRS})
add_library(ba_system_collisionDetection ba_system_collisionDetection.h)
target_include_directories(ba_system_collisionDetection PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(ba_system_collisionDetection PUBLIC ${LIBS})
set_target_properties(ba_system_collisionDetection PROPERTIES LINKER_LANGUAGE CXX)
# export cmake project
export(TARGETS ba_system_collisionDetection FILE ba_system_collisionDetection.cmake)
# additional commands end
#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 BA_SYSTEM_COLLISIONDETECTION
#define BA_SYSTEM_COLLISIONDETECTION
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "types/ba_struct_Rectangle.h"
#include "ba_system_collisionDetection_singleSetCompareRect.h"
#include "ba_system_collisionDetection_rectIntersection_1_.h"
#include "ba_system_collisionDetection_multiOr.h"
using namespace arma;
class ba_system_collisionDetection{
const int n = 2;
const int x = 1;
public:
ba_struct_Rectangle hulls[2];
bool collision;
ba_system_collisionDetection_singleSetCompareRect singleSetCompareRect;
ba_system_collisionDetection_rectIntersection_1_ rectIntersection[1];
ba_system_collisionDetection_multiOr multiOr;
void init()
{
singleSetCompareRect.init();
rectIntersection[0].init();
multiOr.init();
}
void execute()
{
singleSetCompareRect.setIn[0] = hulls[0];
singleSetCompareRect.setIn[1] = hulls[1];
singleSetCompareRect.execute();
rectIntersection[0].rect1 = singleSetCompareRect.outA[0];
rectIntersection[0].rect2 = singleSetCompareRect.outB[0];
rectIntersection[0].execute();
multiOr.boolIn[0] = rectIntersection[0].collision;
multiOr.execute();
collision = multiOr.boolOut;
}
};
#endif
#ifndef BA_SYSTEM_COLLISIONDETECTION_MULTIOR
#define BA_SYSTEM_COLLISIONDETECTION_MULTIOR
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
using namespace arma;
class ba_system_collisionDetection_multiOr{
const int x = 1;
public:
bool boolIn[1];
bool boolOut;
void init()
{
}
void execute()
{
bool flag = false;
for( auto i=1;i<=x;++i){
flag = flag||boolIn[i-1];
}
boolOut = flag;
}