@ -109,13 +109,61 @@ void test_feature_extractor_shape() {
std : : cout < < " [PASS] feature_extractor_shape ( " < < mel . rows ( ) < < " x " < < mel . cols ( ) < < " ) " < < std : : endl ;
}
void test_audio_buffer_overflow ( ) {
AudioBuffer buf ( 10 , 1 ) ;
std : : vector < float > data ( 25 , 1.0f ) ;
buf . Push ( data ) ;
assert ( buf . Size ( ) = = 10 ) ; // should cap at capacity
auto popped = buf . Pop ( 5 ) ;
assert ( popped . size ( ) = = 5 ) ;
assert ( buf . Size ( ) = = 5 ) ;
std : : cout < < " [PASS] audio_buffer_overflow " < < std : : endl ;
}
void test_distance_estimator_multi_class ( ) {
DistanceConfig config ;
config . ref_spl_gunshot = 150.0f ;
config . ref_spl_artillery = 180.0f ;
config . ref_spl_explosion = 170.0f ;
config . attenuation_alpha = 0.6f ;
DistanceEstimator est ( config ) ;
float d1 = est . Estimate ( 120.0f , " gunshot " ) ;
float d2 = est . Estimate ( 120.0f , " artillery " ) ;
float d3 = est . Estimate ( 120.0f , " explosion " ) ;
assert ( d2 > d1 ) ; // artillery has higher ref SPL -> farther estimated distance at same SPL
assert ( d3 > d1 ) ;
std : : cout < < " [PASS] distance_estimator_multi_class " < < std : : endl ;
}
void test_threat_tracker_filtering ( ) {
ThreatTracker tracker ( 0.3f , 15.0f , 5 ) ;
AcousticThreat t1 ;
t1 . sound_type = " gunshot " ;
t1 . confidence = 0.9f ;
t1 . azimuth = 45.0f ;
t1 . distance = 100.0f ;
// First update should publish
auto out1 = tracker . Update ( { t1 } ) ;
assert ( out1 . size ( ) = = 1 ) ;
// Immediate second update with same azimuth should be filtered (interval < 0.3s)
auto out2 = tracker . Update ( { t1 } ) ;
assert ( out2 . empty ( ) ) ;
std : : cout < < " [PASS] threat_tracker_filtering " < < std : : endl ;
}
int main ( ) {
std : : cout < < " Running core library tests... " < < std : : endl ;
test_audio_buffer ( ) ;
test_audio_buffer_overflow ( ) ;
test_preemphasis ( ) ;
test_gcc_phat_cross_array ( ) ;
test_distance_estimator ( ) ;
test_distance_estimator_multi_class ( ) ;
test_threat_tracker ( ) ;
test_threat_tracker_filtering ( ) ;
test_feature_extractor_shape ( ) ;
std : : cout < < " All tests passed! " < < std : : endl ;
return 0 ;