ProteoWizard
Namespaces | Macros | Functions
unit.hpp File Reference
#include "Exception.hpp"
#include "DateTime.hpp"
#include "Filesystem.hpp"
#include "pwiz/utility/math/round.hpp"
#include <string>
#include <sstream>
#include <cmath>
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
#include "libraries/doctest.h"

Go to the source code of this file.

Namespaces

 pwiz
 
 pwiz::util
 

Macros

#define unit_assert(x)   (!(x) ? throw std::runtime_error(unit_assert_message(__FILE__, __LINE__, #x)) : 0)
 
#define unit_assert_to_stream(x, os)   ((os) << (!(x) ? unit_assert_message(__FILE__, __LINE__, #x) + "\n" : ""))
 
#define unit_assert_operator_equal(expected, actual)   (!((expected) == (actual)) ? throw std::runtime_error(unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual)) : 0)
 
#define unit_assert_operator_equal_to_stream(expected, actual, os)   ((os) << (!((expected) == (actual)) ? unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual) + "\n" : ""))
 
#define unit_assert_equal(x, y, epsilon)   (!(fabs((x)-(y)) <= (epsilon)) ? throw std::runtime_error(unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon))) : 0)
 
#define unit_assert_equal_to_stream(x, y, epsilon, os)   ((os) << (!(fabs((x)-(y)) <= (epsilon)) ? unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon)) + "\n" : ""))
 
#define unit_assert_throws(x, exception)
 
#define unit_assert_throws_what(x, exception, whatStr)
 
#define unit_assert_matrices_equal(A, B, epsilon)   unit_assert(boost::numeric::ublas::norm_frobenius((A)-(B)) < (epsilon))
 
#define unit_assert_vectors_equal(A, B, epsilon)   unit_assert(boost::numeric::ublas::norm_2((A)-(B)) < (epsilon))
 
#define TEST_PROLOG_EX(argc, argv, suffix)
 
#define TEST_PROLOG(argc, argv)   TEST_PROLOG_EX(argc, argv, "")
 
#define TEST_FAILED(x)
 
#define TEST_EPILOG
 
#define DOCTEST_CONFIG_DISABLE
 

Functions

std::string pwiz::util::unit_assert_message (const char *filename, int line, const char *expression)
 
std::string pwiz::util::unit_assert_equal_message (const char *filename, int line, const std::string &x, const std::string &y, const char *expression)
 
std::string pwiz::util::unit_assert_numeric_equal_message (const char *filename, int line, double x, double y, double epsilon)
 
std::string pwiz::util::unit_assert_exception_message (const char *filename, int line, const char *expression, const std::string &exception)
 
std::string pwiz::util::quote_string (const string &str)
 
std::string pwiz::util::escape_teamcity_string (const std::string &str)
 

Macro Definition Documentation

◆ unit_assert

#define unit_assert (   x)    (!(x) ? throw std::runtime_error(unit_assert_message(__FILE__, __LINE__, #x)) : 0)

Definition at line 85 of file unit.hpp.

◆ unit_assert_to_stream

#define unit_assert_to_stream (   x,
  os 
)    ((os) << (!(x) ? unit_assert_message(__FILE__, __LINE__, #x) + "\n" : ""))

Definition at line 88 of file unit.hpp.

◆ unit_assert_operator_equal

#define unit_assert_operator_equal (   expected,
  actual 
)    (!((expected) == (actual)) ? throw std::runtime_error(unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual)) : 0)

Definition at line 92 of file unit.hpp.

◆ unit_assert_operator_equal_to_stream

#define unit_assert_operator_equal_to_stream (   expected,
  actual,
  os 
)    ((os) << (!((expected) == (actual)) ? unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual) + "\n" : ""))

Definition at line 95 of file unit.hpp.

◆ unit_assert_equal

#define unit_assert_equal (   x,
  y,
  epsilon 
)    (!(fabs((x)-(y)) <= (epsilon)) ? throw std::runtime_error(unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon))) : 0)

Definition at line 99 of file unit.hpp.

◆ unit_assert_equal_to_stream

