summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-09 10:52:23 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-09 10:52:23 +0200
commit5bfd97756ad5c51e6a810d67ae69d054c7b38875 (patch)
tree83a469071c7e670f342fd161b1b6e1abfad981ac /test
parentf6d822abd400d7a61ccacb49df75212132bcec66 (diff)
a
Diffstat (limited to 'test')
-rw-r--r--test/app.hpp1
-rw-r--r--test/const-math.cpp72
-rw-r--r--test/main.cpp2
3 files changed, 75 insertions, 0 deletions
diff --git a/test/app.hpp b/test/app.hpp
index 44fbed11..a7bb7d8b 100644
--- a/test/app.hpp
+++ b/test/app.hpp
@@ -9,5 +9,6 @@ struct app final : Platform::WindowlessWglApplication // NOLINT(cppcoreguideline
int exec() override;
static bool test_json();
static bool test_tile_iter();
+ static bool test_const_math();
};
} // namespace Magnum::Examples
diff --git a/test/const-math.cpp b/test/const-math.cpp
new file mode 100644
index 00000000..3f125a1f
--- /dev/null
+++ b/test/const-math.cpp
@@ -0,0 +1,72 @@
+#include "app.hpp"
+#include "compat/assert.hpp"
+#include <type_traits>
+#include <Magnum/Math/Vector.h>
+#include <Magnum/Math/Vector2.h>
+#include <Magnum/Math/Vector3.h>
+#include <Magnum/Math/Vector4.h>
+
+#ifdef __GNUG__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
+
+using namespace Magnum;
+using Magnum::Math::Vector;
+
+template<typename vec, typename f>
+static constexpr void test_float2()
+{
+ const vec a{(f)1, (f)2}, b{(f)2, (f)3};
+
+ ASSERT(a[0] == (f)1 && a[1] == (f)2);
+ ASSERT(a + b == vec{(f)3, (f)5});
+ ASSERT(a - b == vec{(f)-1, (f)-1});
+ ASSERT(a * b == vec{(f)2, (f)6});
+ ASSERT(b / a == vec{(f)2, (f)1.5});
+ ASSERT(b.product() == (f)6);
+ ASSERT(b.sum() == (f)5);
+}
+
+template<typename ivec>
+static constexpr void test_int()
+{
+ using I = typename ivec::Type;
+ constexpr auto vec = [](auto x, auto y) { return ivec{(I)x, (I)y}; };
+ const auto a = vec(3, 5), b = vec(11, 7);
+
+ ASSERT(a[0] == 3 && a[1] == 5);
+ ASSERT(a + b == vec(14,12));
+ ASSERT(b - a == vec(8, 2));
+ ASSERT(b % a == vec(2, 2));
+ ASSERT(b / a == vec(3, 1));
+ ASSERT(a.product() == 15);
+ ASSERT(a.sum() == 8);
+}
+
+static constexpr void* compile_tests()
+{
+ test_float2<Vector<2, float>, float>();
+ test_float2<Vector<2, double>, double>();
+ test_float2<Vector2, float>();
+
+ test_int<Vector<2, int>>();
+ test_int<Vector<2, unsigned>>();
+ test_int<Vector<2, char>>();
+
+ return nullptr;
+}
+
+namespace Magnum::Examples {
+
+bool app::test_const_math()
+{
+ static_assert(compile_tests() == nullptr);
+ return true;
+}
+
+} // namespace Magnum::Examples
+
+#ifdef __GNUG__
+# pragma GCC diagnostic pop
+#endif
diff --git a/test/main.cpp b/test/main.cpp
index 06a2e64d..6dfe1f85 100644
--- a/test/main.cpp
+++ b/test/main.cpp
@@ -1,4 +1,5 @@
#include "app.hpp"
+#include "compat/assert.hpp"
#include "loader.hpp"
#include <filesystem>
#include <Corrade/Containers/Pair.h>
@@ -26,6 +27,7 @@ int app::exec()
bool ret = true;
ret &= test_json();
ret &= test_tile_iter();
+ ret &= test_const_math();
return !ret;
}