summaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/features
diff options
context:
space:
mode:
authorGeir Storli <geirstorli@yahoo.no>2017-01-24 09:40:38 +0100
committerGitHub <noreply@github.com>2017-01-24 09:40:38 +0100
commit975cb8801a3a383efb449325b307b4d87b120bcb (patch)
tree1549547bdb3dc560a3fccbcb918ac8544fc0b9e2 /searchlib/src/tests/features
parent846a09f2a87bddd671c71e02e2584835562e0b8e (diff)
parent8932d24bdb0aaa097153814c2912807a4ac570b3 (diff)
Merge pull request #1570 from yahoo/lesters/add-random-normal-feature
Add randomNormal rank feature
Diffstat (limited to 'searchlib/src/tests/features')
-rw-r--r--searchlib/src/tests/features/prod_features.cpp48
-rw-r--r--searchlib/src/tests/features/prod_features.h1
2 files changed, 48 insertions, 1 deletions
diff --git a/searchlib/src/tests/features/prod_features.cpp b/searchlib/src/tests/features/prod_features.cpp
index 425279fbfe1..ad52c3ac861 100644
--- a/searchlib/src/tests/features/prod_features.cpp
+++ b/searchlib/src/tests/features/prod_features.cpp
@@ -32,6 +32,7 @@ LOG_SETUP("prod_features_test");
#include <vespa/searchlib/features/queryfeature.h>
#include <vespa/searchlib/features/querytermcountfeature.h>
#include <vespa/searchlib/features/randomfeature.h>
+#include <vespa/searchlib/features/random_normal_feature.h>
#include <vespa/searchlib/features/rankingexpressionfeature.h>
#include <vespa/searchlib/features/setup.h>
#include <vespa/searchlib/features/termfeature.h>
@@ -88,7 +89,7 @@ Test::Main()
TEST_DO(testAttribute()); TEST_FLUSH();
TEST_DO(testAttributeMatch()); TEST_FLUSH();
TEST_DO(testCloseness()); TEST_FLUSH();
- TEST_DO(testMatchCount()); TEST_FLUSH();
+ TEST_DO(testMatchCount()); TEST_FLUSH();
TEST_DO(testDistance()); TEST_FLUSH();
TEST_DO(testDistanceToPath()); TEST_FLUSH();
TEST_DO(testDotProduct()); TEST_FLUSH();
@@ -104,6 +105,7 @@ Test::Main()
TEST_DO(testQuery()); TEST_FLUSH();
TEST_DO(testQueryTermCount()); TEST_FLUSH();
TEST_DO(testRandom()); TEST_FLUSH();
+ TEST_DO(testRandomNormal()); TEST_FLUSH();
TEST_DO(testRankingExpression()); TEST_FLUSH();
TEST_DO(testTerm()); TEST_FLUSH();
TEST_DO(testTermDistance()); TEST_FLUSH();
@@ -1725,6 +1727,50 @@ Test::testRandom()
}
}
+void
+Test::testRandomNormal()
+{
+ { // Test blueprint.
+ RandomNormalBlueprint pt;
+
+ EXPECT_TRUE(assertCreateInstance(pt, "randomNormal"));
+
+ StringList params, in, out;
+ FT_SETUP_OK (pt, params, in, out.add("out"));
+ FT_SETUP_OK (pt, params.add("0.5").add("1.0"), in, out);
+ FT_SETUP_OK (pt, params.add("val1"), in, out);
+
+ FT_DUMP_EMPTY(_factory, "randomNormal");
+ }
+
+ { // Test executor (current time used as seed)
+ FtFeatureTest ft(_factory, "randomNormal");
+ ASSERT_TRUE(ft.setup());
+ RankResult rr;
+ rr.addScore("randomNormal", 1000.0);
+ for (uint32_t i = 0; i < 5; ++i) {
+ feature_t last = rr.getScore("randomNormal");
+ rr.clear();
+ ASSERT_TRUE(ft.executeOnly(rr, i + 1));
+ ASSERT_TRUE(last != rr.getScore("randomNormal"));
+ }
+ }
+
+ { // Test setting of mean and stddev values, and seed
+ FtFeatureTest ft1(_factory, "randomNormal(0.0,0.1)");
+ FtFeatureTest ft2(_factory, "randomNormal(1.0,0.2)");
+ ft1.getIndexEnv().getProperties().add("randomNormal(0.0,0.1).seed", "100");
+ ft2.getIndexEnv().getProperties().add("randomNormal(1.0,0.2).seed", "100");
+ ASSERT_TRUE(ft1.setup());
+ ASSERT_TRUE(ft2.setup());
+ RankResult rr;
+ for (uint32_t i = 0; i < 5; ++i) {
+ rr.clear();
+ ASSERT_TRUE(ft1.executeOnly(rr, i + 1));
+ ASSERT_TRUE(ft2.execute(((rr.getScore("randomNormal(0.0,0.1)")-0.0)/0.1) * 0.2 + 1.0, EPS, i + 1));
+ }
+ }
+}
void
Test::testRankingExpression()
diff --git a/searchlib/src/tests/features/prod_features.h b/searchlib/src/tests/features/prod_features.h
index 00c1fa46ec8..510f8cae230 100644
--- a/searchlib/src/tests/features/prod_features.h
+++ b/searchlib/src/tests/features/prod_features.h
@@ -32,6 +32,7 @@ public:
void testQuery();
void testQueryTermCount();
void testRandom();
+ void testRandomNormal();
void testRankingExpression();
void testTerm();
void testTermDistance();