tap: use fmtlib specifiers
This commit is contained in:
parent
4848178cc7
commit
a94cd677bd
11
tap.hpp
11
tap.hpp
@ -9,8 +9,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "except.hpp"
|
||||
#include "format.hpp"
|
||||
#include "maths.hpp"
|
||||
#include "debug/validate.hpp"
|
||||
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <functional>
|
||||
@ -50,10 +52,11 @@ namespace cruft::TAP {
|
||||
bool
|
||||
expect (const bool test, const char (&fmt)[N], Args&&... args)
|
||||
{
|
||||
CHECK (!strstr (fmt, "%"));
|
||||
m_output << (test ? "ok " : "not ok ") << ++m_size
|
||||
<< " - "
|
||||
<< format::printf (fmt) (std::forward<Args> (args)...)
|
||||
<< std::endl;
|
||||
<< " - ";
|
||||
fmt::print (m_output, fmt, std::forward<Args> (args)...);
|
||||
m_output << std::endl;
|
||||
|
||||
if (!test)
|
||||
m_status = EXIT_FAILURE;
|
||||
|
@ -138,7 +138,7 @@ test_perspective (cruft::TAP::logger &tap)
|
||||
|
||||
tap.expect (
|
||||
cruft::relatively_equal (m, p, 1e-7f),
|
||||
"perspective %!:%!@%!",
|
||||
"perspective {}:{}@{}",
|
||||
t.w, t.h, t.fov
|
||||
);
|
||||
}
|
||||
@ -163,7 +163,7 @@ test_mq_axis (cruft::TAP::logger &tap)
|
||||
auto q = cruft::quaternionf::angle_axis (1, t.euler);
|
||||
|
||||
auto diff = sum (abs (m - q.as_matrix ()));
|
||||
tap.expect_le (diff, 1e-6f, "matrix/quaternion rotation identities, %s", t.msg);
|
||||
tap.expect_le (diff, 1e-6f, "matrix/quaternion rotation identities, {:s}", t.msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ test_mq_euler (cruft::TAP::logger &tap)
|
||||
).as_matrix ();
|
||||
|
||||
auto diff = cruft::sum (abs (m - q));
|
||||
tap.expect_le (diff, 1e-6f, "matrix-quaternion xyz euler rotations, %s", t.msg);
|
||||
tap.expect_le (diff, 1e-6f, "matrix-quaternion xyz euler rotations, {:s}", t.msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ main (int, char**)
|
||||
[] (int a, int b) { return a < b; }
|
||||
);
|
||||
|
||||
tap.expect (std::is_sorted (std::cbegin (t.values), std::cend (t.values)), "%s", t.msg);
|
||||
tap.expect (std::is_sorted (std::cbegin (t.values), std::cend (t.values)), "{:s}", t.msg);
|
||||
}
|
||||
|
||||
// Check that SOA sort works with multiple value arrays
|
||||
|
@ -41,7 +41,7 @@ main (int, char**)
|
||||
!(result[2] % alignment) &&
|
||||
!(result[3] % alignment),
|
||||
|
||||
"allocations make alignment of %zu", alignment
|
||||
"allocations make alignment of {}", alignment
|
||||
);
|
||||
|
||||
return tap.status ();
|
||||
|
@ -47,7 +47,7 @@ main ()
|
||||
for (const auto &t: TESTS) {
|
||||
auto ptr = reinterpret_cast<uintptr_t> (alloc.allocate (t.size).data ());
|
||||
auto offset = ptr - reinterpret_cast<uintptr_t> (base);
|
||||
tap.expect_mod (offset, alignment, "%s", t.message);
|
||||
tap.expect_mod (offset, alignment, "{:s}", t.message);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -62,7 +62,7 @@ main (int, char**)
|
||||
|
||||
tap.expect (
|
||||
is_digit && is_hex && is_upper && is_lower && is_space && integer && hexadecimal,
|
||||
"%s", t.msg
|
||||
"{:s}", t.msg
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -85,13 +85,13 @@ test_bool (cruft::TAP::logger &tap)
|
||||
for (auto i: positive) {
|
||||
argv[2] = i;
|
||||
p.scan (argv.size (), argv.data ());
|
||||
tap.expect_eq (value, true, "read bool, %s", i);
|
||||
tap.expect_eq (value, true, "read bool, {:s}", i);
|
||||
}
|
||||
|
||||
for (auto i: negative) {
|
||||
argv[2] = i;
|
||||
p.scan (argv.size (), argv.data ());
|
||||
tap.expect_eq (value, false, "read bool, %s", i);
|
||||
tap.expect_eq (value, false, "read bool, {:s}", i);
|
||||
}
|
||||
|
||||
// Check that invalid forms of boolean all throw exceptions
|
||||
@ -101,7 +101,7 @@ test_bool (cruft::TAP::logger &tap)
|
||||
argv[2] = i;
|
||||
tap.expect_throw<cruft::cmdopt::invalid_value> ([&] () {
|
||||
p.scan (argv.size (), argv.data ());
|
||||
}, "invalid bool, %s", i);
|
||||
}, "invalid bool, {:s}", i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ test_bytes (cruft::TAP::logger &tap)
|
||||
argv[2] = i.str;
|
||||
p.scan (std::size (argv), argv);
|
||||
|
||||
tap.expect_eq (i.val, size, "bytes, %s", i.str);
|
||||
tap.expect_eq (i.val, size, "bytes, {:s}", i.str);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ main (void)
|
||||
};
|
||||
|
||||
for (auto const &t: TESTS)
|
||||
tap.expect (cruft::coord::element_ordering (t.a, t.b) == t.expected, "ordering; %!", t.message);
|
||||
tap.expect (cruft::coord::element_ordering (t.a, t.b) == t.expected, "ordering; {}", t.message);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -84,7 +84,7 @@ test_size (cruft::TAP::logger &tap)
|
||||
tap.expect_eq (
|
||||
encoded,
|
||||
output_v<Size>[i],
|
||||
"%! character base%! encode; '%!' is '%!'", i, Size, encoded, output_v<Size>[i]
|
||||
"{} character base{} encode; '{}' is '{}'", i, Size, encoded, output_v<Size>[i]
|
||||
);
|
||||
|
||||
|
||||
@ -94,7 +94,7 @@ test_size (cruft::TAP::logger &tap)
|
||||
cruft::make_view (encoded)
|
||||
);
|
||||
|
||||
tap.expect_eq (decoded, fragment, "%! character base%! decode, '%!'", i, Size, decoded);
|
||||
tap.expect_eq (decoded, fragment, "{} character base{} decode, '{}'", i, Size, decoded);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "encode/number.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
@ -22,7 +24,7 @@ int main ()
|
||||
for (auto const &t: TESTS) {
|
||||
// decode the truth string and test against the truth number
|
||||
cruft::view src (t.str);
|
||||
tap.expect_eq (cruft::encode::decode36<unsigned> (src), t.value, "base36 decode '%!'", t.str);
|
||||
tap.expect_eq (cruft::encode::decode36<unsigned> (src), t.value, "base36 decode '{}'", t.str);
|
||||
|
||||
// encode the truth number
|
||||
std::ostringstream dst;
|
||||
@ -35,7 +37,7 @@ int main ()
|
||||
std::transform (encoded_truth.begin (), encoded_truth.end (), encoded_truth.begin (), ::tolower);
|
||||
|
||||
// compare lower case encoded strings
|
||||
tap.expect_eq (encoded_computed, encoded_truth, "base36 encode '%!'", t.value);
|
||||
tap.expect_eq (encoded_computed, encoded_truth, "base36 encode '{}'", t.value);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -22,7 +22,7 @@ main (int, char **argv)
|
||||
tap.expect_eq (
|
||||
query.stem (),
|
||||
truth.stem (),
|
||||
"identify executable path # %!", query
|
||||
"identify executable path # {}", query
|
||||
);
|
||||
|
||||
return tap.status ();
|
||||
|
@ -20,19 +20,19 @@ test_simple (cruft::TAP::logger &tap)
|
||||
std::ostringstream os;
|
||||
os << "fixed<" << type_to_string<T> () << ',' << I << ',' << E << '>';
|
||||
|
||||
tap.expect_eq (lo, lo, "%s self equality", os.str ());
|
||||
tap.expect_eq (hi, hi, "%s self equality", os.str ());
|
||||
tap.expect_eq (lo, lo, "{:s} self equality", os.str ());
|
||||
tap.expect_eq (hi, hi, "{:s} self equality", os.str ());
|
||||
|
||||
tap.expect_neq (hi, lo, "%s inequality", os.str ());
|
||||
tap.expect_neq (lo, hi, "%s inequality", os.str ());
|
||||
tap.expect_neq (hi, lo, "{:s} inequality", os.str ());
|
||||
tap.expect_neq (lo, hi, "{:s} inequality", os.str ());
|
||||
|
||||
tap.expect_lt (lo, hi, "%s less than", os.str ());
|
||||
tap.expect_le (lo, hi, "%s less than equal", os.str ());
|
||||
tap.expect_le (lo, lo, "%s less than equal", os.str ());
|
||||
tap.expect_lt (lo, hi, "{:s} less than", os.str ());
|
||||
tap.expect_le (lo, hi, "{:s} less than equal", os.str ());
|
||||
tap.expect_le (lo, lo, "{:s} less than equal", os.str ());
|
||||
|
||||
tap.expect_gt (hi, lo, "%s greater than", os.str ());
|
||||
tap.expect_ge (lo, lo, "%s greater than equal", os.str ());
|
||||
tap.expect_ge (hi, lo, "%s greater than equal", os.str ());
|
||||
tap.expect_gt (hi, lo, "{:s} greater than", os.str ());
|
||||
tap.expect_ge (lo, lo, "{:s} greater than equal", os.str ());
|
||||
tap.expect_ge (hi, lo, "{:s} greater than equal", os.str ());
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,7 +21,7 @@ main (void)
|
||||
|
||||
#define CHECK_RENDER(fmt,res,...) do { \
|
||||
auto val = to_string (cruft::format::printf (fmt)(__VA_ARGS__)); \
|
||||
tap.expect_eq (val, res, "render '%!', # %! == %!", fmt, val, res); \
|
||||
tap.expect_eq (val, res, "render '{}', # {} == {}", fmt, val, res); \
|
||||
} while (0)
|
||||
|
||||
CHECK_RENDER ("foo", "foo");
|
||||
@ -182,7 +182,7 @@ main (void)
|
||||
#define CHECK_THROW(fmt,except,...) do { \
|
||||
tap.expect_throw<std::exception> ([&] { \
|
||||
to_string (cruft::format::printf (fmt)(__VA_ARGS__)); \
|
||||
}, "exception '%s' for format '%s'", #except, fmt); \
|
||||
}, "exception '{:s}' for format '{:s}'", #except, fmt); \
|
||||
} while (0)
|
||||
|
||||
CHECK_THROW("%", syntax_error);
|
||||
|
@ -48,7 +48,7 @@ main (int, char**)
|
||||
for (auto const &t: TESTS) {
|
||||
cruft::geom::aabb2f const shape (t.lo, t.hi);
|
||||
cruft::geom::ray2f const r {t.base, t.direction};
|
||||
tap.expect_eq (distance (r, shape), t.distance, "%!", t.message);
|
||||
tap.expect_eq (distance (r, shape), t.distance, "{}", t.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -39,7 +39,7 @@ test_intersection (cruft::TAP::logger &tap)
|
||||
};
|
||||
|
||||
for (auto const& t: TESTS) {
|
||||
tap.expect_eq (t.distance, distance (t.caster, t.shape), "%s", t.message);
|
||||
tap.expect_eq (t.distance, distance (t.caster, t.shape), "{:s}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ test_area (cruft::TAP::logger &tap)
|
||||
|
||||
for (auto const& t: TESTS) {
|
||||
auto found = area (t.shape);
|
||||
tap.expect (cruft::relatively_equal (found, t.value, 1.08e-2f), "%!", t.message);
|
||||
tap.expect (cruft::relatively_equal (found, t.value, 1.08e-2f), "{}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ test_cover (cruft::TAP::logger &tap)
|
||||
return intersects (shape, p);
|
||||
});
|
||||
|
||||
tap.expect (success, "%!", t.message);
|
||||
tap.expect (success, "{}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ main ()
|
||||
};
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
tap.expect_eq (intersects (origin90, t.box), t.intersects, "origin frustrum, %s", t.message);
|
||||
tap.expect_eq (intersects (origin90, t.box), t.intersects, "origin frustrum, {:s}", t.message);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -21,7 +21,7 @@ main (int, char**)
|
||||
for (auto const& t: TESTS) {
|
||||
cruft::geom::line3f l { t.origin, t.direction };
|
||||
auto d = distance2 (l, t.q);
|
||||
tap.expect_eq (d, t.distance, "%!", t.message);
|
||||
tap.expect_eq (d, t.distance, "{}", t.message);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -20,7 +20,7 @@ test_distances (cruft::TAP::logger &tap)
|
||||
for (auto const &t: TESTS) {
|
||||
auto const p = cruft::geom::make_plane (t.a, t.b, t.c);
|
||||
const auto d = distance (p, t.query);
|
||||
tap.expect_eq (d, t.distance, "%!", t.message);
|
||||
tap.expect_eq (d, t.distance, "{}", t.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ int main ()
|
||||
bool const y_perim = pos.y == 0 || pos.y == AREA.h;
|
||||
|
||||
if (!x_perim && !y_perim) {
|
||||
tap.fail ("position %! falls outside perimeter: %!", i, pos);
|
||||
tap.fail ("position {} falls outside perimeter: {}", i, pos);
|
||||
return tap.status ();
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ int main ()
|
||||
|
||||
tap.expect_lt (
|
||||
std::abs (rel_diff), 0.05f,
|
||||
"occurence counts are evenly spaced: %!:%! vs %!:%!",
|
||||
"occurence counts are evenly spaced: {}:{} vs {}:{}",
|
||||
hi->first, hi->second,
|
||||
lo->first, lo->second
|
||||
);
|
||||
|
@ -40,7 +40,7 @@ main ()
|
||||
}
|
||||
}
|
||||
|
||||
tap.expect (success, "subregion coverage validity, %!", msg);
|
||||
tap.expect (success, "subregion coverage validity, {}", msg);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -22,7 +22,7 @@ void test_point_distance (cruft::TAP::logger &tap)
|
||||
for (auto const& t: TESTS) {
|
||||
cruft::geom::segment3f s {t.a, t.b};
|
||||
auto d = distance (s, t.q);
|
||||
tap.expect_eq (d, t.distance, "%!", t.message);
|
||||
tap.expect_eq (d, t.distance, "{}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ void test_region_intersection (cruft::TAP::logger &tap)
|
||||
};
|
||||
|
||||
for (auto const &t: TESTS)
|
||||
tap.expect_eq (intersects (t.a, t.b), t.expected, "region intersection: %!", t.message);
|
||||
tap.expect_eq (intersects (t.a, t.b), t.expected, "region intersection: {}", t.message);
|
||||
}
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ void test_bresenham (cruft::TAP::logger &tap)
|
||||
std::vector<cruft::point2i> computed;
|
||||
for (auto const p: cruft::geom::bresenham ({ t.a, t.b }))
|
||||
computed.push_back (p);
|
||||
tap.expect_eq (computed, t.expected, "bresenham: %!", t.message);
|
||||
tap.expect_eq (computed, t.expected, "bresenham: {}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ test_intersect (cruft::TAP::logger &tap)
|
||||
};
|
||||
|
||||
for (const auto &[d,s,r,msg]: TESTS) {
|
||||
tap.expect_eq (d, distance (r, s), "%!", msg);
|
||||
tap.expect_eq (d, distance (r, s), "{}", msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,13 @@ main (int, char**) {
|
||||
tap.expect_eq (
|
||||
t.adler,
|
||||
a (cruft::view {t.data}.template cast<const uint8_t*> ()),
|
||||
"adler checksum: %s", t.msg
|
||||
"adler checksum: {:s}", t.msg
|
||||
);
|
||||
|
||||
tap.expect_eq (
|
||||
t.bsd,
|
||||
b (cruft::view {t.data}.template cast<const uint8_t*> ()),
|
||||
"bsdsum checksum: %s", t.msg);
|
||||
"bsdsum checksum: {:s}", t.msg);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -34,7 +34,7 @@ main (int, char**)
|
||||
for (const auto &t: TESTS) {
|
||||
#define TEST(KLASS) do { \
|
||||
auto computed = cruft::hash::KLASS{}(cruft::view {t.dat}.template cast<const uint8_t*> ()); \
|
||||
tap.expect_eq (t.result.KLASS, computed, "%s: %s", #KLASS, t.msg); \
|
||||
tap.expect_eq (t.result.KLASS, computed, "{:s}: {:s}", #KLASS, t.msg); \
|
||||
} while (0)
|
||||
|
||||
TEST(crc32);
|
||||
|
@ -47,8 +47,8 @@ main (void)
|
||||
for (const auto &t: TESTS) {
|
||||
cruft::view data { t.data };
|
||||
|
||||
tap.expect_eq (t.hash32, h32 (t.seed32, data.cast<uint8_t const*> ()), "h32(%0" PRIx32 ")", t.seed32);
|
||||
tap.expect_eq (t.hash64, h64 (t.seed64, data.cast<uint8_t const*> ()), "h64(%0" PRIx64 ")", t.seed64);
|
||||
tap.expect_eq (t.hash32, h32 (t.seed32, data.cast<uint8_t const*> ()), "h32({:#04x})", t.seed32);
|
||||
tap.expect_eq (t.hash64, h64 (t.seed64, data.cast<uint8_t const*> ()), "h64({:#08x})", t.seed64);
|
||||
}
|
||||
|
||||
tap.expect (success32, "fasthash32");
|
||||
|
@ -24,8 +24,8 @@ main (void)
|
||||
const cruft::hash::fnv1a<uint64_t> h64;
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
tap.expect_eq (h32 (cruft::view{t.data}.cast <const uint8_t*> ()), t.h32, "fnv1a32: '%s'", t.data);
|
||||
tap.expect_eq (h64 (cruft::view{t.data}.cast <const uint8_t*> ()), t.h64, "fnv1a64: '%s'", t.data);
|
||||
tap.expect_eq (h32 (cruft::view{t.data}.cast <const uint8_t*> ()), t.h32, "fnv1a32: '{:s}'", t.data);
|
||||
tap.expect_eq (h64 (cruft::view{t.data}.cast <const uint8_t*> ()), t.h64, "fnv1a64: '{:s}'", t.data);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -124,13 +124,13 @@ test (cruft::TAP::logger &tap)
|
||||
const cruft::hash::murmur3_128_x86 h3_x86 (t.m3_128_x86.seed);
|
||||
const cruft::hash::murmur3_128_x64 h3_x64 (t.m3_128_x64.seed);
|
||||
|
||||
tap.expect_eq (h1 (t.data), t.m1_32.hash, "murmur1_32, '%s'", t.msg);
|
||||
tap.expect_eq (h2_32 (t.data), t.m2_32.hash, "murmur2_32, '%s'", t.msg);
|
||||
tap.expect_eq (h2_64 (t.data), t.m2_64.hash, "murmur2_64, '%s'", t.msg);
|
||||
tap.expect_eq (h1 (t.data), t.m1_32.hash, "murmur1_32, '{:s}'", t.msg);
|
||||
tap.expect_eq (h2_32 (t.data), t.m2_32.hash, "murmur2_32, '{:s}'", t.msg);
|
||||
tap.expect_eq (h2_64 (t.data), t.m2_64.hash, "murmur2_64, '{:s}'", t.msg);
|
||||
|
||||
tap.expect_eq (h3 (t.data), t.m3_32.hash, "murmur3_32, '%s'", t.msg);
|
||||
tap.expect_eq (h3_x86 (t.data), t.m3_128_x86.hash, "murmur3_128_x86, '%s'", t.msg);
|
||||
tap.expect_eq (h3_x64 (t.data), t.m3_128_x64.hash, "murmur3_128_x64, '%s'", t.msg);
|
||||
tap.expect_eq (h3 (t.data), t.m3_32.hash, "murmur3_32, '{:s}'", t.msg);
|
||||
tap.expect_eq (h3_x86 (t.data), t.m3_128_x86.hash, "murmur3_128_x86, '{:s}'", t.msg);
|
||||
tap.expect_eq (h3_x64 (t.data), t.m3_128_x64.hash, "murmur3_128_x64, '{:s}'", t.msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ main ()
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
cruft::hash::siphash<2,4> h (t.key);
|
||||
tap.expect_eq (h (t.data), t.digest, "%s", t.message);
|
||||
tap.expect_eq (h (t.data), t.digest, "{:s}", t.message);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -35,7 +35,7 @@ void test_type (cruft::TAP::logger &tap)
|
||||
auto const pos = std::adjacent_find (std::begin (results), std::end (results));
|
||||
tap.expect (
|
||||
pos == std::end (results),
|
||||
"no equal elements, %!",
|
||||
"no equal elements, {}",
|
||||
cruft::introspection::name::bare<ValueT> ()
|
||||
);
|
||||
}
|
||||
@ -62,7 +62,7 @@ void test_type (cruft::TAP::logger &tap)
|
||||
|
||||
tap.expect (
|
||||
success,
|
||||
"equal counts at bit positions, %!",
|
||||
"equal counts at bit positions, {}",
|
||||
cruft::introspection::name::bare<ValueT> ()
|
||||
);
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ main (int, char **)
|
||||
cruft::hash::xxhash32 h32 (t.seed);
|
||||
cruft::hash::xxhash64 h64 (t.seed);
|
||||
|
||||
tap.expect_eq (h32 (t.data), t.hash32, "xxhash32 %s", t.msg);
|
||||
tap.expect_eq (h64 (t.data), t.hash64, "xxhash64 %s, seed %!", t.msg, t.seed);
|
||||
tap.expect_eq (h32 (t.data), t.hash32, "xxhash32 {:s}", t.msg);
|
||||
tap.expect_eq (h64 (t.data), t.hash64, "xxhash64 {:s}, seed {}", t.msg, t.seed);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "introspection/name.hpp"
|
||||
#include "introspection/type.hpp"
|
||||
#include "std.hpp"
|
||||
#include "view.hpp"
|
||||
|
||||
#include "tap.hpp"
|
||||
#include <iostream>
|
||||
|
@ -45,7 +45,7 @@ test_iota (cruft::TAP::logger &tap)
|
||||
{
|
||||
cruft::iterator::iota seq (5);
|
||||
auto const sum = std::accumulate (std::begin (seq), std::end (seq), 0u);
|
||||
tap.expect_eq (sum, 4u+3u+2u+1u+0u, "iota summation %!", sum);
|
||||
tap.expect_eq (sum, 4u+3u+2u+1u+0u, "iota summation {}", sum);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,6 +45,6 @@ main (void)
|
||||
success = count == INNER && success;
|
||||
}
|
||||
|
||||
tap.expect (success, "%! trivial increment jobs of size %!", OUTTER, INNER);
|
||||
tap.expect (success, "{} trivial increment jobs of size {}", OUTTER, INNER);
|
||||
return tap.status ();
|
||||
}
|
@ -135,8 +135,8 @@ test_normalisations (cruft::TAP::logger &tap)
|
||||
};
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
tap.expect_eq (cruft::renormalise<int32_t,uint32_t> (t.sint), t.uint, "%s s32-to-u32", t.msg);
|
||||
tap.expect_eq (cruft::renormalise<uint32_t,int32_t> (t.uint), t.sint, "%s u32-to-s32", t.msg);
|
||||
tap.expect_eq (cruft::renormalise<int32_t,uint32_t> (t.sint), t.uint, "{:s} s32-to-u32", t.msg);
|
||||
tap.expect_eq (cruft::renormalise<uint32_t,int32_t> (t.uint), t.sint, "{:s} u32-to-s32", t.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,11 +87,11 @@ main ()
|
||||
//
|
||||
// const float relerr = 1 - observed / expected;
|
||||
// std::cout << observed << '\t' << expected << '\t' << relerr << '\n';
|
||||
// tap.expect_lt (relerr, 1e-4f, "relative exp(%!) error", i);
|
||||
// tap.expect_lt (relerr, 1e-4f, "relative exp({}) error", i);
|
||||
//}
|
||||
|
||||
tap.expect_eq (successes.sin, std::size (sins), "sin evaluation, %!/%!", successes.sin, std::size (sins));
|
||||
tap.expect_eq (successes.exp, std::size (exps), "exp evaluation, %!/%!", successes.exp, std::size (exps));
|
||||
tap.expect_eq (successes.sin, std::size (sins), "sin evaluation, {}/{}", successes.sin, std::size (sins));
|
||||
tap.expect_eq (successes.exp, std::size (exps), "exp evaluation, {}/{}", successes.exp, std::size (exps));
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ main (void)
|
||||
truth, euler,
|
||||
[] (auto a, auto b) { return cruft::almost_equal (a, b); }
|
||||
)),
|
||||
"matrix-to-euler, %s",
|
||||
"matrix-to-euler, {:s}",
|
||||
t.msg
|
||||
);
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "tap.hpp"
|
||||
|
||||
#include "parallel/queue.hpp"
|
||||
#include "thread/flag.hpp"
|
||||
#include "thread/semaphore.hpp"
|
||||
|
||||
#include "tap.hpp"
|
||||
#include "view.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -66,7 +66,7 @@ int main ()
|
||||
for (auto &t: contestants)
|
||||
t.join ();
|
||||
|
||||
tap.expect (true, "n-way fight, %! contestants", contestants.size ());
|
||||
tap.expect (true, "n-way fight, {} contestants", contestants.size ());
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -25,7 +25,7 @@ int main ()
|
||||
if (!res) {
|
||||
tap.fail ("SI parsing %!", t.str);
|
||||
} else {
|
||||
tap.expect_eq (t.val, *res, "SI parsing '%!'", t.str);
|
||||
tap.expect_eq (t.val, *res, "SI parsing '{}'", t.str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ int main ()
|
||||
|
||||
for (auto const &[str,val,msg]: TESTS) {
|
||||
auto res = cruft::parse::duration::from (str);
|
||||
tap.expect (res && val == *res, "%! %! == %!", msg, val.count (), res->count());
|
||||
tap.expect (res && val == *res, "{} {} == {}", msg, val.count (), res->count());
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -51,7 +51,7 @@ main (int, char**)
|
||||
ok = false;
|
||||
}
|
||||
|
||||
tap.expect (ok, "%s", i.name);
|
||||
tap.expect (ok, "{:s}", i.name);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -89,7 +89,7 @@ main (void)
|
||||
auto m = cruft::rotation<float> (r.mag, r.axis);
|
||||
auto diff = cruft::abs (q - m);
|
||||
|
||||
tap.expect_lt (cruft::sum (diff), 1e-6f, "single basis rotation %zu", i);
|
||||
tap.expect_lt (cruft::sum (diff), 1e-6f, "single basis rotation {:d}", i);
|
||||
}
|
||||
|
||||
auto q = quaternionf::identity ();
|
||||
@ -127,7 +127,7 @@ main (void)
|
||||
auto v = rotate (src, q);
|
||||
|
||||
auto diff = std::abs (cruft::sum (dst - v));
|
||||
tap.expect_lt (diff, 1e-06f, "quaternion from-to, %s", t.msg);
|
||||
tap.expect_lt (diff, 1e-06f, "quaternion from-to, {:s}", t.msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ main (void)
|
||||
tap.expect_eq (
|
||||
cruft::quaternionf::from_euler ({ t.x, t.y, t.z }),
|
||||
t.expected,
|
||||
"from_euler: %!",
|
||||
"from_euler: {}",
|
||||
t.msg
|
||||
);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ test_buckets (cruft::TAP::logger &tap, Args&& ...args)
|
||||
std::find_if (std::cbegin (buckets),
|
||||
std::cend (buckets),
|
||||
[] (auto v) { return v < EXPECTED * 7 / 8; }) == std::cend (buckets),
|
||||
"bucket counts for %s", cruft::introspection::name::full<GeneratorT> ()
|
||||
"bucket counts for {:s}", cruft::introspection::name::full<GeneratorT> ()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,8 @@ main (int, char **)
|
||||
};
|
||||
|
||||
for (auto const &[a, b, res, msg]: TESTS) {
|
||||
tap.expect_eq (a.intersects (b), res, "intersection a-on-b: %!", msg);
|
||||
tap.expect_eq (b.intersects (a), res, "intersection b-on-a: %!", msg);
|
||||
tap.expect_eq (a.intersects (b), res, "intersection a-on-b: {}", msg);
|
||||
tap.expect_eq (b.intersects (a), res, "intersection b-on-a: {}", msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ main (int, char **)
|
||||
};
|
||||
|
||||
for (auto const &[a, b, expected, msg]: TESTS)
|
||||
tap.expect_eq (a.covers (b), expected, "covers: %!", msg);
|
||||
tap.expect_eq (a.covers (b), expected, "covers: {}", msg);
|
||||
}
|
||||
|
||||
// ensure make_region covers the expected values
|
||||
@ -185,7 +185,7 @@ main (int, char **)
|
||||
|
||||
for (auto const &t: TESTS) {
|
||||
auto const d2 = distance2 (t.r, t.p);
|
||||
tap.expect_eq (d2, t.distance2, "region-point distance2: %!", t.message);
|
||||
tap.expect_eq (d2, t.distance2, "region-point distance2: {}", t.message);
|
||||
}
|
||||
};
|
||||
|
||||
@ -233,7 +233,7 @@ main (int, char **)
|
||||
};
|
||||
|
||||
for (auto const &[a, b, res, message]: TESTS)
|
||||
tap.expect_eq (intersection (a, b), res, "region-region interesection: %!", message);
|
||||
tap.expect_eq (intersection (a, b), res, "region-region interesection: {}", message);
|
||||
}
|
||||
|
||||
// Test rotate behaves as expected.
|
||||
@ -282,7 +282,7 @@ main (int, char **)
|
||||
|
||||
for (auto const &obj: TESTS) {
|
||||
auto const computed = rotate90 (orig, obj.rotation);
|
||||
tap.expect_eq (computed, obj.res, "%! rotation", obj.rotation);
|
||||
tap.expect_eq (computed, obj.res, "{} rotation", obj.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ main (void)
|
||||
for (const auto &t: TESTS) {
|
||||
constexpr float TOLERANCE = 0.00001f;
|
||||
auto root = cruft::roots::bisection (t.lo, t.hi, t.func, TOLERANCE);
|
||||
tap.expect_eq (root, t.root, "%s", t.msg);
|
||||
tap.expect_eq (root, t.root, "{:s}", t.msg);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -26,8 +26,8 @@ test_transforms (cruft::TAP::logger &tap)
|
||||
};
|
||||
|
||||
for (auto const &[src, upper, lower, msg]: TESTS) {
|
||||
tap.expect_eq (cruft::to_upper (src), upper, "to_upper, %!", msg);
|
||||
tap.expect_eq (cruft::to_lower (src), lower, "to_lower, %!", msg);
|
||||
tap.expect_eq (cruft::to_upper (src), upper, "to_upper, {:s}", msg);
|
||||
tap.expect_eq (cruft::to_lower (src), lower, "to_lower, {:s}", msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ test_position (cruft::TAP::logger &tap)
|
||||
|
||||
tap.expect (
|
||||
pos.line == t.line && pos.column == t.column,
|
||||
"character_position %!:%!",
|
||||
"character_position {}:{}",
|
||||
t.line,
|
||||
t.column
|
||||
);
|
||||
@ -90,7 +90,7 @@ test_tokeniser (cruft::TAP::logger &tap)
|
||||
|
||||
cruft::view src { csv.c_str (), csv.size () };
|
||||
for (auto [tok, expected]: cruft::iterator::zip (cruft::tokeniser (src, ','), TESTS)) {
|
||||
tap.expect (equal (tok, expected.value), "%s", expected.message);
|
||||
tap.expect (equal (tok, expected.value), "{:s}", expected.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ test_contains (cruft::TAP::logger &tap)
|
||||
for (auto const &t: TESTS) {
|
||||
cruft::tokeniser tok (t.haystack, t.separator);
|
||||
auto const found = tok.contains (t.needle);
|
||||
tap.expect_eq (found, t.expected, "%!", t.message);
|
||||
tap.expect_eq (found, t.expected, "{}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ void test_comparator_less (cruft::TAP::logger &tap)
|
||||
};
|
||||
|
||||
for (auto const &t: TESTS)
|
||||
tap.expect_eq (cmp (t.a, t.b), t.less, "string_less, %!", t.message);
|
||||
tap.expect_eq (cmp (t.a, t.b), t.less, "string_less, {}", t.message);
|
||||
}
|
||||
|
||||
|
||||
@ -209,7 +209,7 @@ void test_comparator_lower (cruft::TAP::logger &tap)
|
||||
cruft::string::compare::lower cmp;
|
||||
|
||||
for (auto const &t: TESTS) {
|
||||
tap.expect_eq (cmp (t.a, t.b), t.equal, "compare::lower, pointers, %!", t.message);
|
||||
tap.expect_eq (cmp (t.a, t.b), t.equal, "compare::lower, pointers, {}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ main ()
|
||||
for (auto &t: contestants)
|
||||
t.join ();
|
||||
|
||||
tap.expect (true, "n-way fight, %! contestants", std::thread::hardware_concurrency ());
|
||||
tap.expect (true, "n-way fight, {} contestants", std::thread::hardware_concurrency ());
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -16,7 +16,7 @@ main (int, char**)
|
||||
for (const auto &t: BAD) {
|
||||
tap.expect_throw<std::invalid_argument> (
|
||||
[t] () { cruft::time::iso8601::parse (t); },
|
||||
"invalid timestamp '%s'", t
|
||||
"invalid timestamp '{:s}'", t
|
||||
);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ main (int, char**)
|
||||
|
||||
for (const auto &t: DECODE) {
|
||||
auto val = cruft::time::iso8601::parse (t.string);
|
||||
tap.expect_eq (val, t.value, "%s", t.message);
|
||||
tap.expect_eq (val, t.value, "{:s}", t.message);
|
||||
}
|
||||
|
||||
tap.expect_eq (
|
||||
|
22
test/uri.cpp
22
test/uri.cpp
@ -140,18 +140,18 @@ main (void)
|
||||
};
|
||||
|
||||
for (auto t: GOOD) {
|
||||
tap.expect_nothrow ([t] (void) { cruft::uri foo (t.src); }, "nothrow parsing '%s'", t.src);
|
||||
tap.expect_nothrow ([t] (void) { cruft::uri foo (t.src); }, "nothrow parsing '{:s}'", t.src);
|
||||
cruft::uri u (t.src);
|
||||
|
||||
tap.expect_eq (u.scheme (), t.scheme, "scheme for '%s'", t.src);
|
||||
tap.expect_eq (u.heirarchical (), t.hierarchical, "hierarchical for '%s'", t.src);
|
||||
tap.expect_eq (u.authority (), t.authority, "authority for '%s'", t.src);
|
||||
tap.expect_eq (u.host (), t.host, "host for '%s'", t.src);
|
||||
tap.expect_eq (u.user (), t.user, "user for '%s'", t.src);
|
||||
tap.expect_eq (u.port (), t.port, "port for '%s'", t.src);
|
||||
tap.expect_eq (u.path (), t.path, "path for '%s'", t.src);
|
||||
tap.expect_eq (u.query (), t.query, "query for '%s'", t.src);
|
||||
tap.expect_eq (u.fragment (), t.fragment, "fragment for '%s'", t.src);
|
||||
tap.expect_eq (u.scheme (), t.scheme, "scheme for '{:s}'", t.src);
|
||||
tap.expect_eq (u.heirarchical (), t.hierarchical, "hierarchical for '{:s}'", t.src);
|
||||
tap.expect_eq (u.authority (), t.authority, "authority for '{:s}'", t.src);
|
||||
tap.expect_eq (u.host (), t.host, "host for '{:s}'", t.src);
|
||||
tap.expect_eq (u.user (), t.user, "user for '{:s}'", t.src);
|
||||
tap.expect_eq (u.port (), t.port, "port for '{:s}'", t.src);
|
||||
tap.expect_eq (u.path (), t.path, "path for '{:s}'", t.src);
|
||||
tap.expect_eq (u.query (), t.query, "query for '{:s}'", t.src);
|
||||
tap.expect_eq (u.fragment (), t.fragment, "fragment for '{:s}'", t.src);
|
||||
}
|
||||
|
||||
static const char* BAD[] = {
|
||||
@ -160,7 +160,7 @@ main (void)
|
||||
|
||||
for (auto i: BAD)
|
||||
tap.expect_throw<cruft::uri::parse_error> (
|
||||
[i] (void) { cruft::uri foo (i); }, "throw parsing '%s'", i
|
||||
[i] (void) { cruft::uri foo (i); }, "throw parsing '{:s}'", i
|
||||
);
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ simple_valid (cruft::TAP::logger &tap)
|
||||
#endif
|
||||
};
|
||||
|
||||
static constexpr char fmt[] = "valid length, %s";
|
||||
static constexpr char fmt[] = "valid length, {:s}";
|
||||
|
||||
for (const auto &t: VALID) {
|
||||
try {
|
||||
@ -71,7 +71,7 @@ single_boundaries (cruft::TAP::logger &tap)
|
||||
{ { 0xF4, 0x90, 0x80, 0x80 }, 0x00110000, "other" },
|
||||
};
|
||||
|
||||
static constexpr char fmt[] = "single character (%s), %!-byte sequence";
|
||||
static constexpr char fmt[] = "single character ({:s}), {}-byte sequence";
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
auto data = cruft::make_view (
|
||||
@ -111,7 +111,7 @@ malformed (cruft::TAP::logger &tap)
|
||||
{ { 0x80, 0xBF, 0x80, 0xBF }, "continuation sequence" },
|
||||
};
|
||||
|
||||
static constexpr char fmt[] = "malformed %! byte sequence, %s";
|
||||
static constexpr char fmt[] = "malformed {} byte sequence, {:s}";
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
auto data = cruft::make_view (
|
||||
@ -179,7 +179,7 @@ malformed (cruft::TAP::logger &tap)
|
||||
{ success = false; }
|
||||
}
|
||||
|
||||
tap.expect (success, "lonely start characters, %! bytes", t.length);
|
||||
tap.expect (success, "lonely start characters, {} bytes", t.length);
|
||||
}
|
||||
|
||||
|
||||
@ -197,7 +197,7 @@ malformed (cruft::TAP::logger &tap)
|
||||
|
||||
tap.expect_throw<cruft::utf8::malformed_error> (
|
||||
[&data] () { cruft::utf8::decode (data); },
|
||||
"%! byte sequence missing the lastbyte",
|
||||
"{} byte sequence missing the lastbyte",
|
||||
t.size ()
|
||||
);
|
||||
}
|
||||
@ -217,7 +217,7 @@ malformed (cruft::TAP::logger &tap)
|
||||
|
||||
tap.expect_throw<cruft::utf8::malformed_error> (
|
||||
[&data] () { cruft::utf8::decode (data); },
|
||||
"impossible %! byte sequence",
|
||||
"impossible {} byte sequence",
|
||||
t.size ()
|
||||
);
|
||||
}
|
||||
@ -255,7 +255,7 @@ overlong (cruft::TAP::logger &tap)
|
||||
[&] () {
|
||||
cruft::utf8::decode (data);
|
||||
},
|
||||
"overlong %! byte sequence, %s",
|
||||
"overlong {} byte sequence, {:s}",
|
||||
t.data.size (),
|
||||
t.message
|
||||
);
|
||||
|
@ -51,7 +51,7 @@ test_polar (cruft::TAP::logger &tap)
|
||||
auto in_cart = t.cartesian;
|
||||
auto to_cart = cruft::polar_to_cartesian (t.polar);
|
||||
|
||||
tap.expect_lt (norm (in_cart - to_cart), 0.00001f, "%s", t.desc);
|
||||
tap.expect_lt (norm (in_cart - to_cart), 0.00001f, "{:s}", t.desc);
|
||||
|
||||
// Compare polar representations. Make sure to normalise them first.
|
||||
auto in_polar = t.polar;
|
||||
@ -60,7 +60,7 @@ test_polar (cruft::TAP::logger &tap)
|
||||
in_polar[1] = std::fmod (in_polar[1], 2 * cruft::pi<float>);
|
||||
to_polar[1] = std::fmod (to_polar[1], 2 * cruft::pi<float>);
|
||||
|
||||
tap.expect_eq (in_polar, to_polar, "%s", t.desc);
|
||||
tap.expect_eq (in_polar, to_polar, "{:s}", t.desc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ test_euler (cruft::TAP::logger &tap)
|
||||
for (auto i: TESTS) {
|
||||
tap.expect_eq (cruft::to_euler (i.dir),
|
||||
i.euler * cruft::pi<float>,
|
||||
"to euler, %s", i.name);
|
||||
"to euler, {:s}", i.name);
|
||||
}
|
||||
|
||||
// check error in round trip through euler angles
|
||||
@ -100,7 +100,7 @@ test_euler (cruft::TAP::logger &tap)
|
||||
|
||||
// trig functions reduce precision above almost_equal levels, so we
|
||||
// hard code a fairly low bound here instead.
|
||||
tap.expect_lt (mag, 1e-7, "euler round-trip error, %s", i.name);
|
||||
tap.expect_lt (mag, 1e-7, "euler round-trip error, {:s}", i.name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ test_spherical (cruft::TAP::logger &tap)
|
||||
for (const auto t: S2C) {
|
||||
tap.expect (
|
||||
all (abs (cruft::spherical_to_cartesian (t.spherical) - t.cartesian) < 1e-7f),
|
||||
"%s, spherical-cartesian",
|
||||
"{:s}, spherical-cartesian",
|
||||
t.message
|
||||
);
|
||||
}
|
||||
@ -188,7 +188,7 @@ test_spherical (cruft::TAP::logger &tap)
|
||||
const auto s1 = cruft::canonical_spherical (t.spherical);
|
||||
tap.expect (
|
||||
all (abs (s0 - s1) < 1e-4f),
|
||||
"%s, cartesian-spherical",
|
||||
"{:s}, cartesian-spherical",
|
||||
t.message
|
||||
);
|
||||
}
|
||||
@ -197,7 +197,7 @@ test_spherical (cruft::TAP::logger &tap)
|
||||
//tap.expect_eq (
|
||||
// cruft::cartesian_to_spherical (t.cartesian),
|
||||
// t.spherical,
|
||||
// "%s, cartesian-spherical",
|
||||
// "{:s}, cartesian-spherical",
|
||||
// t.message
|
||||
//);
|
||||
|
||||
|
@ -55,7 +55,7 @@ main () {
|
||||
bool parts = std::equal (v.begin (), v.end (), t.parts);
|
||||
bool release = v.release == t.release;
|
||||
|
||||
tap.expect (parts && release, "%s", t.msg);
|
||||
tap.expect (parts && release, "{:s}", t.msg);
|
||||
}
|
||||
|
||||
|
||||
@ -64,9 +64,9 @@ main () {
|
||||
const bool lt = t.a < t.b;
|
||||
const bool gt = t.a > t.b;
|
||||
|
||||
tap.expect (t.eq == eq, "%s: equality", t.msg);
|
||||
tap.expect (t.lt == lt, "%s: less-than", t.msg);
|
||||
tap.expect (t.gt == gt, "%s: greater-than", t.msg);
|
||||
tap.expect (t.eq == eq, "{:s}: equality", t.msg);
|
||||
tap.expect (t.lt == lt, "{:s}: less-than", t.msg);
|
||||
tap.expect (t.gt == gt, "{:s}: greater-than", t.msg);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -73,7 +73,7 @@ main (int, char**)
|
||||
};
|
||||
|
||||
for (const auto &t: TESTS) {
|
||||
tap.expect_eq (cruft::view { t.init }.slice (t.a, t.b), t.result, "slice; %s", t.message);
|
||||
tap.expect_eq (cruft::view { t.init }.slice (t.a, t.b), t.result, "slice; {:s}", t.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user