diff options
author | Haavard <havardpe@yahoo-inc.com> | 2017-02-23 17:41:37 +0000 |
---|---|---|
committer | Haavard <havardpe@yahoo-inc.com> | 2017-02-23 17:41:37 +0000 |
commit | 4648d58976d5cb8ae84c11beb10f564839751a0f (patch) | |
tree | 1bf301e53ff4e0361c9d5000969cd616fc111145 /searchlib/src/tests/fef | |
parent | 16a699970e229b03ee210899d473881871d85d19 (diff) |
added tests for auto-unboxing
Diffstat (limited to 'searchlib/src/tests/fef')
-rw-r--r-- | searchlib/src/tests/fef/rank_program/rank_program_test.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/searchlib/src/tests/fef/rank_program/rank_program_test.cpp b/searchlib/src/tests/fef/rank_program/rank_program_test.cpp index 91c266f2745..c7ea20dd72f 100644 --- a/searchlib/src/tests/fef/rank_program/rank_program_test.cpp +++ b/searchlib/src/tests/fef/rank_program/rank_program_test.cpp @@ -13,6 +13,9 @@ using namespace search::fef; using namespace search::fef::test; using namespace search::features; +using vespalib::eval::DoubleValue; +using vespalib::eval::ValueType; + uint32_t default_docid = 1; void maybe_insert(const LazyValue &value, std::vector<LazyValue> &seen) { @@ -96,6 +99,31 @@ struct DocidBlueprint : Blueprint { } }; +struct BoxingExecutor : FeatureExecutor { + DoubleValue value; + BoxingExecutor() : value(0.0) {} + bool isPure() override { return true; } + void execute(uint32_t) override { + value = DoubleValue(inputs().get_number(0)); + outputs().set_object(0, value); + } +}; + +struct BoxingBlueprint : Blueprint { + BoxingBlueprint() : Blueprint("box") {} + void visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const override {} + Blueprint::UP createInstance() const override { return Blueprint::UP(new BoxingBlueprint()); } + bool setup(const IIndexEnvironment &, const std::vector<vespalib::string> ¶ms) override { + ASSERT_EQUAL(1u, params.size()); + defineInput(params[0]); + describeOutput("out", "boxed value", FeatureType::object(ValueType::double_type())); + return true; + } + FeatureExecutor &createExecutor(const IQueryEnvironment &, vespalib::Stash &stash) const override { + return stash.create<BoxingExecutor>(); + } +}; + struct MySetup { BlueprintFactory factory; IndexEnvironment indexEnv; @@ -109,6 +137,7 @@ struct MySetup { factory.addPrototype(Blueprint::SP(new ImpureValueBlueprint())); factory.addPrototype(Blueprint::SP(new SumBlueprint())); factory.addPrototype(Blueprint::SP(new DocidBlueprint())); + factory.addPrototype(Blueprint::SP(new BoxingBlueprint())); } MySetup &add(const vespalib::string &feature) { resolver->addSeed(feature); @@ -221,4 +250,20 @@ TEST_F("require that the rank program can calculate scores for multiple document EXPECT_EQUAL(f1.get(1), 11.0); } +TEST_F("require that auto-unboxing of const object values work", MySetup()) { + f1.add("box(value(10))").compile(); + EXPECT_EQUAL(10.0, f1.get()); + EXPECT_EQUAL(2u, f1.program.num_executors()); + EXPECT_EQUAL(3u, count_features(f1.program)); + EXPECT_EQUAL(3u, count_const_features(f1.program)); +} + +TEST_F("require that auto-unboxing of non-const object values work", MySetup()) { + f1.add("box(ivalue(10))").compile(); + EXPECT_EQUAL(10.0, f1.get()); + EXPECT_EQUAL(2u, f1.program.num_executors()); + EXPECT_EQUAL(3u, count_features(f1.program)); + EXPECT_EQUAL(0u, count_const_features(f1.program)); +} + TEST_MAIN() { TEST_RUN_ALL(); } |