From fe7cec9ccbc7eed7ae74972da36e94d3b16ea0a5 Mon Sep 17 00:00:00 2001
From: namark <namark@disroot.org>
Date: Wed, 26 Aug 2020 02:20:09 +0400
Subject: [PATCH] Promotion defiance test for vector.
---
unit_tests/point.cpp | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/unit_tests/point.cpp b/unit_tests/point.cpp
index ca70dba..984659b 100644
--- a/unit_tests/point.cpp
+++ b/unit_tests/point.cpp
@@ -1,6 +1,7 @@
#include "simple/geom/vector.hpp"
#include <cmath>
#include <cassert>
+#include <cstdio>
using namespace simple;
using geom::vector;
@@ -452,6 +453,25 @@ void CoordinateOrder()
assert( int4(p_wzyx) == int4(4,3,2,1) );
}
+void DefyPromotion()
+{
+ using puny = unsigned short;
+ using vuny = vector<unsigned short,1>;
+ if constexpr (sizeof(puny) < sizeof(decltype(puny{} + puny{})))
+ {
+ puny p{1};
+ vuny v{p};
+ assert( puny( -p >> 1 ) == puny(-p) );
+ assert( vuny( -v >> 1 ) != vuny(-v) );
+ assert( puny( -p >> 1 ) != -p >> 1 );
+ assert( vuny( -v >> 1 ) == -v >> 1 );
+ }
+ else
+ {
+ std::puts("Type not puny enough, to test promotion defiance!");
+ }
+};
+
constexpr void Constexprness() // TODO: needs better coverage
{
constexpr int4 p = int4(1,2,3,4);
@@ -481,6 +501,7 @@ int main()
NumericLimits();
CoordinateOrder();
Constexprness();
+ DefyPromotion();
return 0;
}
--
GitLab