diff options
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/test_assets.cc | 12 | ||||
| -rw-r--r-- | src/tests/test_maths.cc | 19 | ||||
| -rw-r--r-- | src/tests/test_sequence.cc | 37 | ||||
| -rw-r--r-- | src/tests/test_spectool.cc | 8 |
4 files changed, 45 insertions, 31 deletions
diff --git a/src/tests/test_assets.cc b/src/tests/test_assets.cc index ff1cae2..e8b6318 100644 --- a/src/tests/test_assets.cc +++ b/src/tests/test_assets.cc @@ -2,11 +2,11 @@ // It tests the asset manager's ability to retrieve packed data. // Verifies data integrity and size reporting. -#ifdef USE_TEST_ASSETS +#if defined(USE_TEST_ASSETS) #include "generated/test_assets.h" #else #include "generated/assets.h" -#endif +#endif /* defined(USE_TEST_ASSETS) */ #include <assert.h> #include <stdio.h> @@ -16,18 +16,18 @@ int main() { printf("Running AssetManager test...\n"); size_t size = 0; - const uint8_t *data = GetAsset(AssetId::ASSET_TEST_ASSET, &size); + const uint8_t* data = GetAsset(AssetId::ASSET_TEST_ASSET, &size); assert(data != nullptr); assert(size > 0); - const char *expected_prefix = "This is a test asset file."; - if (strncmp((const char *)data, expected_prefix, strlen(expected_prefix)) == + const char* expected_prefix = "This is a test asset file."; + if (strncmp((const char*)data, expected_prefix, strlen(expected_prefix)) == 0) { printf("Asset content verification: SUCCESS\n"); } else { printf("Asset content verification: FAILED\n"); - printf("Got: %.*s\n", (int)size, (const char *)data); + printf("Got: %.*s\n", (int)size, (const char*)data); return 1; } diff --git a/src/tests/test_maths.cc b/src/tests/test_maths.cc index e7a686c..d9bc4d1 100644 --- a/src/tests/test_maths.cc +++ b/src/tests/test_maths.cc @@ -9,7 +9,9 @@ #include <vector> // Checks if two floats are approximately equal -bool near(float a, float b, float e = 0.001f) { return std::abs(a - b) < e; } +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 <typename T> void test_vector_ops(int n) { @@ -22,16 +24,19 @@ template <typename T> void test_vector_ops(int n) { // Add T c = a + b; - for (int i = 0; i < n; ++i) assert(near(c[i], (float)(i + 1) + 10.0f)); + for (int i = 0; i < n; ++i) + assert(near(c[i], (float)(i + 1) + 10.0f)); // Scale T s = a * 2.0f; - for (int i = 0; i < n; ++i) assert(near(s[i], (float)(i + 1) * 2.0f)); + for (int i = 0; i < n; ++i) + assert(near(s[i], (float)(i + 1) * 2.0f)); // Dot Product // vec3(1,2,3) . vec3(1,2,3) = 1+4+9 = 14 float expected_dot = 0; - for (int i = 0; i < n; ++i) expected_dot += a[i] * a[i]; + for (int i = 0; i < n; ++i) + expected_dot += a[i] * a[i]; assert(near(T::dot(a, a), expected_dot)); // Norm (Length) @@ -43,7 +48,8 @@ template <typename T> void test_vector_ops(int n) { // Lerp T l = lerp(a, b, 0.3f); - for (int i = 0; i < n; ++i) assert(near(l[i], .7 * (i + 1) + .3 * 10.0f)); + for (int i = 0; i < n; ++i) + assert(near(l[i], .7 * (i + 1) + .3 * 10.0f)); } // Specific test for padding alignment in vec3 @@ -127,7 +133,8 @@ 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); + for (int i = 0; i < 60; ++i) + spring::solve(p, v, 10.0f, 0.5f, 0.016f); assert(p > 8.5f); // Test vector spring diff --git a/src/tests/test_sequence.cc b/src/tests/test_sequence.cc index 363846b..6b04302 100644 --- a/src/tests/test_sequence.cc +++ b/src/tests/test_sequence.cc @@ -19,23 +19,26 @@ static WGPURenderPassEncoder dummy_render_pass_encoder = // --- Dummy Effect for Tracking --- class DummyEffect : public Effect { -public: + public: int init_calls = 0; int start_calls = 0; int render_calls = 0; int end_calls = 0; bool is_pp = false; - DummyEffect(bool post_process = false) : is_pp(post_process) {} + DummyEffect(bool post_process = false) : is_pp(post_process) { + } - void init(MainSequence *demo) override { - init_calls++; + void init(MainSequence* demo) override { + ++init_calls; (void)demo; } - void start() override { start_calls++; } + void start() override { + ++start_calls; + } void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override { - render_calls++; + ++render_calls; (void)pass; (void)time; (void)beat; @@ -50,13 +53,17 @@ public: (void)intensity; (void)aspect_ratio; } - void end() override { end_calls++; } - bool is_post_process() const override { return is_pp; } + void end() override { + ++end_calls; + } + bool is_post_process() const override { + return is_pp; + } }; // --- Dummy PostProcessEffect for Tracking (unused in simplified tests) --- class DummyPostProcessEffect : public PostProcessEffect { -public: + public: int init_calls = 0; int render_calls = 0; int update_bind_group_calls = 0; @@ -66,13 +73,13 @@ public: (void)format; } - void init(MainSequence *demo) override { - init_calls++; + void init(MainSequence* demo) override { + ++init_calls; (void)demo; } void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override { - render_calls++; + ++render_calls; (void)pass; (void)time; (void)beat; @@ -80,7 +87,7 @@ public: (void)aspect_ratio; } void update_bind_group(WGPUTextureView input_view) override { - update_bind_group_calls++; + ++update_bind_group_calls; (void)input_view; } }; @@ -133,7 +140,7 @@ void test_effect_lifecycle() { } void test_simulate_until() { -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) printf(" test_simulate_until...\n"); MainSequence main_seq; main_seq.init_test(dummy_device, dummy_queue, dummy_format); @@ -158,7 +165,7 @@ void test_simulate_until() { assert(effect1->end_calls == 1); // Should end #else printf(" test_simulate_until (skipped in STRIP_ALL build)...\n"); -#endif +#endif /* !defined(STRIP_ALL) */ } int main() { diff --git a/src/tests/test_spectool.cc b/src/tests/test_spectool.cc index b9270ed..37a74b7 100644 --- a/src/tests/test_spectool.cc +++ b/src/tests/test_spectool.cc @@ -20,7 +20,7 @@ struct SpecHeader { int32_t num_frames; }; -void generate_test_wav(const char *path, int duration_seconds) { +void generate_test_wav(const char* path, int duration_seconds) { ma_encoder_config config = ma_encoder_config_init(ma_encoding_format_wav, ma_format_f32, 1, 32000); ma_encoder encoder; @@ -40,8 +40,8 @@ void generate_test_wav(const char *path, int duration_seconds) { } int main() { - const char *test_wav = "test_input.wav"; - const char *test_spec = "test_output.spec"; + const char* test_wav = "test_input.wav"; + const char* test_spec = "test_output.spec"; printf("Generating test WAV...\n"); generate_test_wav(test_wav, 1); @@ -54,7 +54,7 @@ int main() { assert(ret == 0); printf("Verifying .spec file...\n"); - FILE *f = fopen(test_spec, "rb"); + FILE* f = fopen(test_spec, "rb"); assert(f != NULL); SpecHeader header; |
