This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/Assertions.h
FrankE d283d9b326 geometry changes/fixes/new features
new grid walkers + fixes
new test-cases
worked on step/and turn detection
android offline-data-reader
worked on vap-grouping
2016-09-07 10:16:51 +02:00

81 lines
2.2 KiB
C++

#ifndef ASSERTIONS_H
#define ASSERTIONS_H
#include "Exception.h"
#include <sstream>
#include <cmath>
// for GTEST Testcases
#define FRIEND_TEST(test_case_name, test_name)\
friend class test_case_name##_##test_name##_Test
/**
* this file provides assertion methods that may be enabled to trace
* coding errors efficiently during debug or disabled to speed up the
* code execution for the release build
*
* compile with -DWITH_ASSERTIONS
*/
namespace Assert {
template <typename STR> static inline void doThrow(const STR err) {
#ifdef WITH_ASSERTIONS
std::string str = "in: ";
str += __PRETTY_FUNCTION__;
str += " error: ";
str += err;
throw Exception(err);
#else
(void) err;
#endif
}
template <typename T, typename STR> static inline void equal(const T v1, const T v2, const STR err) {
if (v1 != v2) {doThrow(err);}
}
template <typename T, typename STR> static inline void notEqual(const T v1, const T v2, const STR err) {
if (v1 == v2) {doThrow(err);}
}
template <typename T, typename STR> static inline void isTrue(const T v, const STR err) {
if (!v) {doThrow(err);}
}
template <typename T, typename STR> static inline void isFalse(const T v, const STR err) {
if (v) {doThrow(err);}
}
template <typename T, typename STR> static inline void isNull(const T v, const STR err) {
if (v != nullptr) {doThrow(err);}
}
template <typename T, typename STR> static inline void isNotNull(const T v, const STR err) {
if (v == nullptr) {doThrow(err);}
}
template <typename T, typename STR> static inline void isNotNaN(const T v, const STR err) {
if (v != v) {doThrow(err);}
}
template <typename T, typename STR> static inline void isNot0(const T v, const STR err) {
if (v == 0) {doThrow(err);}
}
template <typename T, typename STR> static inline void isNear(const T v1, const T v2, const T delta, const STR err) {
if (std::abs(v1-v2) > delta) {doThrow(err);}
}
template <typename T, typename STR> static inline void isBetween(const T v, const T min, const T max, const STR err) {
if (v < min || v > max) {
std::stringstream ss; ss << "\n[" << min << ":" << max << "] but is " << v << "\n";
doThrow(err+ss.str());
}
}
}
#endif // ASSERTIONS_H