2018-08-15 01:38:54 -05:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2018-09-14 02:12:05 -05:00
|
|
|
#include "RiaWeightedMeanCalculator.h"
|
2018-08-15 01:38:54 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-08-15 01:38:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
TEST( RiaWeightedMeanCalculator, BasicUsage )
|
2018-08-15 01:38:54 -05:00
|
|
|
{
|
|
|
|
{
|
2018-09-14 02:12:05 -05:00
|
|
|
RiaWeightedMeanCalculator<double> calc;
|
2018-08-15 01:38:54 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
EXPECT_DOUBLE_EQ( 0.0, calc.aggregatedWeight() );
|
|
|
|
EXPECT_FALSE( calc.validAggregatedWeight() );
|
2018-08-15 01:38:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-09-14 02:12:05 -05:00
|
|
|
RiaWeightedMeanCalculator<double> calc;
|
2018-08-15 01:38:54 -05:00
|
|
|
|
2020-11-06 03:46:38 -06:00
|
|
|
std::vector<double> values{ 3.0, 6.0 };
|
|
|
|
std::vector<double> weights{ 1.0, 2.0 };
|
2018-08-15 01:38:54 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < values.size(); i++ )
|
2018-08-15 01:38:54 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
calc.addValueAndWeight( values[i], weights[i] );
|
2018-08-15 01:38:54 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
EXPECT_TRUE( calc.validAggregatedWeight() );
|
|
|
|
EXPECT_DOUBLE_EQ( 3.0, calc.aggregatedWeight() );
|
|
|
|
EXPECT_DOUBLE_EQ( 5.0, calc.weightedMean() );
|
2018-08-15 01:38:54 -05:00
|
|
|
}
|
|
|
|
}
|