aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-04-12 11:54:22 +0000
committerArne Juul <arnej@verizonmedia.com>2021-04-12 11:54:22 +0000
commit0e48c75de4e9e4ae343cad61bb4b267474a0c4c1 (patch)
treede7ebb0a760fd5ebfc945d9ccfc076685633c8b4 /searchlib
parent849a42d9d0a3bc0105f940b98c46d881f9862cc4 (diff)
test a bit more
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp28
1 files changed, 27 insertions, 1 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 6f8c9b4c885..701f4c91ff2 100644
--- a/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp
+++ b/searchlib/src/tests/tensor/distance_functions/distance_functions_test.cpp
@@ -14,7 +14,8 @@ using vespalib::eval::Int8Float;
using vespalib::eval::TypedCells;
using search::attribute::DistanceMetric;
-TypedCells t(const std::vector<double> &v) { return TypedCells(v); }
+template <typename T>
+TypedCells t(const std::vector<T> &v) { return TypedCells(v); }
void verify_geo_miles(const DistanceFunction *dist_fun,
const std::vector<double> &p1,
@@ -59,6 +60,31 @@ TEST(DistanceFunctionsTest, euclidean_gives_expected_score)
EXPECT_EQ(threshold, 0.25);
}
+TEST(DistanceFunctionsTest, euclidean_int8_smoketest)
+{
+ auto ct = vespalib::eval::CellType::INT8;
+
+ auto euclid = make_distance_function(DistanceMetric::Euclidean, ct);
+
+ std::vector<double> p00{0.0, 0.0, 0.0};
+ std::vector<Int8Float> p0{0.0, 0.0, 0.0};
+ std::vector<Int8Float> p1{1.0, 0.0, 0.0};
+ std::vector<Int8Float> p5{0.0,-1.0, 0.0};
+ std::vector<Int8Float> p7{-1.0, 2.0, -2.0};
+
+ EXPECT_DOUBLE_EQ(1.0, euclid->calc(t(p0), t(p1)));
+ EXPECT_DOUBLE_EQ(1.0, euclid->calc(t(p0), t(p5)));
+ EXPECT_DOUBLE_EQ(9.0, euclid->calc(t(p0), t(p7)));
+
+ EXPECT_DOUBLE_EQ(2.0, euclid->calc(t(p1), t(p5)));
+ EXPECT_DOUBLE_EQ(12.0, euclid->calc(t(p1), t(p7)));
+ EXPECT_DOUBLE_EQ(14.0, euclid->calc(t(p5), t(p7)));
+
+ EXPECT_DOUBLE_EQ(1.0, euclid->calc(t(p00), t(p1)));
+ EXPECT_DOUBLE_EQ(1.0, euclid->calc(t(p00), t(p5)));
+ EXPECT_DOUBLE_EQ(9.0, euclid->calc(t(p00), t(p7)));
+}
+
TEST(DistanceFunctionsTest, angular_gives_expected_score)
{
auto ct = vespalib::eval::CellType::DOUBLE;