aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/tests/queryeval/getnodeweight/getnodeweight_test.cpp
blob: d9b7d5b31925bc08e385bf93fd65e89b5c6fadc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vespalib/testkit/testapp.h>

#include <vespa/searchlib/query/tree/simplequery.h>
#include <vespa/searchlib/queryeval/get_weight_from_node.h>
#include <vespa/log/log.h>
LOG_SETUP("getweight_test");

using namespace search::query;
using namespace search::queryeval;

namespace {
    int32_t
    getWeight(const Node &node) {
        return getWeightFromNode(node).percent();
    }
}

TEST("test variations of getWeight")
{
    EXPECT_EQUAL(0, getWeight(SimpleAnd()));
    EXPECT_EQUAL(0, getWeight(SimpleAndNot()));
    EXPECT_EQUAL(42, getWeight(SimpleEquiv(0, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleNumberTerm("foo", "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleLocationTerm(Location(), "bar", 1, Weight(42))));
    EXPECT_EQUAL(0, getWeight(SimpleNear(5)));
    EXPECT_EQUAL(0, getWeight(SimpleONear(5)));
    EXPECT_EQUAL(0, getWeight(SimpleOr()));
    EXPECT_EQUAL(42, getWeight(SimplePhrase("bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimplePrefixTerm("foo", "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleRangeTerm(Range(), "bar", 1, Weight(42))));
    EXPECT_EQUAL(0, getWeight(SimpleRank()));
    EXPECT_EQUAL(42, getWeight(SimpleStringTerm("foo", "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleSubstringTerm("foo", "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleSuffixTerm("foo", "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleWeightedSetTerm(0, "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleDotProduct(0, "bar", 1, Weight(42))));
    EXPECT_EQUAL(42, getWeight(SimpleWandTerm(0, "bar", 1, Weight(42), 57, 67, 77.7)));
}

TEST_MAIN() { TEST_RUN_ALL(); }