summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/aggregator
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2019-04-04 05:23:46 +0000
committerHenning Baldersheim <balder@oath.com>2019-04-04 05:24:50 +0000
commitcddc9b3316798a7b39fa83c0305273a613fea104 (patch)
treea81a1b4ba545352513b8dbdc23c01fbd9d6d46f5 /searchlib/src/tests/aggregator
parent8f1aed25a611903966c97e4c2b50f00b99070590 (diff)
Ensure that we do not end up with a nullptr when accidentally averaging over a string field.
Diffstat (limited to 'searchlib/src/tests/aggregator')
-rw-r--r--searchlib/src/tests/aggregator/perdocexpr.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/searchlib/src/tests/aggregator/perdocexpr.cpp b/searchlib/src/tests/aggregator/perdocexpr.cpp
index 66d2e48194d..c3667c36f8e 100644
--- a/searchlib/src/tests/aggregator/perdocexpr.cpp
+++ b/searchlib/src/tests/aggregator/perdocexpr.cpp
@@ -1325,6 +1325,38 @@ TEST("testAggregationResults") {
FloatResultNode(15.54));
}
+TEST("test Average over integer") {
+ AggregationResult::Configure conf;
+ AverageAggregationResult avg;
+ avg.setExpression(createScalarInt(I4)).select(conf, conf);
+ avg.aggregate(0, 0);
+ EXPECT_EQUAL(I4, avg.getAverage().getInteger());
+}
+
+TEST("test Average over float") {
+ AggregationResult::Configure conf;
+ AverageAggregationResult avg;
+ avg.setExpression(createScalarFloat(I4)).select(conf, conf);
+ avg.aggregate(0, 0);
+ EXPECT_EQUAL(I4, avg.getAverage().getInteger());
+}
+
+TEST("test Average over numeric string") {
+ AggregationResult::Configure conf;
+ AverageAggregationResult avg;
+ avg.setExpression(createScalarString("7.8")).select(conf, conf);
+ avg.aggregate(0, 0);
+ EXPECT_EQUAL(7.8, avg.getAverage().getFloat());
+}
+
+TEST("test Average over non-numeric string") {
+ AggregationResult::Configure conf;
+ AverageAggregationResult avg;
+ avg.setExpression(createScalarString("ABC")).select(conf, conf);
+ avg.aggregate(0, 0);
+ EXPECT_EQUAL(0, avg.getAverage().getInteger());
+}
+
TEST("testGrouping") {
AttributeGuard attr1 = createInt64Attribute();
ExpressionNode::UP result1(new CountAggregationResult());