#pragma once #include #include #include #include namespace test { struct TestCase { std::string name; std::function fn; }; std::vector ®istry(); struct Registrar { Registrar(const char *name, std::function fn); }; } // namespace test #define TEST_CASE(name) \ static void name(); \ static test::Registrar name##_registrar(#name, name); \ static void name() #define REQUIRE(expr) \ do \ { \ if (!(expr)) \ { \ throw std::runtime_error("Requirement failed: " #expr); \ } \ } while (false) // Layout maths runs in floats, so exact comparison would make the tests fragile // for reasons that have nothing to do with the behaviour under test. #define REQUIRE_NEAR(actual, expected) \ do \ { \ const float _a = static_cast(actual); \ const float _e = static_cast(expected); \ if (!(std::fabs(_a - _e) <= 0.01f)) \ { \ throw std::runtime_error("Requirement failed: " #actual " ~= " #expected); \ } \ } while (false)