aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/tests/real.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-23 00:32:38 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-23 00:32:38 +0100
commit0fa623093366351ad47583f47add6e51f56a56d8 (patch)
tree3eaaa64f5c9b88798d2b971d2810f85cc3e06cd6 /nihil.ucl/tests/real.cc
parent8cbb82a1f6eb6605a4615d30922b777e7bf1e4d8 (diff)
downloadnihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.gz
nihil-0fa623093366351ad47583f47add6e51f56a56d8.tar.bz2
nihil.ucl: improve tests
Diffstat (limited to 'nihil.ucl/tests/real.cc')
-rw-r--r--nihil.ucl/tests/real.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/nihil.ucl/tests/real.cc b/nihil.ucl/tests/real.cc
index 4bd9b3f..b11c113 100644
--- a/nihil.ucl/tests/real.cc
+++ b/nihil.ucl/tests/real.cc
@@ -2,13 +2,32 @@
* This source code is released into the public domain.
*/
+#include <concepts>
#include <string>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
+#include <ucl.h>
import nihil.ucl;
+TEST_CASE("ucl: real: invariants", "[ucl]")
+{
+ using namespace nihil::ucl;
+
+ static_assert(std::same_as<double, real::contained_type>);
+ REQUIRE(real::ucl_type == object_type::real);
+ REQUIRE(static_cast<::ucl_type>(real::ucl_type) == UCL_FLOAT);
+
+ static_assert(std::destructible<real>);
+ static_assert(std::default_initializable<real>);
+ static_assert(std::move_constructible<real>);
+ static_assert(std::copy_constructible<real>);
+ static_assert(std::equality_comparable<real>);
+ static_assert(std::totally_ordered<real>);
+ static_assert(std::swappable<real>);
+}
+
TEST_CASE("ucl: real: construct", "[ucl]")
{
auto obj = nihil::ucl::real(42.1);
@@ -22,6 +41,19 @@ TEST_CASE("ucl: real: default construct", "[ucl]")
REQUIRE(i == 0);
}
+TEST_CASE("ucl: real: swap", "[ucl]")
+{
+ // do not add using namespace nihil::ucl
+
+ auto r1 = nihil::ucl::real(1);
+ auto r2 = nihil::ucl::real(2);
+
+ swap(r1, r2);
+
+ REQUIRE(r1 == 2.);
+ REQUIRE(r2 == 1.);
+}
+
TEST_CASE("ucl: real: operator==", "[ucl]")
{
auto i = nihil::ucl::real(42.5);