mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 14:11:28 +07:00
rename unit test approx classes
This commit is contained in:
@@ -15,8 +15,8 @@ namespace
|
||||
|
||||
TEST_CASE("vmath/fun") {
|
||||
SUBCASE("Angle and Trigonometry Functions") {
|
||||
STATIC_REQUIRE(radians(degrees(12.13f)) == approx(12.13f));
|
||||
STATIC_REQUIRE(degrees(radians(12.13f)) == approx(12.13f));
|
||||
STATIC_REQUIRE(radians(degrees(12.13f)) == uapprox(12.13f));
|
||||
STATIC_REQUIRE(degrees(radians(12.13f)) == uapprox(12.13f));
|
||||
|
||||
(void)sin(0.f);
|
||||
(void)cos(0.f);
|
||||
@@ -38,8 +38,8 @@ TEST_CASE("vmath/fun") {
|
||||
{
|
||||
float out_s{}, out_c{};
|
||||
sincos(15.f, &out_s, &out_c);
|
||||
REQUIRE(out_s == approx(sin(15.f)));
|
||||
REQUIRE(out_c == approx(cos(15.f)));
|
||||
REQUIRE(out_s == uapprox(sin(15.f)));
|
||||
REQUIRE(out_c == uapprox(cos(15.f)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,90 +56,90 @@ TEST_CASE("vmath/fun") {
|
||||
SUBCASE("Common Functions") {
|
||||
STATIC_REQUIRE(vmath_hpp::abs(1) == 1);
|
||||
STATIC_REQUIRE(vmath_hpp::abs(-1) == 1);
|
||||
STATIC_REQUIRE(vmath_hpp::abs(1.f) == approx(1.f));
|
||||
STATIC_REQUIRE(vmath_hpp::abs(-1.f) == approx(1.f));
|
||||
STATIC_REQUIRE(vmath_hpp::abs(1.f) == uapprox(1.f));
|
||||
STATIC_REQUIRE(vmath_hpp::abs(-1.f) == uapprox(1.f));
|
||||
|
||||
STATIC_REQUIRE(sign(2) == 1);
|
||||
STATIC_REQUIRE(sign(-2) == -1);
|
||||
STATIC_REQUIRE(sign(0) == 0);
|
||||
STATIC_REQUIRE(sign(2.f) == approx(1.f));
|
||||
STATIC_REQUIRE(sign(-2.f) == approx(-1.f));
|
||||
STATIC_REQUIRE(sign(0.f) == approx(0.f));
|
||||
STATIC_REQUIRE(sign(2.f) == uapprox(1.f));
|
||||
STATIC_REQUIRE(sign(-2.f) == uapprox(-1.f));
|
||||
STATIC_REQUIRE(sign(0.f) == uapprox(0.f));
|
||||
|
||||
STATIC_REQUIRE(reciprocal(2.f) == approx(0.5f));
|
||||
STATIC_REQUIRE(reciprocal(4.f) == approx(0.25f));
|
||||
STATIC_REQUIRE(reciprocal(2.f) == uapprox(0.5f));
|
||||
STATIC_REQUIRE(reciprocal(4.f) == uapprox(0.25f));
|
||||
|
||||
REQUIRE(floor(1.7f) == approx(1.f));
|
||||
REQUIRE(trunc(1.7f) == approx(1.f));
|
||||
REQUIRE(round(1.7f) == approx(2.f));
|
||||
REQUIRE(ceil(1.7f) == approx(2.f));
|
||||
REQUIRE(floor(1.7f) == uapprox(1.f));
|
||||
REQUIRE(trunc(1.7f) == uapprox(1.f));
|
||||
REQUIRE(round(1.7f) == uapprox(2.f));
|
||||
REQUIRE(ceil(1.7f) == uapprox(2.f));
|
||||
|
||||
REQUIRE(fract(1.7f) == approx(0.7f));
|
||||
REQUIRE(fract(-2.3f) == approx(0.7f));
|
||||
REQUIRE(fract(1.7f) == uapprox(0.7f));
|
||||
REQUIRE(fract(-2.3f) == uapprox(0.7f));
|
||||
|
||||
REQUIRE(fmod(1.7f, 1.2f) == approx(0.5f));
|
||||
REQUIRE(fmod(1.7f, 1.2f) == uapprox(0.5f));
|
||||
|
||||
{
|
||||
float out_i{};
|
||||
REQUIRE(modf(1.7f, &out_i) == approx(0.7f));
|
||||
REQUIRE(out_i == approx(1.f));
|
||||
REQUIRE(modf(1.7f, &out_i) == uapprox(0.7f));
|
||||
REQUIRE(out_i == uapprox(1.f));
|
||||
}
|
||||
|
||||
STATIC_REQUIRE(min(0.f, 1.f) == approx(0.f));
|
||||
STATIC_REQUIRE(min(3.f, 2.f, 1.f) == approx(1.f));
|
||||
STATIC_REQUIRE(min(4.f, 3.f, 2.f, 1.f) == approx(1.f));
|
||||
STATIC_REQUIRE(min(0.f, 1.f) == uapprox(0.f));
|
||||
STATIC_REQUIRE(min(3.f, 2.f, 1.f) == uapprox(1.f));
|
||||
STATIC_REQUIRE(min(4.f, 3.f, 2.f, 1.f) == uapprox(1.f));
|
||||
|
||||
STATIC_REQUIRE(max(0.f, 1.f) == approx(1.f));
|
||||
STATIC_REQUIRE(max(3.f, 2.f, 1.f) == approx(3.f));
|
||||
STATIC_REQUIRE(max(4.f, 3.f, 2.f, 1.f) == approx(4.f));
|
||||
STATIC_REQUIRE(max(0.f, 1.f) == uapprox(1.f));
|
||||
STATIC_REQUIRE(max(3.f, 2.f, 1.f) == uapprox(3.f));
|
||||
STATIC_REQUIRE(max(4.f, 3.f, 2.f, 1.f) == uapprox(4.f));
|
||||
|
||||
STATIC_REQUIRE(clamp(1.0f, 2.f, 3.f) == approx(2.0f));
|
||||
STATIC_REQUIRE(clamp(2.5f, 2.f, 3.f) == approx(2.5f));
|
||||
STATIC_REQUIRE(clamp(3.5f, 2.f, 3.f) == approx(3.0f));
|
||||
STATIC_REQUIRE(clamp(1.0f, 2.f, 3.f) == uapprox(2.0f));
|
||||
STATIC_REQUIRE(clamp(2.5f, 2.f, 3.f) == uapprox(2.5f));
|
||||
STATIC_REQUIRE(clamp(3.5f, 2.f, 3.f) == uapprox(3.0f));
|
||||
|
||||
STATIC_REQUIRE(saturate(-0.5f) == approx(0.f));
|
||||
STATIC_REQUIRE(saturate(0.5f) == approx(0.5f));
|
||||
STATIC_REQUIRE(saturate(1.5f) == approx(1.f));
|
||||
STATIC_REQUIRE(saturate(-0.5f) == uapprox(0.f));
|
||||
STATIC_REQUIRE(saturate(0.5f) == uapprox(0.5f));
|
||||
STATIC_REQUIRE(saturate(1.5f) == uapprox(1.f));
|
||||
|
||||
STATIC_REQUIRE(lerp(0.f, 10.f, 0.5f) == approx(5.f));
|
||||
STATIC_REQUIRE(step(0.5f, 0.4f) == approx(0.f));
|
||||
STATIC_REQUIRE(step(0.5f, 0.6f) == approx(1.f));
|
||||
STATIC_REQUIRE(smoothstep(0.f, 1.f, 0.1f) == approx(0.028f));
|
||||
STATIC_REQUIRE(lerp(0.f, 10.f, 0.5f) == uapprox(5.f));
|
||||
STATIC_REQUIRE(step(0.5f, 0.4f) == uapprox(0.f));
|
||||
STATIC_REQUIRE(step(0.5f, 0.6f) == uapprox(1.f));
|
||||
STATIC_REQUIRE(smoothstep(0.f, 1.f, 0.1f) == uapprox(0.028f));
|
||||
|
||||
REQUIRE_FALSE(vmath_hpp::isnan(1.f));
|
||||
REQUIRE_FALSE(vmath_hpp::isinf(1.f));
|
||||
REQUIRE(vmath_hpp::isfinite(1.f));
|
||||
|
||||
REQUIRE(fma(2.f, 3.f, 4.f) == approx(10.f));
|
||||
REQUIRE(fma(2.f, 3.f, 4.f) == uapprox(10.f));
|
||||
|
||||
{
|
||||
int out_exp{};
|
||||
REQUIRE(frexp(1.7f, &out_exp) == approx(0.85f));
|
||||
REQUIRE(frexp(1.7f, &out_exp) == uapprox(0.85f));
|
||||
REQUIRE(out_exp == 1);
|
||||
}
|
||||
|
||||
REQUIRE(ldexp(0.85f, 1) == approx(1.7f));
|
||||
REQUIRE(ldexp(0.85f, 1) == uapprox(1.7f));
|
||||
}
|
||||
|
||||
SUBCASE("Geometric Functions") {
|
||||
STATIC_REQUIRE(length(10.f) == approx(10.f));
|
||||
STATIC_REQUIRE(length(-10.f) == approx(10.f));
|
||||
STATIC_REQUIRE(length(10.f) == uapprox(10.f));
|
||||
STATIC_REQUIRE(length(-10.f) == uapprox(10.f));
|
||||
|
||||
STATIC_REQUIRE(length2(10.f) == approx(100.f));
|
||||
STATIC_REQUIRE(length2(-10.f) == approx(100.f));
|
||||
STATIC_REQUIRE(length2(10.f) == uapprox(100.f));
|
||||
STATIC_REQUIRE(length2(-10.f) == uapprox(100.f));
|
||||
|
||||
STATIC_REQUIRE(distance(5.f, 10.f) == approx(5.f));
|
||||
STATIC_REQUIRE(distance(-5.f, -10.f) == approx(5.f));
|
||||
STATIC_REQUIRE(distance(5.f, 10.f) == uapprox(5.f));
|
||||
STATIC_REQUIRE(distance(-5.f, -10.f) == uapprox(5.f));
|
||||
|
||||
STATIC_REQUIRE(distance2(5.f, 10.f) == approx(25.f));
|
||||
STATIC_REQUIRE(distance2(-5.f, -10.f) == approx(25.f));
|
||||
STATIC_REQUIRE(distance2(5.f, 10.f) == uapprox(25.f));
|
||||
STATIC_REQUIRE(distance2(-5.f, -10.f) == uapprox(25.f));
|
||||
|
||||
STATIC_REQUIRE(dot(2.f, 5.f) == approx(10.f));
|
||||
REQUIRE(normalize(0.5f) == approx(1.f));
|
||||
STATIC_REQUIRE(dot(2.f, 5.f) == uapprox(10.f));
|
||||
REQUIRE(normalize(0.5f) == uapprox(1.f));
|
||||
|
||||
STATIC_REQUIRE(faceforward(1.f, 2.f, 3.f) == approx(-1.f));
|
||||
STATIC_REQUIRE(reflect(1.f, 2.f) == approx(-7.f));
|
||||
REQUIRE(refract(1.f, 2.f, 1.f) == approx(-7.f));
|
||||
STATIC_REQUIRE(faceforward(1.f, 2.f, 3.f) == uapprox(-1.f));
|
||||
STATIC_REQUIRE(reflect(1.f, 2.f) == uapprox(-7.f));
|
||||
REQUIRE(refract(1.f, 2.f, 1.f) == uapprox(-7.f));
|
||||
}
|
||||
|
||||
SUBCASE("Relational Functions") {
|
||||
|
||||
Reference in New Issue
Block a user