Commit 705fed8e authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Adapt test cases

parent b5358cb5
Pipeline #107716 passed with stages
in 35 minutes and 10 seconds
......@@ -5,7 +5,7 @@
#include <iostream>
<#list viewModel.includes as i>
#include "${i}"
#include "${i}"
</#list>
int main(){
......
......@@ -58,6 +58,6 @@ public class TestsGenTest extends AbstractSymtabTest {
Set<File> files = new HashSet<>(generatorCPP.generateFiles(symTab, componentSymbol, symTab));
// assertEquals(18, files.size());
assertEquals(14, files.size()); // TODO: check if 14 is correct here?
assertEquals(13, files.size()); // TODO: check if 14 is correct here?
}
}
......@@ -33,4 +33,4 @@ set_target_properties(test_basicPortsMath_StreamTests PROPERTIES LINKER_LANGUAG
# execute tests
add_custom_target(run_test_basicPortsMath_StreamTests ALL
COMMAND test_basicPortsMath_StreamTests
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
\ No newline at end of file
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
......@@ -4,7 +4,49 @@
#include "armadillo.h"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
bool close(false);
if(arma::max(arma::max(arma::abs(X-Y))) < tol)
{
close = true;
}
return close;
}
#endif
class HelperA{
public:
static mat getEigenVectors(mat A){
......
//created by ComponentStreamTest2.ftl
#ifndef TEST_BASICPORTSMATH_TEST
#define TEST_BASICPORTSMATH_TEST
#include "catch.hpp"
//#include "catch.hpp"
#include "../test_basicPortsMath.h"
#include <iostream>
#include <fstream>
#include <string>
/*void toFileString(std::ofstream& myfile, mat A){
namespace test_basicPortsMath_test{
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
......@@ -33,7 +37,8 @@ void toFileString(std::ofstream& myfile, int A){
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
bool isClose(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
......@@ -44,20 +49,59 @@ bool Is_close(mat& X, mat& Y, double tol)
}
return close;
}
int overallAssertions = 0;
int overallFailedAssertions = 0;
int assertions = 0;
int failedAssertions = 0;
void require_is_close(mat& A, mat& lower, double tol){
assertions++;
if(!isClose(A, lower, tol)){
std::cout << "Failed at: isClose(" << A << ", " << lower << ", " << tol << std::endl;
failedAssertions++;
}
}
void require_boolean(bool a){
assertions++;
if(!a){
std::cout << "Failed at: " << a << " != true" << std::endl;
failedAssertions++;
}
}
void require_boolean_false(bool a){
assertions++;
if(a){
std::cout << "Failed at: " << a << " != false" << std::endl;
failedAssertions++;
}
}
void require_lower_or_equals(double a, double b){
assertions++;
if(a > b){
std::cout << "Failed at: " << a << " <= " << b << std::endl;
failedAssertions++;
}
}
void rangeValueCheck(double A, double lower, double upper){
REQUIRE( A >= lower );
REQUIRE( A <= upper );
require_lower_or_equals(lower, A);
require_lower_or_equals(A, upper);
}
void rangeValueCheck(int A, double lower, double upper){
REQUIRE( A >= lower );
REQUIRE( A <= upper );
require_lower_or_equals(lower, A);
require_lower_or_equals(A, upper);
}
void rangeValueCheck(mat& A, mat& lower , mat& upper){
REQUIRE(Is_close(A, lower, 0.0001));
REQUIRE(Is_close(A, upper, 0.0001));
}*/
TEST_CASE("test.BasicPortsMath", "[test_basicPortsMath]") {
require_is_close(A, lower, 0.0001);
require_is_close(A, upper, 0.0001);
}
void test_case_test_BasicPortsMath(){
mat tmpA;
mat tmpB;
test_basicPortsMath component;
......@@ -111,6 +155,22 @@ TEST_CASE("test.BasicPortsMath", "[test_basicPortsMath]") {
std::cout << "test.BasicPortsMath: success\n";
}
int runTest(){
assertions = 0;
failedAssertions = 0;
test_case_test_BasicPortsMath();
overallAssertions += assertions;
overallFailedAssertions += failedAssertions;
if(overallFailedAssertions == 0){
std::cout << "All tests passed! Made " << overallAssertions << " assertions." << std::endl;
return 0;
}else{
std::cout << "There are failed tests! Failed " << overallFailedAssertions << " of " << overallAssertions << " assertions." << std::endl;
return 1;
}
}
}
#endif
//created by TestsMainEntry.ftl
#ifndef TESTS_MAIN
#define TESTS_MAIN
//#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_FAST_COMPILE
#include "catch.hpp"
/*
int main(int argc, char* argv[]) {
Catch::Session session;
int returnCode = session.applyCommandLine(argc, argv);
if (returnCode != 0) {
return returnCode;
}
int numFailed = session.run();
return numFailed;
}*/
#include <iostream>
#include "test_basicPortsMath_test.hpp"
int main(){
std::cout << "=================Start stream testing=================" << std::endl;
int errorCode = 0;
errorCode += test_basicPortsMath_test::runTest();
std::cout << "==================End stream testing==================" << std::endl;
exit(errorCode);
}
#endif
......@@ -29,3 +29,8 @@ add_executable(test_math_floatDivisionTest_StreamTests test/tests_main.cpp)
target_compile_definitions(test_math_floatDivisionTest_StreamTests PRIVATE CATCH_CONFIG_MAIN=1 ARMA_DONT_USE_WRAPPER)
target_link_libraries(test_math_floatDivisionTest_StreamTests PUBLIC test_math_floatDivisionTest)
set_target_properties(test_math_floatDivisionTest_StreamTests PROPERTIES LINKER_LANGUAGE CXX)
# execute tests
add_custom_target(run_test_math_floatDivisionTest_StreamTests ALL
COMMAND test_math_floatDivisionTest_StreamTests
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
......@@ -4,7 +4,49 @@
#include "armadillo.h"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
bool close(false);
if(arma::max(arma::max(arma::abs(X-Y))) < tol)
{
close = true;
}
return close;
}
#endif
class HelperA{
public:
static mat getEigenVectors(mat A){
......
//created by ComponentStreamTest2.ftl
#ifndef TEST_MATH_FLOATDIVISIONTEST_TEST
#define TEST_MATH_FLOATDIVISIONTEST_TEST
#include "catch.hpp"
//#include "catch.hpp"
#include "../test_math_floatDivisionTest.h"
#include <iostream>
#include <fstream>
#include <string>
/*void toFileString(std::ofstream& myfile, mat A){
namespace test_math_floatDivisionTest_test{
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
......@@ -33,7 +37,8 @@ void toFileString(std::ofstream& myfile, int A){
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
bool isClose(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
......@@ -44,20 +49,59 @@ bool Is_close(mat& X, mat& Y, double tol)
}
return close;
}
int overallAssertions = 0;
int overallFailedAssertions = 0;
int assertions = 0;
int failedAssertions = 0;
void require_is_close(mat& A, mat& lower, double tol){
assertions++;
if(!isClose(A, lower, tol)){
std::cout << "Failed at: isClose(" << A << ", " << lower << ", " << tol << std::endl;
failedAssertions++;
}
}
void require_boolean(bool a){
assertions++;
if(!a){
std::cout << "Failed at: " << a << " != true" << std::endl;
failedAssertions++;
}
}
void require_boolean_false(bool a){
assertions++;
if(a){
std::cout << "Failed at: " << a << " != false" << std::endl;
failedAssertions++;
}
}
void require_lower_or_equals(double a, double b){
assertions++;
if(a > b){
std::cout << "Failed at: " << a << " <= " << b << std::endl;
failedAssertions++;
}
}
void rangeValueCheck(double A, double lower, double upper){
REQUIRE( A >= lower );
REQUIRE( A <= upper );
require_lower_or_equals(lower, A);
require_lower_or_equals(A, upper);
}
void rangeValueCheck(int A, double lower, double upper){
REQUIRE( A >= lower );
REQUIRE( A <= upper );
require_lower_or_equals(lower, A);
require_lower_or_equals(A, upper);
}
void rangeValueCheck(mat& A, mat& lower , mat& upper){
REQUIRE(Is_close(A, lower, 0.0001));
REQUIRE(Is_close(A, upper, 0.0001));
}*/
TEST_CASE("test.math.FloatDivisionTest", "[test_math_floatDivisionTest]") {
require_is_close(A, lower, 0.0001);
require_is_close(A, upper, 0.0001);
}
void test_case_test_math_FloatDivisionTest(){
mat tmpA;
mat tmpB;
test_math_floatDivisionTest component;
......@@ -78,6 +122,22 @@ TEST_CASE("test.math.FloatDivisionTest", "[test_math_floatDivisionTest]") {
std::cout << "test.math.FloatDivisionTest: success\n";
}
int runTest(){
assertions = 0;
failedAssertions = 0;
test_case_test_math_FloatDivisionTest();
overallAssertions += assertions;
overallFailedAssertions += failedAssertions;
if(overallFailedAssertions == 0){
std::cout << "All tests passed! Made " << overallAssertions << " assertions." << std::endl;
return 0;
}else{
std::cout << "There are failed tests! Failed " << overallFailedAssertions << " of " << overallAssertions << " assertions." << std::endl;
return 1;
}
}
}
#endif
//created by TestsMainEntry.ftl
#ifndef TESTS_MAIN
#define TESTS_MAIN
//#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_FAST_COMPILE
#include "catch.hpp"
/*
int main(int argc, char* argv[]) {
Catch::Session session;
int returnCode = session.applyCommandLine(argc, argv);
if (returnCode != 0) {
return returnCode;
}
int numFailed = session.run();
return numFailed;
}*/
#include <iostream>
#include "test_math_floatDivisionTest_test.hpp"
int main(){
std::cout << "=================Start stream testing=================" << std::endl;
int errorCode = 0;
errorCode += test_math_floatDivisionTest_test::runTest();
std::cout << "==================End stream testing==================" << std::endl;
exit(errorCode);
}
#endif
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