Files
j3ml/tests/MathFuncTests.hpp
maxine 05d664ecba
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 6m37s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 24s
migrate to new JTest API
2024-08-21 20:21:14 -04:00

93 lines
2.6 KiB
C++

/// Josh's 3D Math Library
/// A C++20 Library for 3D Math, Computer Graphics, and Scientific Computing.
/// Developed and Maintained by Josh O'Leary @ Redacted Software.
/// Special Thanks to William Tomasine II and Maxine Hayes.
/// (c) 2024 Redacted Software
/// This work is dedicated to the public domain.
/// @file MathFuncTests.hpp
/// @desc Unit tests for core math functions
/// @edit 2024-07-06
#pragma once
#include <jtest/jtest.hpp>
#include <jtest/Unit.hpp>
#include <J3ML/J3ML.hpp>
jtest::Unit MathUnit {"Math"};
namespace MathTests
{
inline void Define()
{
using namespace jtest;
using namespace J3ML::Math;
using namespace J3ML;
MathUnit += Test("IsFinite", [] {
check(IsFinite<u32>(420));
check(IsFinite<u64>(25));
check(IsFinite(5.f));
check(IsFinite(5.0));
check(!IsFinite(Infinity));
check(!IsFinite(NotANumber));
});
MathUnit += Test("IsNotANumber", [] {
check(!IsNotANumber(5.f));
check(!IsNotANumber(5.0));
check(IsNotANumber(NotANumber));
check(!IsNotANumber(Infinity));
});
MathUnit += Test("IsInfinite", [] {
check(!IsInfinite(5.f));
check(!IsInfinite(5.0));
check(IsInfinite(Infinity));
});
MathUnit += Test("ReinterpretAsU32", [] {
check(ReinterpretAs<u32>(0.f) == 0x00000000);
check(ReinterpretAs<u32>(1.f) == 0x3F800000);
check(ReinterpretAs<u32>(2.f) == 0x40000000);
check(ReinterpretAs<u32>(-1.f) == 0xBF800000);
check(ReinterpretAs<u32>(Infinity) == 0x7F800000);
});
MathUnit += Test("ReinterpretAsFloat", [] {
check(ReinterpretAs<float, u32>(0x00000000) == 0.f);
check(ReinterpretAs<float, u32>(0x3F800000) == 1.f);
check(ReinterpretAs<float, u32>(0x40000000) == 2.f);
check(ReinterpretAs<float, u32>(0xBF800000) == -1.f);
check(ReinterpretAs<float>(0x7F800000) == Infinity);
check(IsNotANumber(ReinterpretAs<float>(0x7F800001)));
});
MathUnit += Test("SqrtVals", [] {
});
MathUnit += Test("SqrtPrecision", [] {
});
MathUnit += Test("SqrtRSqrtPrecision", [] {
});
MathUnit += Test("SqrtRecipPrecision", [] {
});
MathUnit += Test("Min", [] {});
MathUnit += Test("Max", [] {});
MathUnit += Test("IsPow2", [] {});
}
inline void Run()
{
MathUnit.RunAll();
}
}