summaryrefslogtreecommitdiff
path: root/src/tests/test_spectral_brush.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_spectral_brush.cc')
-rw-r--r--src/tests/test_spectral_brush.cc53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/tests/test_spectral_brush.cc b/src/tests/test_spectral_brush.cc
index 1431ba7..ae1862a 100644
--- a/src/tests/test_spectral_brush.cc
+++ b/src/tests/test_spectral_brush.cc
@@ -28,11 +28,11 @@ void test_bezier_linear_2points() {
// Midpoint: linear interpolation
const float mid = evaluate_bezier_linear(frames, values, 2, 50.0f);
- assert(float_eq(mid, 100.0f)); // (50 + 150) / 2
+ assert(float_eq(mid, 100.0f)); // (50 + 150) / 2
// Quarter point
const float quarter = evaluate_bezier_linear(frames, values, 2, 25.0f);
- assert(float_eq(quarter, 75.0f)); // 50 + (150 - 50) * 0.25
+ assert(float_eq(quarter, 75.0f)); // 50 + (150 - 50) * 0.25
printf("[PASS] test_bezier_linear_2points\n");
}
@@ -78,8 +78,10 @@ void test_bezier_edge_cases() {
// Out of range: clamp to endpoints
const float frames2[] = {10.0f, 90.0f};
const float values2[] = {100.0f, 200.0f};
- assert(float_eq(evaluate_bezier_linear(frames2, values2, 2, 0.0f), 100.0f)); // Before start
- assert(float_eq(evaluate_bezier_linear(frames2, values2, 2, 100.0f), 200.0f)); // After end
+ assert(float_eq(evaluate_bezier_linear(frames2, values2, 2, 0.0f),
+ 100.0f)); // Before start
+ assert(float_eq(evaluate_bezier_linear(frames2, values2, 2, 100.0f),
+ 200.0f)); // After end
printf("[PASS] test_bezier_edge_cases\n");
}
@@ -98,7 +100,7 @@ void test_profile_gaussian() {
// Far from center: should approach 0
const float far = evaluate_profile(PROFILE_GAUSSIAN, 100.0f, 30.0f, 0.0f);
- assert(far < 0.01f); // Very small
+ assert(far < 0.01f); // Very small
printf("[PASS] test_profile_gaussian\n");
}
@@ -110,12 +112,14 @@ void test_profile_decaying_sinusoid() {
// At center (distance = 0)
// exp(-0 * 0.15) * cos(0 * 0.8) = 1.0 * 1.0 = 1.0
- assert(float_eq(evaluate_profile(PROFILE_DECAYING_SINUSOID, 0.0f, decay, omega), 1.0f));
+ assert(float_eq(
+ evaluate_profile(PROFILE_DECAYING_SINUSOID, 0.0f, decay, omega), 1.0f));
// At distance 10
const float dist = 10.0f;
const float expected = expf(-decay * dist) * cosf(omega * dist);
- const float actual = evaluate_profile(PROFILE_DECAYING_SINUSOID, dist, decay, omega);
+ const float actual =
+ evaluate_profile(PROFILE_DECAYING_SINUSOID, dist, decay, omega);
assert(float_eq(actual, expected));
printf("[PASS] test_profile_decaying_sinusoid\n");
@@ -127,12 +131,15 @@ void test_profile_noise() {
const uint32_t seed = 42;
// Same distance + seed should produce same value
- const float val1 = evaluate_profile(PROFILE_NOISE, 10.0f, amplitude, (float)seed);
- const float val2 = evaluate_profile(PROFILE_NOISE, 10.0f, amplitude, (float)seed);
+ const float val1 =
+ evaluate_profile(PROFILE_NOISE, 10.0f, amplitude, (float)seed);
+ const float val2 =
+ evaluate_profile(PROFILE_NOISE, 10.0f, amplitude, (float)seed);
assert(float_eq(val1, val2));
// Different distance should produce different value (with high probability)
- const float val3 = evaluate_profile(PROFILE_NOISE, 20.0f, amplitude, (float)seed);
+ const float val3 =
+ evaluate_profile(PROFILE_NOISE, 20.0f, amplitude, (float)seed);
assert(!float_eq(val1, val3));
// Should be in range [0, amplitude]
@@ -150,25 +157,25 @@ void test_draw_bezier_curve() {
// Simple curve: constant frequency, linearly decaying amplitude
const float frames[] = {0.0f, 100.0f};
- const float freqs[] = {440.0f, 440.0f}; // A4 note (constant pitch)
- const float amps[] = {1.0f, 0.0f}; // Fade out
+ const float freqs[] = {440.0f, 440.0f}; // A4 note (constant pitch)
+ const float amps[] = {1.0f, 0.0f}; // Fade out
- draw_bezier_curve(spectrogram, dct_size, num_frames, frames, freqs, amps, 2, PROFILE_GAUSSIAN,
- 30.0f);
+ draw_bezier_curve(spectrogram, dct_size, num_frames, frames, freqs, amps, 2,
+ PROFILE_GAUSSIAN, 30.0f);
// Verify: At frame 0, should have peak around 440 Hz bin
// bin = (440 / 16000) * 512 ≈ 14.08
const int expected_bin = 14;
const float val_at_peak = spectrogram[0 * dct_size + expected_bin];
- assert(val_at_peak > 0.5f); // Should be near 1.0 due to Gaussian
+ assert(val_at_peak > 0.5f); // Should be near 1.0 due to Gaussian
// Verify: At frame 99 (end), amplitude should be near 0
const float val_at_end = spectrogram[99 * dct_size + expected_bin];
- assert(val_at_end < 0.1f); // Near zero
+ assert(val_at_end < 0.1f); // Near zero
// Verify: At frame 50 (midpoint), amplitude should be ~0.5
const float val_at_mid = spectrogram[50 * dct_size + expected_bin];
- assert(val_at_mid > 0.3f && val_at_mid < 0.7f); // Around 0.5
+ assert(val_at_mid > 0.3f && val_at_mid < 0.7f); // Around 0.5
printf("[PASS] test_draw_bezier_curve\n");
}
@@ -184,20 +191,20 @@ void test_draw_bezier_curve_add() {
const float frames1[] = {0.0f, 100.0f};
const float freqs1[] = {440.0f, 440.0f};
const float amps1[] = {0.5f, 0.5f};
- draw_bezier_curve(spectrogram, dct_size, num_frames, frames1, freqs1, amps1, 2, PROFILE_GAUSSIAN,
- 30.0f);
+ draw_bezier_curve(spectrogram, dct_size, num_frames, frames1, freqs1, amps1,
+ 2, PROFILE_GAUSSIAN, 30.0f);
- const int bin = 14; // ~440 Hz
+ const int bin = 14; // ~440 Hz
const float val_before_add = spectrogram[0 * dct_size + bin];
// Add second curve (same frequency, same amplitude)
- draw_bezier_curve_add(spectrogram, dct_size, num_frames, frames1, freqs1, amps1, 2,
- PROFILE_GAUSSIAN, 30.0f);
+ draw_bezier_curve_add(spectrogram, dct_size, num_frames, frames1, freqs1,
+ amps1, 2, PROFILE_GAUSSIAN, 30.0f);
const float val_after_add = spectrogram[0 * dct_size + bin];
// Should be approximately doubled
- assert(val_after_add > val_before_add * 1.8f); // Allow small error
+ assert(val_after_add > val_before_add * 1.8f); // Allow small error
printf("[PASS] test_draw_bezier_curve_add\n");
}