50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include <cruft/util/tap.hpp>
|
|
#include <cruft/util/bool.hpp>
|
|
|
|
using cruft::tribool;
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
static char const*
|
|
tribool_to_str (tribool const &val)
|
|
{
|
|
if (!val.has ())
|
|
return "?";
|
|
|
|
return val.get () ? "t" : "f";
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
int main ()
|
|
{
|
|
cruft::TAP::logger tap;
|
|
|
|
|
|
{
|
|
// Exhausting `or` testing. Because why not.
|
|
static constexpr struct {
|
|
tribool a;
|
|
tribool b;
|
|
tribool res;
|
|
} TESTS[] = {
|
|
{ .a = tribool (false), .b = tribool (false), .res = tribool (false), },
|
|
{ .a = tribool (false), .b = tribool (true), .res = tribool (false), },
|
|
{ .a = tribool (true), .b = tribool (false), .res = tribool (true), },
|
|
{ .a = tribool (true), .b = tribool (true), .res = tribool (true) },
|
|
|
|
{ .a = tribool (nullptr), .b = tribool (false), .res = tribool (false), },
|
|
{ .a = tribool (nullptr), .b = tribool (true), .res = tribool (true), },
|
|
|
|
{ .a = tribool (true), .b = tribool (nullptr), .res = tribool (true), },
|
|
{ .a = tribool (false), .b = tribool (nullptr), .res = tribool (false), },
|
|
|
|
{ .a = tribool (nullptr), .b = tribool (nullptr), .res = tribool (nullptr), },
|
|
};
|
|
|
|
for (auto const &[a, b, res]: TESTS)
|
|
tap.expect ((a | b) == res, "{} | {}", tribool_to_str (a), tribool_to_str (b));
|
|
}
|
|
|
|
return tap.status ();
|
|
} |