123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "tests/MathTests.h"
- #include "math/Math.h"
- #include "test/Test.h"
- constexpr float eps = 0.0001f;
- static void testInterpolate() {
- CORE_TEST_FLOAT(7.5f, Core::Math::interpolate(5.0f, 10.0f, 0.5f), eps);
- CORE_TEST_FLOAT(-2.0, Core::Math::interpolate(-10.0f, 10.0f, 0.4f), eps);
- CORE_TEST_FLOAT(10.0f, Core::Math::interpolate(-3.0f, 10.0f, 1.0f), eps);
- CORE_TEST_FLOAT(7.0f, Core::Math::interpolate(7.0f, 10.0f, 0.0f), eps);
- CORE_TEST_FLOAT(6.0f, Core::Math::interpolate(0.0f, 10.0f, 0.6f), eps);
- }
- static void testRoundUpLog2() {
- CORE_TEST_EQUAL(0, Core::Math::roundUpLog2(-5));
- CORE_TEST_EQUAL(0, Core::Math::roundUpLog2(0));
- CORE_TEST_EQUAL(1, Core::Math::roundUpLog2(1));
- CORE_TEST_EQUAL(1, Core::Math::roundUpLog2(2));
- CORE_TEST_EQUAL(2, Core::Math::roundUpLog2(3));
- CORE_TEST_EQUAL(2, Core::Math::roundUpLog2(4));
- CORE_TEST_EQUAL(3, Core::Math::roundUpLog2(5));
- CORE_TEST_EQUAL(4, Core::Math::roundUpLog2(10));
- CORE_TEST_EQUAL(5, Core::Math::roundUpLog2(20));
- CORE_TEST_EQUAL(16, Core::Math::roundUpLog2(35345));
- CORE_TEST_EQUAL(31, Core::Math::roundUpLog2(0x7FFFFFFF));
- }
- static void testMin() {
- CORE_TEST_EQUAL(-5, Core::Math::min(-5));
- CORE_TEST_EQUAL(-10, Core::Math::min(-5, 4, 3, 2, -10));
- CORE_TEST_EQUAL(4, Core::Math::min(5, 20, 4, 30));
- }
- static void testMax() {
- CORE_TEST_EQUAL(-5, Core::Math::max(-5));
- CORE_TEST_EQUAL(4, Core::Math::max(-5, 4, 3, 2, -10));
- CORE_TEST_EQUAL(30, Core::Math::max(5, 20, 4, 30));
- }
- static void testClamp() {
- CORE_TEST_EQUAL(5, Core::Math::clamp(1, 5, 10));
- CORE_TEST_EQUAL(7, Core::Math::clamp(7, 5, 10));
- CORE_TEST_EQUAL(10, Core::Math::clamp(20, 5, 10));
- CORE_TEST_EQUAL(5, Core::Math::clamp(1, 10, 5));
- CORE_TEST_EQUAL(7, Core::Math::clamp(7, 10, 5));
- CORE_TEST_EQUAL(10, Core::Math::clamp(20, 10, 5));
- }
- void Core::MathTests::test() {
- testInterpolate();
- testRoundUpLog2();
- testMin();
- testMax();
- testClamp();
- }
|