summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-06-29 07:32:15 +0000
committerArne Juul <arnej@verizonmedia.com>2020-06-29 07:32:15 +0000
commit32c53b5b8b8314cd41768807dd3da6d6509edd73 (patch)
tree67aaef511f52a93f37e587f47f2f6e45c37db796 /searchlib
parent8372975229b7d67f25100301ac462a305578b5fa (diff)
split unit tests per distance function
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp b/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp
index 7d0f741e362..082d04f104b 100644
--- a/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp
+++ b/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp
@@ -31,13 +31,11 @@ void verify_geo_miles(const DistanceFunction *dist_fun,
}
-TEST(DistanceFunctionsTest, gives_expected_score)
+TEST(DistanceFunctionsTest, euclidean_gives_expected_score)
{
auto ct = vespalib::eval::ValueType::CellType::DOUBLE;
auto euclid = make_distance_function(DistanceMetric::Euclidean, ct);
- auto angular = make_distance_function(DistanceMetric::Angular, ct);
- auto innerproduct = make_distance_function(DistanceMetric::InnerProduct, ct);
std::vector<double> p0{0.0, 0.0, 0.0};
std::vector<double> p1{1.0, 0.0, 0.0};
@@ -52,6 +50,21 @@ TEST(DistanceFunctionsTest, gives_expected_score)
double d12 = euclid->calc(t(p1), t(p2));
EXPECT_EQ(d12, 2.0);
EXPECT_DOUBLE_EQ(euclid->to_rawscore(d12), 1.0/(1.0 + sqrt(2.0)));
+}
+
+TEST(DistanceFunctionsTest, angular_gives_expected_score)
+{
+ auto ct = vespalib::eval::ValueType::CellType::DOUBLE;
+
+ auto angular = make_distance_function(DistanceMetric::Angular, ct);
+
+ std::vector<double> p0{0.0, 0.0, 0.0};
+ std::vector<double> p1{1.0, 0.0, 0.0};
+ std::vector<double> p2{0.0, 1.0, 0.0};
+ std::vector<double> p3{0.0, 0.0, 1.0};
+ std::vector<double> p4{0.5, 0.5, 0.707107};
+ std::vector<double> p5{0.0,-1.0, 0.0};
+ std::vector<double> p6{1.0, 2.0, 2.0};
constexpr double pi = 3.14159265358979323846;
double a12 = angular->calc(t(p1), t(p2));
@@ -92,6 +105,21 @@ TEST(DistanceFunctionsTest, gives_expected_score)
EXPECT_FLOAT_EQ(a16, 1.0 - (1.0/3.0));
EXPECT_FLOAT_EQ(a26, 1.0 - (2.0/3.0));
EXPECT_FLOAT_EQ(a36, 1.0 - (2.0/3.0));
+}
+
+TEST(DistanceFunctionsTest, innerproduct_gives_expected_score)
+{
+ auto ct = vespalib::eval::ValueType::CellType::DOUBLE;
+
+ auto innerproduct = make_distance_function(DistanceMetric::InnerProduct, ct);
+
+ std::vector<double> p0{0.0, 0.0, 0.0};
+ std::vector<double> p1{1.0, 0.0, 0.0};
+ std::vector<double> p2{0.0, 1.0, 0.0};
+ std::vector<double> p3{0.0, 0.0, 1.0};
+ std::vector<double> p4{0.5, 0.5, 0.707107};
+ std::vector<double> p5{0.0,-1.0, 0.0};
+ std::vector<double> p6{1.0, 2.0, 2.0};
double i12 = innerproduct->calc(t(p1), t(p2));
double i13 = innerproduct->calc(t(p1), t(p3));
@@ -112,7 +140,6 @@ TEST(DistanceFunctionsTest, gives_expected_score)
double i44 = innerproduct->calc(t(p4), t(p4));
EXPECT_GE(i44, 0.0);
EXPECT_LT(i44, 0.000001);
-
}
TEST(GeoDegreesTest, gives_expected_score)