Commit 13e47a52 authored by Nick Thompson's avatar Nick Thompson
Browse files

Explain the return of std::ostream&.

parent 4869b674
Pipeline #223392 failed with stages
in 88 minutes and 52 seconds
......@@ -97,18 +97,24 @@ namespace testing
namespace
{
static std::atomic<vtkm::Id> error_count{ 0 };
// I have verified that there is no performance overhead to returning cnull
// when optional streaming output is not used. There is a moderate performance
// overhead when the optional streaming output is used, but not printed as the test passes.
// I ran it 100,000,000 times returning bool and if printing the optional message, and it took .22 seconds.
// Then I ran it returning cnull with passing tests and an optional message, and it took 1.2 seconds.
// So it seems like it's a reasonable price to pay to unify the syntax with the (familiar) syntax of googletest.
static std::ostream cnull(nullptr);
}
template <class Real>
std::ostream& CheckULPCloseUniformTypes(Real expected,
Real computed,
vtkm::UInt64 ulps,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
Real computed,
vtkm::UInt64 ulps,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
{
static_assert(
std::is_floating_point<Real>::value,
......@@ -139,13 +145,13 @@ std::ostream& CheckULPCloseUniformTypes(Real expected,
template <class Real1, class Real2>
std::ostream& CheckULPClose(Real1 expected,
Real2 computed,
vtkm::UInt64 ulps,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
Real2 computed,
vtkm::UInt64 ulps,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
{
// This restiction could be lifted with an if constexpr,
// for instance it might be nice to call it with an integer as the "exact" argument.
......@@ -165,13 +171,13 @@ std::ostream& CheckULPClose(Real1 expected,
template <class Real>
std::ostream& CheckAbsClose(Real expected,
Real computed,
Real acceptable_distance,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
Real computed,
Real acceptable_distance,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
{
// Obviously the floating point assertion here could be lifted,
// but this causes recompilation of the entire universe,
......@@ -208,12 +214,12 @@ std::ostream& CheckAbsClose(Real expected,
template <class T>
std::ostream& CheckEqual(T expected,
T computed,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
T computed,
const char* filename,
const char* function,
int line,
const char* expected_string,
const char* computed_string)
{
if (expected == computed)
{
......@@ -232,7 +238,7 @@ std::ostream& CheckEqual(T expected,
<< " = " << std::scientific << expected << " = " << std::hexfloat << expected << "\n";
std::cerr << "\tThe second argument \"" << computed_string << "\" is\n\t\t" << std::fixed
<< computed << " = " << std::scientific << computed << " = " << std::hexfloat
<< computed << "\n";
<< computed;
}
else if (std::is_integral<T>::value)
{
......@@ -240,13 +246,15 @@ std::ostream& CheckEqual(T expected,
<< std::bitset<8 * sizeof(T)>(expected) << "\n";
std::cerr << "\tThe second argument \"" << computed_string << "\" is\n\t\t" << std::dec
<< computed << " = " << std::hex << "0x" << computed << " = 0b"
<< std::bitset<8 * sizeof(T)>(computed) << "\n";
<< std::bitset<8 * sizeof(T)>(computed);
}
else {
// We know nothing about this type; just use the standard overload for <<:s
else
{
// We know nothing about this type; just use the standard overloaded <<.
std::cerr << expected << "\n";
std::cerr << "\tThe second argument \"" << computed_string << "\" is\n\t\t" << computed << "\n";
std::cerr << "\tThe second argument \"" << computed_string << "\" is\n\t\t" << computed;
}
std::cerr << "\n";
std::cerr.flags(f);
++error_count;
return std::cerr;
......
Supports Markdown
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