summaryrefslogtreecommitdiff
path: root/src/tests/test_window.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_window.cc')
-rw-r--r--src/tests/test_window.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/tests/test_window.cc b/src/tests/test_window.cc
new file mode 100644
index 0000000..e23d97c
--- /dev/null
+++ b/src/tests/test_window.cc
@@ -0,0 +1,36 @@
+#include "audio/window.h"
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+
+// A simple floating point comparison with a tolerance
+bool is_close(float a, float b, float epsilon = 1e-6f) {
+ return fabsf(a - b) < epsilon;
+}
+
+int main() {
+ float window[WINDOW_SIZE];
+ hamming_window_512(window);
+
+ // Test 1: Window should start and end at the same small value
+ assert(is_close(window[0], 0.08f));
+ assert(is_close(window[WINDOW_SIZE - 1], 0.08f));
+ printf("Test 1 passed: Window start and end values are correct.\n");
+
+ // Test 2: Window should be symmetric
+ for (int i = 0; i < WINDOW_SIZE / 2; ++i) {
+ assert(is_close(window[i], window[WINDOW_SIZE - 1 - i]));
+ }
+ printf("Test 2 passed: Window is symmetric.\n");
+
+ // Test 3: The two middle points of the even-sized window should be equal and
+ // the peak.
+ assert(is_close(window[WINDOW_SIZE / 2 - 1], window[WINDOW_SIZE / 2]));
+ assert(window[WINDOW_SIZE / 2] >
+ window[WINDOW_SIZE / 2 - 2]); // Should be greater than neighbors
+ printf("Test 3 passed: Window peak is correct for even size.\n");
+
+ printf("All tests passed for Hamming window!\n");
+
+ return 0;
+}