ResInsight/ApplicationLibCode/UnitTests/RiaWeightedMean-Test.cpp

32 lines
954 B
C++
Raw Normal View History

#include "gtest/gtest.h"
#include "RiaWeightedMeanCalculator.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RiaWeightedMeanCalculator, BasicUsage )
{
{
RiaWeightedMeanCalculator<double> calc;
EXPECT_DOUBLE_EQ( 0.0, calc.aggregatedWeight() );
EXPECT_FALSE( calc.validAggregatedWeight() );
}
{
RiaWeightedMeanCalculator<double> calc;
2020-11-06 03:46:38 -06:00
std::vector<double> values{ 3.0, 6.0 };
std::vector<double> weights{ 1.0, 2.0 };
for ( size_t i = 0; i < values.size(); i++ )
{
calc.addValueAndWeight( values[i], weights[i] );
}
EXPECT_TRUE( calc.validAggregatedWeight() );
EXPECT_DOUBLE_EQ( 3.0, calc.aggregatedWeight() );
EXPECT_DOUBLE_EQ( 5.0, calc.weightedMean() );
}
}