test: convert remaining tests to TAP
This commit is contained in:
parent
031ef3dca7
commit
d9a0649acb
@ -217,7 +217,6 @@ test_required (util::TAP::logger &tap)
|
||||
int
|
||||
main (int, char **) {
|
||||
util::TAP::logger tap;
|
||||
tap.todo ("convert to TAP");
|
||||
|
||||
test_null (tap);
|
||||
test_present (tap);
|
||||
@ -230,4 +229,6 @@ main (int, char **) {
|
||||
test_numeric<uint64_t> (tap);
|
||||
test_bytes (tap);
|
||||
test_required (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ using namespace std;
|
||||
|
||||
|
||||
void
|
||||
test_double (void) {
|
||||
test_double (util::TAP::logger &tap)
|
||||
{
|
||||
struct sized_test {
|
||||
ieee_double::uint_t bits;
|
||||
double floating;
|
||||
@ -32,16 +33,22 @@ test_double (void) {
|
||||
{ 0x3fd5555555555555, 1.0 / 3.0 }
|
||||
};
|
||||
|
||||
bool success = true;
|
||||
|
||||
for (unsigned int i = 0; i < elems (tests); ++i) {
|
||||
ieee_double val;
|
||||
val.set_bits (tests[i].bits);
|
||||
CHECK (val == tests[i].floating);
|
||||
|
||||
success = success && util::exactly_equal (val, tests[i].floating);
|
||||
}
|
||||
|
||||
tap.expect (success, "double precision bitwise equality");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
test_single (void) {
|
||||
test_single (util::TAP::logger &tap)
|
||||
{
|
||||
struct sized_test {
|
||||
ieee_single::uint_t bits;
|
||||
float floating;
|
||||
@ -61,19 +68,25 @@ test_single (void) {
|
||||
{ 0x3eaaaaab, 1.0f / 3.0f }
|
||||
};
|
||||
|
||||
bool success = true;
|
||||
|
||||
for (unsigned int i = 0; i < elems (tests); ++i) {
|
||||
ieee_single val;
|
||||
val.set_bits (tests[i].bits);
|
||||
CHECK (val == tests[i].floating);
|
||||
|
||||
success = success && util::exactly_equal (val, tests[i].floating);
|
||||
}
|
||||
|
||||
tap.expect (success, "single precision bitwise equality");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int, char **) {
|
||||
test_single ();
|
||||
test_double ();
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.todo ("convert to TAP");
|
||||
|
||||
test_single (tap);
|
||||
test_double (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -271,17 +271,10 @@ static const struct {
|
||||
int
|
||||
main (int, char**)
|
||||
{
|
||||
unsigned i = 0;
|
||||
for (const auto &t: TESTS) {
|
||||
std::cerr << i++ << ": " << t.key.size () << ", " << t.dat.size () << '\n';
|
||||
|
||||
|
||||
if (!t.fun (t.key, t.dat, t.res))
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.todo ("convert to TAP");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
for (size_t i = 0; i < elems (TESTS); ++i)
|
||||
tap.expect (TESTS[i].fun (TESTS[i].key, TESTS[i].dat, TESTS[i].res), "standard test vector");
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -24,9 +24,11 @@ main (int, char**)
|
||||
520489,
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < elems (EXPECTED); ++i)
|
||||
CHECK_EQ (EXPECTED[i], h.value ());
|
||||
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.todo ("convert to TAP");
|
||||
|
||||
for (auto &i: EXPECTED)
|
||||
tap.expect_eq (i, h.value (), "sequence");
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
64
test/ip.cpp
64
test/ip.cpp
@ -8,25 +8,55 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int
|
||||
main (int, char **) {
|
||||
struct ip_test {
|
||||
const char *str;
|
||||
const ipv4::ip ip;
|
||||
} data [] = {
|
||||
{ "0.0.0.0", { 0, 0, 0, 0 } },
|
||||
{ "255.255.255.255", { 255, 255, 255, 255 } },
|
||||
{ "127.0.0.1", { 127, 0, 0, 1 } }
|
||||
//-----------------------------------------------------------------------------
|
||||
static void
|
||||
test_good (util::TAP::logger &tap)
|
||||
{
|
||||
static const struct {
|
||||
const char *str;
|
||||
ipv4::ip ip;
|
||||
const char *msg;
|
||||
} TESTS[] = {
|
||||
{ "0.0.0.0", { 0, 0, 0, 0 }, "null" },
|
||||
{ "255.255.255.255", { 255, 255, 255, 255 }, "full" },
|
||||
{ "127.0.0.1", { 127, 0, 0, 1 }, "localhost" }
|
||||
};
|
||||
|
||||
for (unsigned int i = 0; i < elems (data); ++i) {
|
||||
ipv4::ip parsed (ipv4::ip::parse (data[i].str));
|
||||
CHECK (parsed == data[i].ip);
|
||||
for (const auto &i: TESTS) {
|
||||
ipv4::ip parsed (ipv4::ip::parse (i.str));
|
||||
tap.expect_eq (parsed, i.ip, i.msg);
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.todo ("convert to TAP");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
static void
|
||||
test_bad (util::TAP::logger &tap)
|
||||
{
|
||||
static const struct {
|
||||
const char *str;
|
||||
const char *msg;
|
||||
} TESTS[] = {
|
||||
{ "::1", "ipv6" },
|
||||
{ "foo", "alpha" },
|
||||
{ "", "empty" },
|
||||
{ "256.0.0.1", "overflow" }
|
||||
};
|
||||
|
||||
for (const auto &i: TESTS) {
|
||||
tap.expect_throw<ipv4::error> ([&] { ipv4::ip::parse (i.str); }, i.msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
main (int, char **) {
|
||||
util::TAP::logger tap;
|
||||
|
||||
test_good (tap);
|
||||
test_bad (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -8,7 +8,10 @@
|
||||
#include <cstdlib>
|
||||
|
||||
int
|
||||
main (void) {
|
||||
main (void)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
static const std::string TEST_STRING = R"_(
|
||||
{
|
||||
"string":"brad",
|
||||
@ -26,81 +29,103 @@ main (void) {
|
||||
})_";
|
||||
|
||||
std::unique_ptr<json::tree::node> ptr = json::tree::parse (TEST_STRING);
|
||||
tap.expect (ptr->is_object (), "is_object");
|
||||
CHECK (ptr->is_object ());
|
||||
|
||||
const json::tree::node &ref = *ptr;
|
||||
|
||||
CHECK ( ref["string"].is_string ());
|
||||
CHECK (!ref["string"].is_array ());
|
||||
CHECK (!ref["string"].is_boolean ());
|
||||
CHECK (!ref["string"].is_null ());
|
||||
CHECK (!ref["string"].is_number ());
|
||||
CHECK (!ref["string"].is_object ());
|
||||
CHECK_EQ ( ref["string"].as_string (), "brad");
|
||||
{
|
||||
tap.expect ( ref["string"].is_string (), "string is_string");
|
||||
tap.expect (!ref["string"].is_array (), "string not is_array");
|
||||
tap.expect (!ref["string"].is_boolean (), "string not is_boolean");
|
||||
tap.expect (!ref["string"].is_null (), "string not is_null");
|
||||
tap.expect (!ref["string"].is_number (), "string not is_number");
|
||||
tap.expect (!ref["string"].is_object (), "string not is_object");
|
||||
|
||||
CHECK ( ref["integer"].is_number ());
|
||||
CHECK (!ref["integer"].is_array ());
|
||||
CHECK (!ref["integer"].is_boolean ());
|
||||
CHECK (!ref["integer"].is_null ());
|
||||
CHECK (!ref["integer"].is_object ());
|
||||
CHECK (!ref["integer"].is_string ());
|
||||
CHECK (
|
||||
util::exactly_equal (
|
||||
(unsigned)ref["integer"].as_number ().native (),
|
||||
1u
|
||||
)
|
||||
);
|
||||
tap.expect_eq (ref["string"].as_string (), "brad", "string value equality");
|
||||
}
|
||||
|
||||
CHECK ( ref["null"].is_null ());
|
||||
CHECK (!ref["null"].is_array ());
|
||||
CHECK (!ref["null"].is_boolean ());
|
||||
CHECK (!ref["null"].is_number ());
|
||||
CHECK (!ref["null"].is_object ());
|
||||
CHECK (!ref["null"].is_string ());
|
||||
{
|
||||
tap.expect ( ref["integer"].is_number (), "integer is_number");
|
||||
tap.expect (!ref["integer"].is_array (), "integer not is_array");
|
||||
tap.expect (!ref["integer"].is_boolean (), "integer not is_boolean");
|
||||
tap.expect (!ref["integer"].is_null (), "integer not is_null");
|
||||
tap.expect (!ref["integer"].is_object (), "integer not is_object");
|
||||
tap.expect (!ref["integer"].is_string (), "integer not is_string");
|
||||
tap.expect (
|
||||
util::exactly_equal (
|
||||
(unsigned)ref["integer"].as_number ().native (),
|
||||
1u
|
||||
),
|
||||
"integer value equality"
|
||||
);
|
||||
}
|
||||
|
||||
CHECK ( ref["false"].is_boolean ());
|
||||
CHECK (!ref["false"].is_array ());
|
||||
CHECK (!ref["false"].is_null ());
|
||||
CHECK (!ref["false"].is_number ());
|
||||
CHECK (!ref["false"].is_object ());
|
||||
CHECK (!ref["false"].is_string ());
|
||||
CHECK_EQ ( ref["false"].as_boolean (), false);
|
||||
{
|
||||
tap.expect ( ref["null"].is_null (), "null is_null");
|
||||
tap.expect (!ref["null"].is_array (), "null not is_array");
|
||||
tap.expect (!ref["null"].is_boolean (), "null not is_boolean");
|
||||
tap.expect (!ref["null"].is_number (), "null not is_number");
|
||||
tap.expect (!ref["null"].is_object (), "null not is_object");
|
||||
tap.expect (!ref["null"].is_string (), "null not is_string");
|
||||
}
|
||||
|
||||
CHECK ( ref["true"].is_boolean ());
|
||||
CHECK (!ref["true"].is_array ());
|
||||
CHECK (!ref["true"].is_null ());
|
||||
CHECK (!ref["true"].is_number ());
|
||||
CHECK (!ref["true"].is_object ());
|
||||
CHECK (!ref["true"].is_string ());
|
||||
CHECK_EQ ( ref["true"].as_boolean (), true);
|
||||
{
|
||||
tap.expect ( ref["false"].is_boolean (), "false is_boolean");
|
||||
tap.expect (!ref["false"].is_array (), "false not is_array");
|
||||
tap.expect (!ref["false"].is_null (), "false not is_null");
|
||||
tap.expect (!ref["false"].is_number (), "false not is_number");
|
||||
tap.expect (!ref["false"].is_object (), "false not is_object");
|
||||
tap.expect (!ref["false"].is_string (), "false not is_string");
|
||||
|
||||
CHECK ( ref["double"].is_number ());
|
||||
CHECK (!ref["double"].is_array ());
|
||||
CHECK (!ref["double"].is_boolean ());
|
||||
CHECK (!ref["double"].is_null ());
|
||||
CHECK (!ref["double"].is_object ());
|
||||
CHECK (!ref["double"].is_string ());
|
||||
CHECK (
|
||||
util::exactly_equal (
|
||||
ref["double"].as_number ().native (),
|
||||
3.14
|
||||
)
|
||||
);
|
||||
tap.expect_eq (ref["false"].as_boolean (), false, "false value equality");
|
||||
}
|
||||
|
||||
CHECK ( ref["object"].is_object ());
|
||||
CHECK (!ref["object"].is_array ());
|
||||
CHECK (!ref["object"].is_boolean ());
|
||||
CHECK (!ref["object"].is_null ());
|
||||
CHECK (!ref["object"].is_number ());
|
||||
CHECK (!ref["object"].is_string ());
|
||||
{
|
||||
tap.expect ( ref["true"].is_boolean (), "true, is_boolean");
|
||||
tap.expect (!ref["true"].is_array (), "true not is_array");
|
||||
tap.expect (!ref["true"].is_null (), "true not is_null");
|
||||
tap.expect (!ref["true"].is_number (), "true not is_number");
|
||||
tap.expect (!ref["true"].is_object (), "true not is_object");
|
||||
tap.expect (!ref["true"].is_string (), "true not is_string");
|
||||
|
||||
CHECK ( ref["array"].is_array ());
|
||||
CHECK (!ref["array"].is_boolean ());
|
||||
CHECK (!ref["array"].is_null ());
|
||||
CHECK (!ref["array"].is_number ());
|
||||
CHECK (!ref["array"].is_object ());
|
||||
CHECK (!ref["array"].is_string ());
|
||||
tap.expect_eq ( ref["true"].as_boolean (), true, "true value equality");
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
{
|
||||
tap.expect ( ref["double"].is_number (), "double is_number");
|
||||
|
||||
tap.expect (!ref["double"].is_array (), "double not is_array");
|
||||
tap.expect (!ref["double"].is_boolean (), "double not is_boolean");
|
||||
tap.expect (!ref["double"].is_null (), "double not is_null");
|
||||
tap.expect (!ref["double"].is_object (), "double not is_object");
|
||||
tap.expect (!ref["double"].is_string (), "double not is_string");
|
||||
tap.expect (
|
||||
util::exactly_equal (
|
||||
ref["double"].as_number ().native (),
|
||||
3.14
|
||||
),
|
||||
"double value equality"
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
tap.expect ( ref["object"].is_object (), "object is_object");
|
||||
tap.expect (!ref["object"].is_array (), "object not is_array");
|
||||
tap.expect (!ref["object"].is_boolean (), "object not is_boolean");
|
||||
tap.expect (!ref["object"].is_null (), "object not is_null");
|
||||
tap.expect (!ref["object"].is_number (), "object not is_number");
|
||||
tap.expect (!ref["object"].is_string (), "object not is_string");
|
||||
}
|
||||
|
||||
{
|
||||
tap.expect ( ref["array"].is_array (), "array is_array");
|
||||
tap.expect (!ref["array"].is_boolean (), "array not is_boolean");
|
||||
tap.expect (!ref["array"].is_null (), "array not is_null");
|
||||
tap.expect (!ref["array"].is_number (), "array not is_number");
|
||||
tap.expect (!ref["array"].is_object (), "array not is_object");
|
||||
tap.expect (!ref["array"].is_string (), "array not is_string");
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -1,53 +1,56 @@
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "pool.hpp"
|
||||
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
using namespace util;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
check_single (void) {
|
||||
check_single (util::TAP::logger &tap)
|
||||
{
|
||||
// Ensure a single element doesn't break the circular linked list
|
||||
pool<uint64_t> single(1);
|
||||
single.release (single.acquire ());
|
||||
util::pool<uint64_t> single(1);
|
||||
tap.expect_nothrow ([&] {
|
||||
single.release (single.acquire ());
|
||||
}, "single element acquire-release");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
check_unique_ptr (void) {
|
||||
pool<uint64_t> uintpool (1025);
|
||||
set<uint64_t *> uintset;
|
||||
check_unique_ptr (util::TAP::logger &tap)
|
||||
{
|
||||
util::pool<uint64_t> uintpool (1025);
|
||||
std::set<uint64_t *> uintset;
|
||||
|
||||
// Take all pointers out, checking they are unique, then replace for destruction.
|
||||
for (unsigned int i = 0; i < uintpool.capacity (); ++i) {
|
||||
bool success = uintset.insert (uintpool.acquire ()).second;
|
||||
CHECK (success);
|
||||
}
|
||||
while (!uintpool.empty ())
|
||||
uintset.insert (uintpool.acquire ());
|
||||
|
||||
for (auto i = uintset.begin (); i != uintset.end (); ++i)
|
||||
uintpool.release (*i);
|
||||
tap.expect_eq (uintset.size (), uintpool.capacity (), "extracted maximum elements");
|
||||
|
||||
for (auto i: uintset)
|
||||
uintpool.release (i);
|
||||
|
||||
tap.expect_eq (uintset.size (), uintpool.remain (), "re-inserted maximum elements");
|
||||
uintset.clear ();
|
||||
|
||||
// Do the above one more time to ensure that releasing works right
|
||||
for (unsigned int i = 0; i < uintpool.capacity (); ++i) {
|
||||
bool success = uintset.insert (uintpool.acquire ()).second;
|
||||
CHECK (success);
|
||||
}
|
||||
|
||||
for (auto i = uintset.begin (); i != uintset.end (); ++i)
|
||||
uintpool.release (*i);
|
||||
while (!uintpool.empty ())
|
||||
uintset.insert (uintpool.acquire ());
|
||||
tap.expect_eq (uintset.size (), uintpool.capacity (), "re-extracted maximum elements");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
check_keep_value (void) {
|
||||
check_keep_value (util::TAP::logger &tap)
|
||||
{
|
||||
// Ensure that items keep their values.
|
||||
pool<uint64_t> uintpool(256);
|
||||
util::pool<uint64_t> uintpool(256);
|
||||
std::vector<uint64_t*> uintvector;
|
||||
uintvector.reserve(uintpool.capacity ());
|
||||
|
||||
@ -58,10 +61,11 @@ check_keep_value (void) {
|
||||
|
||||
uintvector.push_back(item);
|
||||
}
|
||||
|
||||
CHECK_EQ (uintvector.size (), uintpool.capacity ());
|
||||
|
||||
// Ensure they're all still present
|
||||
vector<bool> present(uintpool.capacity (), false);
|
||||
std::vector<bool> present(uintpool.capacity (), false);
|
||||
for (auto i = uintvector.begin (); i != uintvector.end (); ++i) {
|
||||
CHECK (**i < uintpool.capacity ());
|
||||
CHECK (present[**i] != true);
|
||||
@ -70,21 +74,24 @@ check_keep_value (void) {
|
||||
}
|
||||
|
||||
// All must have been marked as present...
|
||||
CHECK (find (present.begin (), present.end (), false) == present.end ());
|
||||
tap.expect (std::find (present.begin (), present.end (), false) == present.end (), "values retained");
|
||||
|
||||
// Release all back into the pool for destruction
|
||||
for (auto i = uintvector.begin (); i != uintvector.end (); ++i)
|
||||
uintpool.release (*i);
|
||||
uintvector.clear ();
|
||||
//for (auto i = uintvector.begin (); i != uintvector.end (); ++i)
|
||||
// uintpool.release (*i);
|
||||
//uintvector.clear ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
main (int, char **) {
|
||||
check_single ();
|
||||
check_unique_ptr ();
|
||||
check_keep_value ();
|
||||
|
||||
main (int, char **)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
|
||||
check_single (tap);
|
||||
check_unique_ptr (tap);
|
||||
check_keep_value (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ using namespace std;
|
||||
|
||||
// TODO: Use a more robust test like Chi-Square
|
||||
void
|
||||
test_bool (void) {
|
||||
test_bool (util::TAP::logger &tap)
|
||||
{
|
||||
static const unsigned ITERATIONS = 8192;
|
||||
static const unsigned THRESHOLD = ITERATIONS / 10;
|
||||
|
||||
@ -24,13 +25,14 @@ test_bool (void) {
|
||||
counts[0] - counts[1] :
|
||||
counts[1] - counts[0];
|
||||
|
||||
CHECK_LT (diff, THRESHOLD);
|
||||
tap.expect_lt (diff, THRESHOLD, "approximately even bool distribution");
|
||||
}
|
||||
|
||||
|
||||
// TODO: Use a more robust test like Kolmogorov-Smirnov
|
||||
void
|
||||
test_float (void) {
|
||||
test_float (util::TAP::logger &tap)
|
||||
{
|
||||
static const unsigned BUCKETS = 8;
|
||||
static const unsigned ITERATIONS = 8912;
|
||||
static const unsigned EXPECTED = ITERATIONS / BUCKETS;
|
||||
@ -40,22 +42,27 @@ test_float (void) {
|
||||
for (unsigned i = 0; i < ITERATIONS; ++i)
|
||||
++counts[unsigned (util::random<float> () * BUCKETS)];
|
||||
|
||||
bool success = true;
|
||||
for (unsigned c: counts) {
|
||||
unsigned diff = EXPECTED > c ?
|
||||
EXPECTED - c :
|
||||
c - EXPECTED;
|
||||
|
||||
CHECK_LT (diff, THRESHOLD);
|
||||
success = success && diff < THRESHOLD;
|
||||
}
|
||||
|
||||
tap.expect (success, "approximately equal float buckets");
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int, char **) {
|
||||
srand (time (NULL));
|
||||
test_bool ();
|
||||
test_float ();
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
|
||||
srand (time (NULL));
|
||||
|
||||
test_bool (tap);
|
||||
test_float (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -1,56 +1,54 @@
|
||||
#include "debug.hpp"
|
||||
#include "range.hpp"
|
||||
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
using namespace std;
|
||||
using namespace util;
|
||||
|
||||
int
|
||||
main (int, char **) {
|
||||
main (int, char **)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
// Check some simple cases close to the edges of a unit range. Tests float rounding.
|
||||
CHECK ( range<double>::UNIT.contains ( 0.0));
|
||||
CHECK ( range<double>::UNIT.contains ( 0.5));
|
||||
CHECK ( range<double>::UNIT.contains ( 1.0));
|
||||
CHECK ( range<double>::UNIT.contains (std::numeric_limits<double>::min ()));
|
||||
CHECK (!range<double>::UNIT.contains (-0.00001));
|
||||
CHECK (!range<double>::UNIT.contains ( 1.00001));
|
||||
tap.expect ( util::range<double>::UNIT.contains ( 0.0), "floating unit contains 0");
|
||||
tap.expect ( util::range<double>::UNIT.contains ( 1.0), "floating unit contains 1");
|
||||
tap.expect ( util::range<double>::UNIT.contains (std::numeric_limits<double>::min ()), "floating unit contains min");
|
||||
tap.expect (!util::range<double>::UNIT.contains (-0.00001), "doesn't contain fractionally low value");
|
||||
tap.expect (!util::range<double>::UNIT.contains ( 1.00001), "doesn't contain fractionally high value");
|
||||
|
||||
// Check edge cases of unit with integer values
|
||||
CHECK ( range<uint16_t>::UNIT.contains (0));
|
||||
CHECK ( range<uint16_t>::UNIT.contains (1));
|
||||
CHECK (!range<uint16_t>::UNIT.contains (2));
|
||||
CHECK (!range<uint16_t>::UNIT.contains (numeric_limits <uint16_t>::max ()));
|
||||
tap.expect ( util::range<uint16_t>::UNIT.contains (0), "unsigned unit contains 0");
|
||||
tap.expect ( util::range<uint16_t>::UNIT.contains (1), "unsigned unit contains 1");
|
||||
tap.expect (!util::range<uint16_t>::UNIT.contains (2), "unsigned unit doesn't contain 2");
|
||||
tap.expect (!util::range<uint16_t>::UNIT.contains (std::numeric_limits <uint16_t>::max ()), "unsigned unit doesn't contain max");
|
||||
|
||||
// Check the inclusivity of UNLIMITED with special floating values
|
||||
CHECK ( range<double>::UNLIMITED.contains (0.0));
|
||||
CHECK ( range<double>::UNLIMITED.contains (+numeric_limits<double>::infinity ()));
|
||||
CHECK ( range<double>::UNLIMITED.contains (-numeric_limits<double>::infinity ()));
|
||||
CHECK (!range<double>::UNLIMITED.contains ( numeric_limits<double>::quiet_NaN ()));
|
||||
tap.expect ( util::range<double>::UNLIMITED.contains (0.0), "floating unlimited contains 0");
|
||||
tap.expect ( util::range<double>::UNLIMITED.contains (+std::numeric_limits<double>::infinity ()), "floating unlimited contains +INF");
|
||||
tap.expect ( util::range<double>::UNLIMITED.contains (-std::numeric_limits<double>::infinity ()), "floating unlimited contains -INF");
|
||||
tap.expect (!util::range<double>::UNLIMITED.contains ( std::numeric_limits<double>::quiet_NaN ()), "floating unlimited doesn't contain NAN");
|
||||
|
||||
// Check the inclusivity of UNLIMITED with some large numbers
|
||||
CHECK ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::min()));
|
||||
CHECK ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::max()));
|
||||
tap.expect ( util::range<uint16_t>::UNLIMITED.contains (std::numeric_limits<uint16_t>::min()), "floating unlimited contains min");
|
||||
tap.expect ( util::range<uint16_t>::UNLIMITED.contains (std::numeric_limits<uint16_t>::max()), "floating unlimited contains max");
|
||||
|
||||
// Check inclusivity of MAX
|
||||
CHECK (!range<double>::MAX.contains ( numeric_limits<double>::infinity ()));
|
||||
CHECK (!range<double>::MAX.contains (-numeric_limits<double>::infinity ()));
|
||||
tap.expect (!util::range<double>::MAX.contains ( std::numeric_limits<double>::infinity ()), "floating max contains +INF");
|
||||
tap.expect (!util::range<double>::MAX.contains (-std::numeric_limits<double>::infinity ()), "floating max contains -INF");
|
||||
|
||||
CHECK ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::min()));
|
||||
CHECK ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::max()));
|
||||
tap.expect ( util::range<uint16_t>::MAX.contains (std::numeric_limits<uint16_t>::min()), "unsigned max contains min");
|
||||
tap.expect ( util::range<uint16_t>::MAX.contains (std::numeric_limits<uint16_t>::max()), "unsigned max contains max");
|
||||
|
||||
// Check that expansion via NaN is a noop
|
||||
{
|
||||
range<double> initial_nan (numeric_limits<double>::quiet_NaN (),
|
||||
numeric_limits<double>::quiet_NaN ());
|
||||
util::range<double> initial_nan (std::numeric_limits<double>::quiet_NaN (),
|
||||
std::numeric_limits<double>::quiet_NaN ());
|
||||
initial_nan.expand (1.0);
|
||||
CHECK_EQ (initial_nan.min, 1.0);
|
||||
CHECK_EQ (initial_nan.max, 1.0);
|
||||
|
||||
tap.expect_eq (initial_nan.min, 1.0, "NAN expansion noop for min");
|
||||
tap.expect_eq (initial_nan.max, 1.0, "NAN expansion noop for max");
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
return tap.status ();
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,15 @@
|
||||
#include "region.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "point.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
using namespace util;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
main (int, char **) {
|
||||
main (int, char **)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
{
|
||||
util::point2d ap { 32.7, -6.09703 };
|
||||
util::extent2d ae { 0.8, 2. };
|
||||
@ -15,32 +17,31 @@ main (int, char **) {
|
||||
util::point2d bp {33.5, -4.5};
|
||||
util::extent2d be { 0.5, 0.5 };
|
||||
|
||||
region2d a (ap, ae);
|
||||
region2d b (bp, be);
|
||||
util::region2d a (ap, ae);
|
||||
util::region2d b (bp, be);
|
||||
|
||||
CHECK (!a.intersects (b));
|
||||
tap.expect (!a.intersects (b), "simple 2d intersection");
|
||||
}
|
||||
|
||||
CHECK (region2d::MAX.intersects (region2d::UNIT));
|
||||
CHECK (region2f::MAX.intersects (region2f::UNIT));
|
||||
tap.expect (util::region2d::MAX.intersects (util::region2d::UNIT), "maximal region2d intersection");
|
||||
tap.expect (util::region2f::MAX.intersects (util::region2f::UNIT), "maximal region2f intersection");
|
||||
|
||||
CHECK_EQ (region2d::UNIT.area (), 1.0);
|
||||
CHECK_EQ (region2f::UNIT.area (), 1.0f);
|
||||
tap.expect_eq (util::region2d::UNIT.area (), 1.0, "unit region2d area");
|
||||
tap.expect_eq (util::region2f::UNIT.area (), 1.0f, "unit region2f area");
|
||||
|
||||
util::point2u p0 { 0 };
|
||||
util::extent2u e0 { 2 };
|
||||
|
||||
CHECK (region2u (p0, e0).includes (point2u {1, 1}));
|
||||
CHECK (region2u (p0, e0).includes (point2u {0, 0}));
|
||||
CHECK (region2u (p0, e0).includes (point2u {2, 2}));
|
||||
tap.expect (util::region2u (p0, e0).includes (util::point2u {1, 1}), "unsigned region centre inclusion");
|
||||
tap.expect (util::region2u (p0, e0).includes (util::point2u {0, 0}), "unsigned region base inclusion");
|
||||
tap.expect (util::region2u (p0, e0).includes (util::point2u {2, 2}), "unsigned region corner inclusion");
|
||||
|
||||
CHECK ( region2u (p0, e0).contains (point2u {1, 1}));
|
||||
CHECK (!region2u (p0, e0).contains (point2u {0, 0}));
|
||||
CHECK (!region2u (p0, e0).contains (point2u {2, 2}));
|
||||
tap.expect ( util::region2u (p0, e0).contains (util::point2u {1, 1}), "unsigned region center contains");
|
||||
tap.expect (!util::region2u (p0, e0).contains (util::point2u {0, 0}), "unsigned region base contains");
|
||||
tap.expect (!util::region2u (p0, e0).contains (util::point2u {2, 2}), "unsigned region corner contains");
|
||||
|
||||
//CHECK (region<2,intmax_t> (0, 0, 10, 10).includes (point2d (0.4, 0.01)));
|
||||
//CHECK (region<2,intmax_t> (0, 0, 10, 10).contains (point2d (0.4, 0.01)));
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -1,21 +1,18 @@
|
||||
#include "hash/ripemd.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "tap.hpp"
|
||||
#include "types.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using util::hash::RIPEMD;
|
||||
|
||||
static const
|
||||
struct {
|
||||
const char *input;
|
||||
RIPEMD::digest_t output;
|
||||
const char *msg;
|
||||
const char *data;
|
||||
util::hash::RIPEMD::digest_t output;
|
||||
} TESTS[] = {
|
||||
{
|
||||
"empty",
|
||||
"",
|
||||
{ 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28,
|
||||
0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31 },
|
||||
@ -26,6 +23,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"a",
|
||||
"a",
|
||||
{ 0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae,
|
||||
0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe },
|
||||
@ -36,6 +34,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
{ 0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04,
|
||||
0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc },
|
||||
@ -46,6 +45,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"message digest",
|
||||
"message digest",
|
||||
{ 0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8,
|
||||
0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36 },
|
||||
@ -56,6 +56,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"26 characters",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
{ 0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb,
|
||||
0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc },
|
||||
@ -66,6 +67,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"57 characters",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
{ 0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05,
|
||||
0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b },
|
||||
@ -76,6 +78,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"63 characters",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
{ 0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed,
|
||||
0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89 },
|
||||
@ -86,6 +89,7 @@ struct {
|
||||
},
|
||||
|
||||
{
|
||||
"81 digits",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
{ 0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb,
|
||||
0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb }
|
||||
@ -104,23 +108,22 @@ struct {
|
||||
|
||||
int
|
||||
main(int, char**) {
|
||||
// Check against simple test vectors
|
||||
for (size_t i = 0; i < elems (TESTS); ++i) {
|
||||
std::cout << "testing '" << TESTS[i].input << "'\n";
|
||||
util::TAP::logger tap;
|
||||
|
||||
// Check against simple test vectors
|
||||
for (const auto &i: TESTS) {
|
||||
util::hash::RIPEMD obj;
|
||||
obj.update (reinterpret_cast<const uint8_t*> (TESTS[i].input),
|
||||
strlen (TESTS[i].input));
|
||||
obj.update (reinterpret_cast<const uint8_t*> (i.data), strlen (i.data));
|
||||
obj.finish ();
|
||||
|
||||
CHECK (obj.digest () == TESTS[i].output);
|
||||
tap.expect_eq (obj.digest (), i.output, i.msg);
|
||||
}
|
||||
|
||||
// Perform 'million-a' check
|
||||
static const size_t CHUNK_WIDTH = 1000;
|
||||
static const size_t CHUNK_WIDTH = 1'000;
|
||||
util::hash::RIPEMD obj;
|
||||
|
||||
for (size_t i = 0; i < 1000000; i += CHUNK_WIDTH) {
|
||||
for (size_t i = 0; i < 1'000'000; i += CHUNK_WIDTH) {
|
||||
uint8_t data[CHUNK_WIDTH];
|
||||
memset (data, 'a', sizeof (data));
|
||||
|
||||
@ -132,8 +135,8 @@ main(int, char**) {
|
||||
0x52, 0x78, 0x32, 0x43, 0xc1, 0x69, 0x7b, 0xdb, 0xe1, 0x6d,
|
||||
0x37, 0xf9, 0x7f, 0x68, 0xf0, 0x83, 0x25, 0xdc, 0x15, 0x28
|
||||
};
|
||||
CHECK (obj.digest () == MILLION);
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
tap.expect_eq (obj.digest (), MILLION, "million 'a'");
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -10,32 +10,40 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using util::hash::SHA1;
|
||||
|
||||
|
||||
int
|
||||
main (int, char**) {
|
||||
main (int, char**)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
static const struct {
|
||||
const char *msg;
|
||||
const char *input;
|
||||
SHA1::digest_t output;
|
||||
util::hash::SHA1::digest_t output;
|
||||
} TESTS[] = {
|
||||
{ "",
|
||||
{
|
||||
"empty string",
|
||||
"",
|
||||
{ { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55,
|
||||
0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 } }
|
||||
},
|
||||
|
||||
{
|
||||
"single a",
|
||||
"a",
|
||||
{ { 0x86, 0xf7, 0xe4, 0x37, 0xfa, 0xa5, 0xa7, 0xfc, 0xe1, 0x5d,
|
||||
0x1d, 0xdc, 0xb9, 0xea, 0xea, 0xea, 0x37, 0x76, 0x67, 0xb8 } }
|
||||
},
|
||||
|
||||
{ "abc",
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
{ { 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E,
|
||||
0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D } }
|
||||
},
|
||||
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
{
|
||||
"abc...opq",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
{ { 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE,
|
||||
0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 } }
|
||||
},
|
||||
@ -53,22 +61,13 @@ main (int, char**) {
|
||||
//}
|
||||
};
|
||||
|
||||
for (auto i: TESTS) {
|
||||
for (const auto &i: TESTS) {
|
||||
util::hash::SHA1 obj;
|
||||
obj.update (reinterpret_cast<const uint8_t*> (i.input), strlen (i.input));
|
||||
obj.finish ();
|
||||
|
||||
for (uint8_t c: obj.digest ()) {
|
||||
unsigned hi = c >> 4u;
|
||||
unsigned lo = c & 0xF;
|
||||
|
||||
std::cout << std::hex << hi << lo << " ";
|
||||
}
|
||||
std::cout << "\n";
|
||||
|
||||
CHECK (obj.digest () == i.output);
|
||||
tap.expect_eq (obj.digest (), i.output, i.msg);
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
#include "hash/sha2.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using util::hash::SHA256;
|
||||
|
||||
static const struct {
|
||||
const char *input;
|
||||
SHA256::digest_t output;
|
||||
const char *msg;
|
||||
const char *input;
|
||||
util::hash::SHA256::digest_t output;
|
||||
} TESTS[] = {
|
||||
{ "",
|
||||
{ 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
|
||||
0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55 }
|
||||
{
|
||||
"empty",
|
||||
"",
|
||||
{ 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
|
||||
0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C, 0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55 }
|
||||
},
|
||||
|
||||
{ "a",
|
||||
{ 0xCA, 0x97, 0x81, 0x12, 0xCA, 0x1B, 0xBD, 0xCA, 0xFA, 0xC2, 0x31, 0xB3, 0x9A, 0x23, 0xDC, 0x4D,
|
||||
0xA7, 0x86, 0xEF, 0xF8, 0x14, 0x7C, 0x4E, 0x72, 0xB9, 0x80, 0x77, 0x85, 0xAF, 0xEE, 0x48, 0xBB }
|
||||
{
|
||||
"single a",
|
||||
"a",
|
||||
{ 0xCA, 0x97, 0x81, 0x12, 0xCA, 0x1B, 0xBD, 0xCA, 0xFA, 0xC2, 0x31, 0xB3, 0x9A, 0x23, 0xDC, 0x4D,
|
||||
0xA7, 0x86, 0xEF, 0xF8, 0x14, 0x7C, 0x4E, 0x72, 0xB9, 0x80, 0x77, 0x85, 0xAF, 0xEE, 0x48, 0xBB }
|
||||
},
|
||||
|
||||
{ "abc",
|
||||
{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
|
||||
0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
|
||||
{
|
||||
"abc",
|
||||
"abc",
|
||||
{ 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23,
|
||||
0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD },
|
||||
},
|
||||
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
|
||||
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }
|
||||
{
|
||||
"abc...opq",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
|
||||
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }
|
||||
},
|
||||
|
||||
{ "0123456701234567012345670123456701234567012345670123456701234567",
|
||||
{ 0x81, 0x82, 0xCA, 0xDB, 0x21, 0xAF, 0x0E, 0x37, 0xC0, 0x64, 0x14, 0xEC, 0xE0, 0x8E, 0x19, 0xC6,
|
||||
0x5B, 0xDB, 0x22, 0xC3, 0x96, 0xD4, 0x8B, 0xA7, 0x34, 0x10, 0x12, 0xEE, 0xA9, 0xFF, 0xDF, 0xDD }
|
||||
{
|
||||
"77 digits",
|
||||
"0123456701234567012345670123456701234567012345670123456701234567",
|
||||
{ 0x81, 0x82, 0xCA, 0xDB, 0x21, 0xAF, 0x0E, 0x37, 0xC0, 0x64, 0x14, 0xEC, 0xE0, 0x8E, 0x19, 0xC6,
|
||||
0x5B, 0xDB, 0x22, 0xC3, 0x96, 0xD4, 0x8B, 0xA7, 0x34, 0x10, 0x12, 0xEE, 0xA9, 0xFF, 0xDF, 0xDD }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
main (int, char **) {
|
||||
for (auto i: TESTS) {
|
||||
SHA256 obj;
|
||||
util::TAP::logger tap;
|
||||
|
||||
for (const auto &i: TESTS) {
|
||||
util::hash::SHA256 obj;
|
||||
obj.update (reinterpret_cast<const uint8_t*> (i.input), strlen (i.input));
|
||||
obj.finish ();
|
||||
|
||||
std::cout << std::hex;
|
||||
for (auto c: obj.digest ()) {
|
||||
unsigned hi = c >> 4u;
|
||||
unsigned lo = c & 0xF;
|
||||
|
||||
std::cout << hi << lo << " ";
|
||||
}
|
||||
std::cout << "\n" << std::dec;
|
||||
|
||||
CHECK (obj.digest () == i.output);
|
||||
tap.expect_eq (obj.digest (), i.output, i.msg);
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
return tap.status ();
|
||||
}
|
||||
|
103
test/signal.cpp
103
test/signal.cpp
@ -1,16 +1,16 @@
|
||||
#include "signal.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "raii.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
test_null (void)
|
||||
test_null (util::TAP::logger &tap)
|
||||
{
|
||||
util::signal<void(void)> void_signal;
|
||||
void_signal ();
|
||||
tap.expect_nothrow ([] {
|
||||
util::signal<void(void)> void_signal;
|
||||
void_signal ();
|
||||
}, "void signal");
|
||||
}
|
||||
|
||||
|
||||
@ -24,97 +24,99 @@ increment_uint (unsigned int &val)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
test_single (void)
|
||||
test_single (util::TAP::logger &tap)
|
||||
{
|
||||
unsigned int val = 0;
|
||||
util::signal<void(unsigned int&)> void_signal;
|
||||
|
||||
auto raii = void_signal.connect (increment_uint);
|
||||
auto cookie = void_signal.connect (increment_uint);
|
||||
void_signal (val);
|
||||
|
||||
CHECK_EQ (val, 1u);
|
||||
tap.expect_eq (val, 1u, "single listener");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
test_double (void)
|
||||
test_double (util::TAP::logger &tap)
|
||||
{
|
||||
unsigned int val = 0;
|
||||
util::signal<void(unsigned int&)> void_signal;
|
||||
|
||||
auto raii = void_signal.connect (increment_uint);
|
||||
auto raii = void_signal.connect (increment_uint);
|
||||
auto cookie0 = void_signal.connect (increment_uint);
|
||||
auto cookie1 = void_signal.connect (increment_uint);
|
||||
void_signal (val);
|
||||
|
||||
CHECK_EQ (val, 2u);
|
||||
tap.expect_eq (val, 2u, "double listener");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
test_linking_pointers (void)
|
||||
{
|
||||
util::signal<void(const char*)> ptr_signal;
|
||||
ptr_signal (nullptr);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
test_value_signal (void)
|
||||
test_value_signal (util::TAP::logger &tap)
|
||||
{
|
||||
util::value_signal<unsigned> val;
|
||||
auto raii = val.connect ([] (unsigned v) { CHECK_EQ (v, 42u); });
|
||||
unsigned passed = 0;
|
||||
|
||||
auto cookie = val.connect ([&] (unsigned v) { passed = v; });
|
||||
|
||||
val = 42u;
|
||||
|
||||
tap.expect_eq (passed, 42u, "value signal, passed value");
|
||||
|
||||
unsigned check = val;
|
||||
CHECK_EQ (check, 42u);
|
||||
tap.expect_eq (check, 42u, "value signal, read value");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
test_combiner (void)
|
||||
test_combiner (util::TAP::logger &tap)
|
||||
{
|
||||
{
|
||||
util::signal<bool(void), util::combine::logical_and> sig;
|
||||
|
||||
unsigned count = 0;
|
||||
auto raii = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto raii = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto raii = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto cookie0 = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto cookie1 = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto cookie2 = sig.connect ([&] (void) { ++count; return true; });
|
||||
|
||||
CHECK (sig ());
|
||||
CHECK_EQ (count, 3u);
|
||||
tap.expect (sig (), "bool signal, success");
|
||||
tap.expect_eq (count, 3u, "bool signal, success, count");
|
||||
}
|
||||
|
||||
{
|
||||
util::signal<bool(void), util::combine::logical_and> sig;
|
||||
|
||||
unsigned count = 0;
|
||||
auto raii = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto raii = sig.connect ([&] (void) { ++count; return false; });
|
||||
auto raii = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto cookie0 = sig.connect ([&] (void) { ++count; return true; });
|
||||
auto cookie1 = sig.connect ([&] (void) { ++count; return false; });
|
||||
auto cookie2 = sig.connect ([&] (void) { ++count; return true; });
|
||||
|
||||
CHECK (!sig ());
|
||||
CHECK_EQ (count, 2u);
|
||||
tap.expect (!sig (), "bool signal, failure");
|
||||
|
||||
// ordering of signals is not guaranteed so we can't say for sure how
|
||||
// many callbacks will be triggered; it will _probably_ be in order
|
||||
// though.
|
||||
tap.expect_le (count, 3u, "bool signal, failure, count");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
test_disconnect (void)
|
||||
test_disconnect (util::TAP::logger &tap)
|
||||
{
|
||||
util::signal<void(void)> sig;
|
||||
tap.expect_nothrow ([] {
|
||||
util::signal<void(void)> sig;
|
||||
|
||||
util::signal<void(void)>::cookie a = sig.connect ([&] (void) { sig.disconnect (a); });
|
||||
util::signal<void(void)>::cookie b = sig.connect ([&] (void) { sig.disconnect (b); });
|
||||
util::signal<void(void)>::cookie c = sig.connect ([&] (void) { sig.disconnect (c); });
|
||||
util::signal<void(void)>::cookie d = sig.connect ([&] (void) { sig.disconnect (d); });
|
||||
util::signal<void(void)>::cookie a = sig.connect ([&] (void) { sig.disconnect (a); });
|
||||
util::signal<void(void)>::cookie b = sig.connect ([&] (void) { sig.disconnect (b); });
|
||||
util::signal<void(void)>::cookie c = sig.connect ([&] (void) { sig.disconnect (c); });
|
||||
util::signal<void(void)>::cookie d = sig.connect ([&] (void) { sig.disconnect (d); });
|
||||
|
||||
sig ();
|
||||
sig ();
|
||||
}, "parallel disconnect in invocation");
|
||||
}
|
||||
|
||||
|
||||
@ -122,13 +124,14 @@ test_disconnect (void)
|
||||
int
|
||||
main (int, char **)
|
||||
{
|
||||
test_null ();
|
||||
test_single ();
|
||||
test_double ();
|
||||
test_value_signal ();
|
||||
test_combiner ();
|
||||
test_disconnect ();
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
|
||||
test_null (tap);
|
||||
test_single (tap);
|
||||
test_double (tap);
|
||||
test_value_signal (tap);
|
||||
test_combiner (tap);
|
||||
test_disconnect (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -8,19 +8,20 @@
|
||||
|
||||
int
|
||||
main (int, char**) {
|
||||
util::TAP::logger tap;
|
||||
|
||||
util::stringid map;
|
||||
|
||||
CHECK_THROWS (std::out_of_range, map.find ("invalid"));
|
||||
tap.expect_throw<std::out_of_range> ([&] { map.find ("invalid"); }, "find on empty set throws");
|
||||
|
||||
auto id1 = map.add ("first");
|
||||
CHECK_EQ (id1, map.find ("first"));
|
||||
tap.expect_eq (id1, map.find ("first"), "single entity ID matches");
|
||||
|
||||
CHECK_THROWS (std::out_of_range, map.find ("invalid"));
|
||||
tap.expect_throw<std::out_of_range> ([&] { map.find ("invalid"); }, "invalid find throws");
|
||||
|
||||
auto id2 = map.add ("second");
|
||||
CHECK_EQ (id1 + 1, id2);
|
||||
CHECK_EQ (id1, map.find ("first"));
|
||||
tap.expect_eq (id1 + 1, id2, "monotonically increasing IDs");
|
||||
tap.expect_eq (id1, map.find ("first"), "first element still matches");
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
return tap.status ();
|
||||
}
|
||||
|
@ -1,53 +1,43 @@
|
||||
#include "version.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
static const struct {
|
||||
const char *msg;
|
||||
const char *str;
|
||||
unsigned parts[4];
|
||||
util::version::release_t release;
|
||||
|
||||
using namespace std;
|
||||
using namespace util;
|
||||
} TESTS[] = {
|
||||
{ "1-component", "1", { 1u }, util::version::PRODUCTION },
|
||||
|
||||
{ "2-component", "1.2", { 1u, 2u }, util::version::PRODUCTION },
|
||||
{ "3-component", "1.2.3", { 1u, 2u, 3u }, util::version::PRODUCTION },
|
||||
{ "4-component", "1.2.3.4", { 1u, 2u, 3u, 4u }, util::version::PRODUCTION },
|
||||
|
||||
struct parsed_version {
|
||||
string str;
|
||||
vector <unsigned int> parts;
|
||||
{ "2-component alpha", "9.5a", { 9u, 5u }, util::version::ALPHA },
|
||||
{ "3-component beta", "8.2.5b", { 8u, 2u, 5u }, util::version::BETA },
|
||||
|
||||
/*
|
||||
{ "1.4.1-p8", { 1, 4, 1 } },
|
||||
{ "4.2.0-r4", { 4, 2, 0 } },
|
||||
|
||||
{ "1.4 RC1", { 1, 4 } }
|
||||
*/
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
main () {
|
||||
vector <parsed_version> tests ({
|
||||
{ "1", { 1 } },
|
||||
|
||||
{ "1.2", { 1, 2 } },
|
||||
{ "1.2.3", { 1, 2, 3 } },
|
||||
{ "1.2.3.4", { 1, 2, 3, 4 } },
|
||||
|
||||
{ "9.5a", { 9, 5 } },
|
||||
{ "8.2.5b", { 8, 2, 5 } },
|
||||
|
||||
/*
|
||||
{ "1.4.1-p8", { 1, 4, 1 } },
|
||||
{ "4.2.0-r4", { 4, 2, 0 } },
|
||||
|
||||
{ "1.4 RC1", { 1, 4 } }
|
||||
*/
|
||||
});
|
||||
|
||||
for (auto i = tests.begin (); i != tests.end (); ++i) {
|
||||
version v (i->str);
|
||||
|
||||
if (i->parts.size () > 0) CHECK (v.major () == i->parts[0]);
|
||||
if (i->parts.size () > 1) CHECK (v.minor () == i->parts[1]);
|
||||
if (i->parts.size () > 2) CHECK (v.point () == i->parts[2]);
|
||||
if (i->parts.size () > 3) CHECK (v.build () == i->parts[3]);
|
||||
|
||||
CHECK_LE (i->parts.size (), 4);
|
||||
}
|
||||
|
||||
util::TAP::logger tap;
|
||||
tap.skip ("convert to TAP");
|
||||
|
||||
for (const auto &i: TESTS) {
|
||||
util::version v (i.str);
|
||||
|
||||
tap.expect (std::equal (v.begin (), v.end (), i.parts) && v.release == i.release,
|
||||
i.msg);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user