#12489 Improve robustness of mean calculators

Replace asserts with early-return guards so zero or negative weights
are silently skipped instead of crashing. Add unit tests for zero-weight
and zero-value edge cases in all three calculator classes.

Fixes #12489.
This commit is contained in:
Kristian Bendiksen committed 2026-03-31 08:46:20 +02:00
1 parent ba1055fbc4
commit 394bc6c3df
6 files changed
+122 -13

No files matched your search

@@ -18,8 +18,6 @@
#include "RiaWeightedGeometricMeanCalculator.h"
#include "cvfAssert.h"
#include <cmath>
//--------------------------------------------------------------------------------------------------
@@ -36,7 +34,7 @@ RiaWeightedGeometricMeanCalculator::RiaWeightedGeometricMeanCalculator()
//--------------------------------------------------------------------------------------------------
void RiaWeightedGeometricMeanCalculator::addValueAndWeight( double value, double weight )
{
CVF_ASSERT( weight >= 0.0 );
if ( weight <= 0.0 ) return;
// This can be a very big number, consider other algorithms if that becomes a problem
m_aggregatedWeightedValue += ( std::log( value ) * weight );