From 55ed3610ffb8589505346141604c8b9ea2850e43 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 10:57:28 +0100 Subject: test(coverage): Improve Audio coverage (Task #48) Added unit tests for DCT and procedural audio generation. Enhanced synth tests to cover rendering and resource management. Audio subsystem coverage increased to 93%. --- src/tests/test_dct.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/tests/test_dct.cc (limited to 'src/tests/test_dct.cc') diff --git a/src/tests/test_dct.cc b/src/tests/test_dct.cc new file mode 100644 index 0000000..b40f392 --- /dev/null +++ b/src/tests/test_dct.cc @@ -0,0 +1,43 @@ +// This file is part of the 64k demo project. +// It tests the DCT implementation for correctness and coverage. + +#include "audio/dct.h" +#include +#include +#include +#include +#include + +void test_fdct_idct() { + float input[DCT_SIZE]; + float freq[DCT_SIZE]; + float output[DCT_SIZE]; + + // Initialize with random data + srand(12345); // Fixed seed for reproducibility + for (int i = 0; i < DCT_SIZE; ++i) { + input[i] = (float)rand() / RAND_MAX * 2.0f - 1.0f; + } + + fdct_512(input, freq); + idct_512(freq, output); + + // Verify reconstruction + float max_error = 0.0f; + for (int i = 0; i < DCT_SIZE; ++i) { + float err = std::abs(input[i] - output[i]); + if (err > max_error) max_error = err; + } + std::cout << "Max reconstruction error: " << max_error << std::endl; + + // Allow some error due to float precision and iterative sum + // 512 sums can accumulate error. + assert(max_error < 1e-4f); +} + +int main() { + std::cout << "Running DCT tests..." << std::endl; + test_fdct_idct(); + std::cout << "DCT tests PASSED" << std::endl; + return 0; +} -- cgit v1.2.3