#define unit_assert_equal_to_stream (   x,
  y,
  epsilon,
  os 
)    ((os) << (!(fabs((x)-(y)) <= (epsilon)) ? unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon)) + "\n" : ""))

Definition at line 102 of file unit.hpp.

◆ unit_assert_throws

#define unit_assert_throws (   x,
  exception 
)
Value:
{ \
bool threw = false; \
try { (x); } \
catch (exception&) \
{ \
threw = true; \
} \
if (!threw) \
throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, #exception)); \
}

Definition at line 106 of file unit.hpp.

◆ unit_assert_throws_what

#define unit_assert_throws_what (   x,
  exception,
  whatStr 
)
Value:
{ \
bool threw = false; \
try { (x); } \
catch (exception& e) \
{ \
if (e.what() == std::string(whatStr)) \
threw = true; \
else \
throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+quote_string(whatStr)+"\nBut a different exception was thrown: ")+quote_string(e.what())); \
} \
if (!threw) \
throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+quote_string(whatStr))); \
}

Definition at line 119 of file unit.hpp.

◆ unit_assert_matrices_equal

#define unit_assert_matrices_equal (   A,
  B,
  epsilon 
)    unit_assert(boost::numeric::ublas::norm_frobenius((A)-(B)) < (epsilon))

Definition at line 135 of file unit.hpp.

◆ unit_assert_vectors_equal

#define unit_assert_vectors_equal (   A,
  B,
  epsilon 
)    unit_assert(boost::numeric::ublas::norm_2((A)-(B)) < (epsilon))

Definition at line 139 of file unit.hpp.

◆ TEST_PROLOG_EX

#define TEST_PROLOG_EX (   argc,
  argv,
  suffix 
)
Value:
bnw::args args(argc, argv); \
std::locale global_loc = std::locale(); \
std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet); \
bfs::path::imbue(loc); \
bfs::path testName = bfs::change_extension(bfs::basename(argv[0]), (suffix)); \
string teamcityTestName = pwiz::util::escape_teamcity_string(testName.string()); \
bpt::ptime testStartTime; \
vector<string> testArgs(argv, argv+argc); \
bool teamcityTestDecoration = find(testArgs.begin(), testArgs.end(), "--teamcity-test-decoration") != testArgs.end(); \
if (teamcityTestDecoration) \
{ \
testStartTime = bpt::microsec_clock::local_time(); \
cout << "##teamcity[testStarted name='" << teamcityTestName << "']" << endl; \
} \
int testExitStatus = 0;

Definition at line 157 of file unit.hpp.

◆ TEST_PROLOG

#define TEST_PROLOG (   argc,
  argv 
)    TEST_PROLOG_EX(argc, argv, "")

Definition at line 175 of file unit.hpp.

◆ TEST_FAILED

#define TEST_FAILED (   x)
Value:
if (teamcityTestDecoration) \
cout << "##teamcity[testFailed name='" << teamcityTestName << "' message='" << pwiz::util::escape_teamcity_string((x)) << "']\n"; \
cerr << (x) << endl; \
testExitStatus = 1;

Definition at line 177 of file unit.hpp.

◆ TEST_EPILOG

#define TEST_EPILOG
Value:
if (teamcityTestDecoration) \
cout << "##teamcity[testFinished name='" << teamcityTestName << \
"' duration='" << round((bpt::microsec_clock::local_time() - testStartTime).total_microseconds() / 1000.0) << "']" << endl; \
return testExitStatus;

Definition at line 183 of file unit.hpp.

◆ DOCTEST_CONFIG_DISABLE

#define DOCTEST_CONFIG_DISABLE

Definition at line 197 of file unit.hpp.

pwiz::util::quote_string
std::string quote_string(const string &str)
Definition: unit.hpp:82
pwiz::util::unit_assert_exception_message
std::string unit_assert_exception_message(const char *filename, int line, const char *expression, const std::string &exception)
Definition: unit.hpp:75
x
KernelTraitsBase< Kernel >::space_type::abscissa_type x
Definition: MatchedFilter.hpp:142
pwiz::util::escape_teamcity_string
std::string escape_teamcity_string(const std::string &str)
Definition: unit.hpp:145