From 8dd77545b5ec2f45ce46b98dd7d94a3c4a13e290 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 14 Feb 2026 02:39:49 +0100 Subject: Factor common test patterns into reusable utilities Refactor duplicated test setup/teardown code into shared fixtures: - test_math_helpers.h: Float comparison (test_near, test_near_vec3) - AudioTestFixture: RAII wrapper for AudioEngine lifecycle - EffectTestFixture: Combined WebGPU + AudioEngine + MainSequence Migrated 9 test files (3 math, 6 audio) to use fixtures. Net reduction: 54 LOC (178 insertions, 232 deletions). All 34 tests passing. Co-Authored-By: Claude Sonnet 4.5 --- src/tests/common/test_math_helpers.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/tests/common/test_math_helpers.h (limited to 'src/tests/common/test_math_helpers.h') diff --git a/src/tests/common/test_math_helpers.h b/src/tests/common/test_math_helpers.h new file mode 100644 index 0000000..99e7f9d --- /dev/null +++ b/src/tests/common/test_math_helpers.h @@ -0,0 +1,18 @@ +// test_math_helpers.h - Math utilities for test code +// Common floating-point comparison helpers + +#pragma once +#include +#include "util/mini_math.h" + +// Floating-point comparison with epsilon tolerance +inline bool test_near(float a, float b, float epsilon = 1e-6f) { + return fabs(a - b) < epsilon; +} + +// Vector comparison +inline bool test_near_vec3(vec3 a, vec3 b, float epsilon = 1e-6f) { + return test_near(a.x, b.x, epsilon) && + test_near(a.y, b.y, epsilon) && + test_near(a.z, b.z, epsilon); +} -- cgit v1.2.3