#include "util/mini_math.h" #include #include #include #include // Checks if two floats are approximately equal bool near(float a, float b, float e = 0.001f) { return std::abs(a - b) < e; } // Generic test runner for any vector type (vec2, vec3, vec4) template void test_vector_ops(int n) { T a, b; // Set values for(int i=0; i 0.5f); // Out curves should exceed linear value early assert(near(ease::in_out_quad(0.5f), 0.5f)); // Symmetric curves hit 0.5 at 0.5 } // Tests spring solver void test_spring() { std::cout << "Testing Spring..." << std::endl; float p = 0, v = 0; // Simulate approx 1 sec with 0.5s smooth time for(int i=0; i<60; ++i) spring::solve(p, v, 10.0f, 0.5f, 0.016f); assert(p > 8.5f); // Test vector spring vec3 vp(0,0,0), vv(0,0,0), vt(10,0,0); spring::solve(vp, vv, vt, 0.5f, 0.016f * 60.0f); // 1 huge step approx assert(vp.x > 1.0f); // Should have moved significantly } int main() { std::cout << "Testing vec2..." << std::endl; test_vector_ops(2); std::cout << "Testing vec3..." << std::endl; test_vector_ops(3); test_vec3_special(); std::cout << "Testing vec4..." << std::endl; test_vector_ops(4); test_quat(); test_matrices(); test_ease(); test_spring(); std::cout << "--- ALL TESTS PASSED ---" << std::endl; return 0; }