From 838d3fed97bd2ca6bdcec102bf918153f54f2316 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 5 Aug 2018 16:55:36 +0200 Subject: [PATCH] Added *vec1 tests --- test/ext/CMakeLists.txt | 3 + test/ext/ext_vector_dvec1.cpp | 130 ++++++++++++++++++++++++ test/ext/ext_vector_ivec1.cpp | 180 ++++++++++++++++++++++++++++++++++ test/ext/ext_vector_uvec1.cpp | 40 ++++++++ test/ext/ext_vector_vec1.cpp | 130 ++++++++++++++++++++++++ 5 files changed, 483 insertions(+) create mode 100644 test/ext/ext_vector_dvec1.cpp create mode 100644 test/ext/ext_vector_ivec1.cpp create mode 100644 test/ext/ext_vector_vec1.cpp diff --git a/test/ext/CMakeLists.txt b/test/ext/CMakeLists.txt index d03bc600..df749a69 100644 --- a/test/ext/CMakeLists.txt +++ b/test/ext/CMakeLists.txt @@ -1,6 +1,9 @@ glmCreateTestGTC(ext_matrix_relational) glmCreateTestGTC(ext_scalar_relational) glmCreateTestGTC(ext_vec1) +glmCreateTestGTC(ext_vector_vec1) glmCreateTestGTC(ext_vector_bvec1) +glmCreateTestGTC(ext_vector_dvec1) +glmCreateTestGTC(ext_vector_ivec1) glmCreateTestGTC(ext_vector_uvec1) glmCreateTestGTC(ext_vector_relational) diff --git a/test/ext/ext_vector_dvec1.cpp b/test/ext/ext_vector_dvec1.cpp new file mode 100644 index 00000000..e9232f45 --- /dev/null +++ b/test/ext/ext_vector_dvec1.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include +#include +#include + +template +static int test_operators() +{ + int Error = 0; + + { + genType const A(1); + genType const B(1); + + genType const C = A + B; + Error += glm::all(glm::equal(C, genType(2), glm::epsilon())) ? 0 : 1; + + genType const D = A - B; + Error += glm::all(glm::equal(D, genType(0), glm::epsilon())) ? 0 : 1; + + genType const E = A * B; + Error += glm::all(glm::equal(E, genType(1), glm::epsilon())) ? 0 : 1; + + genType const F = A / B; + Error += glm::all(glm::equal(F, genType(1), glm::epsilon())) ? 0 : 1; + } + + return Error; +} + +template +static int test_ctor() +{ + int Error = 0; + + glm::dvec1 const A = genType(1); + + glm::dvec1 const E(genType(1)); + Error += glm::all(glm::equal(A, E, glm::epsilon())) ? 0 : 1; + + glm::dvec1 const F(E); + Error += glm::all(glm::equal(A, F, glm::epsilon())) ? 0 : 1; + + genType const B = genType(1); + genType const G(glm::dvec2(1)); + Error += glm::all(glm::equal(B, G, glm::epsilon())) ? 0 : 1; + + genType const H(glm::dvec3(1)); + Error += glm::all(glm::equal(B, H, glm::epsilon())) ? 0 : 1; + + genType const I(glm::dvec4(1)); + Error += glm::all(glm::equal(B, I, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_size() +{ + int Error = 0; + + Error += sizeof(glm::dvec1) == sizeof(genType) ? 0 : 1; + Error += genType().length() == 1 ? 0 : 1; + Error += genType::length() == 1 ? 0 : 1; + + return Error; +} + +template +static int test_relational() +{ + int Error = 0; + + genType const A(1); + genType const B(1); + genType const C(0); + + Error += all(equal(A, B, glm::epsilon())) ? 0 : 1; + Error += any(notEqual(A, C, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_constexpr() +{ +# if GLM_CONFIG_CONSTEXP == GLM_ENABLE + static_assert(genType::length() == 1, "GLM: Failed constexpr"); + static_assert(glm::equal(genType(1)[0], 1.0, glm::epsilon()), "GLM: Failed constexpr"); + static_assert(glm::all(glm::equal(genType(1), genType(glm::vec1(1), glm::epsilon()), "GLM: Failed constexpr"); + static_assert(glm::all(glm::notEqual(genType(1), genType(0), glm::epsilon())), "GLM: Failed constexpr"); +# endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + + return Error; +} diff --git a/test/ext/ext_vector_ivec1.cpp b/test/ext/ext_vector_ivec1.cpp new file mode 100644 index 00000000..de2378b1 --- /dev/null +++ b/test/ext/ext_vector_ivec1.cpp @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include + +template +static int test_operators() +{ + int Error = 0; + + { + genType const A(1); + genType const B(1); + + bool const R = A != B; + bool const S = A == B; + Error += (S && !R) ? 0 : 1; + } + + { + genType const A(1); + genType const B(1); + + genType const C = A + B; + Error += C == genType(2) ? 0 : 1; + + genType const D = A - B; + Error += D == genType(0) ? 0 : 1; + + genType const E = A * B; + Error += E == genType(1) ? 0 : 1; + + genType const F = A / B; + Error += F == genType(1) ? 0 : 1; + } + + { + genType const A(3); + genType const B(2); + + genType const C = A % B; + Error += C == genType(1) ? 0 : 1; + } + + { + genType const A(1); + genType const B(1); + genType const C(0); + + genType const I = A & B; + Error += I == genType(1) ? 0 : 1; + genType const D = A & C; + Error += D == genType(0) ? 0 : 1; + + genType const E = A | B; + Error += E == genType(1) ? 0 : 1; + genType const F = A | C; + Error += F == genType(1) ? 0 : 1; + + genType const G = A ^ B; + Error += G == genType(0) ? 0 : 1; + genType const H = A ^ C; + Error += H == genType(1) ? 0 : 1; + } + + { + genType const A(0); + genType const B(1); + genType const C(2); + + genType const D = B << B; + Error += D == genType(2) ? 0 : 1; + genType const E = C >> B; + Error += E == genType(1) ? 0 : 1; + } + + return Error; +} + +template +static int test_ctor() +{ + int Error = 0; + + glm::ivec1 const A = genType(1); + + glm::ivec1 const E(genType(1)); + Error += A == E ? 0 : 1; + + glm::ivec1 const F(E); + Error += A == F ? 0 : 1; + + genType const B = genType(1); + genType const G(glm::ivec2(1)); + Error += B == G ? 0 : 1; + + genType const H(glm::ivec3(1)); + Error += B == H ? 0 : 1; + + genType const I(glm::ivec4(1)); + Error += B == I ? 0 : 1; + + return Error; +} + +template +static int test_size() +{ + int Error = 0; + + Error += sizeof(glm::ivec1) == sizeof(genType) ? 0 : 1; + Error += genType().length() == 1 ? 0 : 1; + Error += genType::length() == 1 ? 0 : 1; + + return Error; +} + +template +static int test_relational() +{ + int Error = 0; + + genType const A(1); + genType const B(1); + genType const C(0); + + Error += A == B ? 0 : 1; + Error += A != C ? 0 : 1; + Error += all(equal(A, B)) ? 0 : 1; + Error += any(notEqual(A, C)) ? 0 : 1; + + return Error; +} + +template +static int test_constexpr() +{ +# if GLM_CONFIG_CONSTEXP == GLM_ENABLE + static_assert(genType::length() == 1, "GLM: Failed constexpr"); + static_assert(genType(1)[0] == 1, "GLM: Failed constexpr"); + static_assert(genType(1) == genType(glm::ivec1(1)), "GLM: Failed constexpr"); + static_assert(genType(1) != genType(0), "GLM: Failed constexpr"); +# endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + + return Error; +} diff --git a/test/ext/ext_vector_uvec1.cpp b/test/ext/ext_vector_uvec1.cpp index d098bc44..48245385 100644 --- a/test/ext/ext_vector_uvec1.cpp +++ b/test/ext/ext_vector_uvec1.cpp @@ -36,6 +36,46 @@ static int test_operators() Error += F == genType(1) ? 0 : 1; } + { + genType const A(3); + genType const B(2); + + genType const C = A % B; + Error += C == genType(1) ? 0 : 1; + } + + { + genType const A(1); + genType const B(1); + genType const C(0); + + genType const I = A & B; + Error += I == genType(1) ? 0 : 1; + genType const D = A & C; + Error += D == genType(0) ? 0 : 1; + + genType const E = A | B; + Error += E == genType(1) ? 0 : 1; + genType const F = A | C; + Error += F == genType(1) ? 0 : 1; + + genType const G = A ^ B; + Error += G == genType(0) ? 0 : 1; + genType const H = A ^ C; + Error += H == genType(1) ? 0 : 1; + } + + { + genType const A(0); + genType const B(1); + genType const C(2); + + genType const D = B << B; + Error += D == genType(2) ? 0 : 1; + genType const E = C >> B; + Error += E == genType(1) ? 0 : 1; + } + return Error; } diff --git a/test/ext/ext_vector_vec1.cpp b/test/ext/ext_vector_vec1.cpp new file mode 100644 index 00000000..cd8ebe9a --- /dev/null +++ b/test/ext/ext_vector_vec1.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +#include +#include +#include + +template +static int test_operators() +{ + int Error = 0; + + { + genType const A(1); + genType const B(1); + + genType const C = A + B; + Error += glm::all(glm::equal(C, genType(2), glm::epsilon())) ? 0 : 1; + + genType const D = A - B; + Error += glm::all(glm::equal(D, genType(0), glm::epsilon())) ? 0 : 1; + + genType const E = A * B; + Error += glm::all(glm::equal(E, genType(1), glm::epsilon())) ? 0 : 1; + + genType const F = A / B; + Error += glm::all(glm::equal(F, genType(1), glm::epsilon())) ? 0 : 1; + } + + return Error; +} + +template +static int test_ctor() +{ + int Error = 0; + + glm::vec1 const A = genType(1); + + glm::vec1 const E(genType(1)); + Error += glm::all(glm::equal(A, E, glm::epsilon())) ? 0 : 1; + + glm::vec1 const F(E); + Error += glm::all(glm::equal(A, F, glm::epsilon())) ? 0 : 1; + + genType const B = genType(1); + genType const G(glm::vec2(1)); + Error += glm::all(glm::equal(B, G, glm::epsilon())) ? 0 : 1; + + genType const H(glm::vec3(1)); + Error += glm::all(glm::equal(B, H, glm::epsilon())) ? 0 : 1; + + genType const I(glm::vec4(1)); + Error += glm::all(glm::equal(B, I, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_size() +{ + int Error = 0; + + Error += sizeof(glm::vec1) == sizeof(genType) ? 0 : 1; + Error += genType().length() == 1 ? 0 : 1; + Error += genType::length() == 1 ? 0 : 1; + + return Error; +} + +template +static int test_relational() +{ + int Error = 0; + + genType const A(1); + genType const B(1); + genType const C(0); + + Error += all(equal(A, B, glm::epsilon())) ? 0 : 1; + Error += any(notEqual(A, C, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_constexpr() +{ +# if GLM_CONFIG_CONSTEXP == GLM_ENABLE + static_assert(genType::length() == 1, "GLM: Failed constexpr"); + static_assert(glm::equal(genType(1)[0], 1.0f, glm::epsilon()), "GLM: Failed constexpr"); + static_assert(glm::all(glm::equal(genType(1), genType(glm::vec1(1), glm::epsilon()), "GLM: Failed constexpr"); + static_assert(glm::all(glm::notEqual(genType(1), genType(0), glm::epsilon())), "GLM: Failed constexpr"); +# endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + + return Error; +}