Fixed tests

This commit is contained in:
Christophe Riccio
2018-09-21 15:25:54 +02:00
parent 635ff4ef2d
commit d5df61aa66
3 changed files with 55 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
#include <glm/ext/scalar_relational.hpp>
#include <glm/gtc/ulp.hpp>
#include <cmath>
static int test_equal_epsilon()
@@ -35,16 +36,16 @@ static int test_equal_ulps()
{
int Error = 0;
float const ULP1Plus = std::nextafter(1.0f, 2.0f);
float const ULP1Plus = glm::next_float(1.0f);
Error += glm::equal(1.0f, ULP1Plus, 1) ? 0 : 1;
float const ULP2Plus = std::nextafter(ULP1Plus, 2.0f);
float const ULP2Plus = glm::next_float(ULP1Plus);
Error += !glm::equal(1.0f, ULP2Plus, 1) ? 0 : 1;
float const ULP1Minus = std::nextafter(1.0f, 0.0f);
float const ULP1Minus = glm::prev_float(1.0f);
Error += glm::equal(1.0f, ULP1Minus, 1) ? 0 : 1;
float const ULP2Minus = std::nextafter(ULP1Minus, 0.0f);
float const ULP2Minus = glm::prev_float(ULP1Minus);
Error += !glm::equal(1.0f, ULP2Minus, 1) ? 0 : 1;
return Error;
@@ -54,16 +55,16 @@ static int test_notEqual_ulps()
{
int Error = 0;
float const ULP1Plus = std::nextafter(1.0f, 2.0f);
float const ULP1Plus = glm::next_float(1.0f);
Error += !glm::notEqual(1.0f, ULP1Plus, 1) ? 0 : 1;
float const ULP2Plus = std::nextafter(ULP1Plus, 2.0f);
float const ULP2Plus = glm::next_float(ULP1Plus);
Error += glm::notEqual(1.0f, ULP2Plus, 1) ? 0 : 1;
float const ULP1Minus = std::nextafter(1.0f, 0.0f);
float const ULP1Minus = glm::prev_float(1.0f);
Error += !glm::notEqual(1.0f, ULP1Minus, 1) ? 0 : 1;
float const ULP2Minus = std::nextafter(ULP1Minus, 0.0f);
float const ULP2Minus = glm::prev_float(ULP1Minus);
Error += glm::notEqual(1.0f, ULP2Minus, 1) ? 0 : 1;
return Error;

View File

@@ -15,6 +15,7 @@
#include <glm/ext/vector_double3_precision.hpp>
#include <glm/ext/vector_double4.hpp>
#include <glm/ext/vector_double4_precision.hpp>
#include <glm/gtc/ulp.hpp>
template <typename vecType>
static int test_equal()
@@ -73,26 +74,23 @@ static int test_equal_ulps()
{
typedef glm::vec<4, T, glm::defaultp> vec4;
T const Zero(0);
T const One(1);
T const Two(2);
vec4 const Ones(1);
int Error = 0;
T const ULP1Plus = std::nextafter(One, Two);
T const ULP1Plus = glm::next_float(One);
Error += glm::all(glm::equal(Ones, vec4(ULP1Plus), 1)) ? 0 : 1;
T const ULP2Plus = std::nextafter(ULP1Plus, Two);
T const ULP2Plus = glm::next_float(ULP1Plus);
Error += !glm::all(glm::equal(Ones, vec4(ULP2Plus), 1)) ? 0 : 1;
T const ULP1Minus = std::nextafter(One, Zero);
T const ULP1Minus = glm::prev_float(One);
Error += glm::all(glm::equal(Ones, vec4(ULP1Minus), 1)) ? 0 : 1;
T const ULP2Minus = std::nextafter(ULP1Minus, Zero);
T const ULP2Minus = glm::prev_float(ULP1Minus);
Error += !glm::all(glm::equal(Ones, vec4(ULP2Minus), 1)) ? 0 : 1;
return Error;
}
@@ -100,27 +98,24 @@ template <typename T>
static int test_notEqual_ulps()
{
typedef glm::vec<4, T, glm::defaultp> vec4;
T const Zero(0);
T const One(1);
T const Two(2);
T const One(1);
vec4 const Ones(1);
int Error = 0;
T const ULP1Plus = std::nextafter(One, Two);
T const ULP1Plus = glm::next_float(One);
Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Plus), 1)) ? 0 : 1;
T const ULP2Plus = std::nextafter(ULP1Plus, Two);
T const ULP2Plus = glm::next_float(ULP1Plus);
Error += glm::all(glm::notEqual(Ones, vec4(ULP2Plus), 1)) ? 0 : 1;
T const ULP1Minus = std::nextafter(One, Zero);
T const ULP1Minus = glm::prev_float(One);
Error += !glm::all(glm::notEqual(Ones, vec4(ULP1Minus), 1)) ? 0 : 1;
T const ULP2Minus = std::nextafter(ULP1Minus, Zero);
T const ULP2Minus = glm::prev_float(ULP1Minus);
Error += glm::all(glm::notEqual(Ones, vec4(ULP2Minus), 1)) ? 0 : 1;
return Error;
}
@@ -132,7 +127,7 @@ int main()
Error += test_equal_ulps<double>();
Error += test_notEqual_ulps<float>();
Error += test_notEqual_ulps<double>();
Error += test_equal<glm::vec1>();
Error += test_equal<glm::lowp_vec1>();
Error += test_equal<glm::mediump_vec1>();