mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3281 Add weighted geometric mean calculator
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiaWeightedGeometricMeanCalculator.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RiaWeightedGeometricMeanCalculator, BasicUsage)
|
||||
{
|
||||
{
|
||||
RiaWeightedGeometricMeanCalculator calc;
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, calc.aggregatedWeight());
|
||||
EXPECT_DOUBLE_EQ(0.0, calc.weightedMean());
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
RiaWeightedGeometricMeanCalculator calc;
|
||||
|
||||
std::vector<double> values {30.0, 60.0};
|
||||
std::vector<double> weights {1.5, 3.5};
|
||||
|
||||
for (size_t i = 0; i< values.size(); i++)
|
||||
{
|
||||
calc.addValueAndWeight(values[i], weights[i]);
|
||||
}
|
||||
|
||||
double expectedValue = std::pow(
|
||||
std::pow(30.0, 1.5) * std::pow(60.0, 3.5),
|
||||
1 / (1.5 + 3.5)
|
||||
);
|
||||
|
||||
EXPECT_DOUBLE_EQ(5.0, calc.aggregatedWeight());
|
||||
EXPECT_DOUBLE_EQ(expectedValue, calc.weightedMean());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user