Coryab/create tests #4
@ -35,6 +35,8 @@
|
|||||||
#define DEBUG(msg)
|
#define DEBUG(msg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ASSERT(expr) m_assert(expr, #expr, __FUNCTION__, __FILE__, __LINE__)
|
||||||
|
|
||||||
/** Code stolen from https://github.com/anderkve/FYS3150
|
/** Code stolen from https://github.com/anderkve/FYS3150
|
||||||
* Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp
|
* Header: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/include/utils.hpp
|
||||||
* Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp
|
* Source: https://github.com/anderkve/FYS3150/blob/master/code_examples/compilation_linking/example_1/src/utils.cpp
|
||||||
@ -62,4 +64,6 @@ std::string scientific_format(const std::vector<double>& v,
|
|||||||
int width=20,
|
int width=20,
|
||||||
int prec=10);
|
int prec=10);
|
||||||
|
|
||||||
|
void m_assert(bool expr, const char* expr_str, const char* func, const char* file, int line);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
* @bug No known bugs
|
* @bug No known bugs
|
||||||
* */
|
* */
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
std::string scientific_format(double d, int width, int prec)
|
std::string scientific_format(double d, int width, int prec)
|
||||||
{
|
{
|
||||||
@ -26,3 +28,20 @@ std::string scientific_format(const std::vector<double>& v, int width, int prec)
|
|||||||
}
|
}
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void m_assert(bool expr,
|
||||||
|
const char* expr_str,
|
||||||
|
const char* f,
|
||||||
|
const char* file,
|
||||||
|
int line)
|
||||||
|
{
|
||||||
|
printf("%s: ", f);
|
||||||
|
if (expr) {
|
||||||
|
printf("\x1B[32mOK\033[0m\n\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("\x1B[31mFAIL\033[0m\n\n");
|
||||||
|
printf("%s %d: Assertion (%s) Failed\n\n", file, line, expr_str);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user