aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/fuzzy
diff options
context:
space:
mode:
authorAlexey Chernyshev <aleksei@spotify.com>2022-03-10 16:33:07 +0100
committerAlexey Chernyshev <aleksei@spotify.com>2022-03-23 16:20:59 +0100
commitd9805209e3b0e33be3c0cc454c4604043663c1c4 (patch)
tree7446c79f68acd8775233ace4d5a70058f90c8406 /vespalib/src/tests/fuzzy
parenta2b1e6654cabc90ddf7422e58adf641876e5201c (diff)
Introducing fuzzy search
Diffstat (limited to 'vespalib/src/tests/fuzzy')
-rw-r--r--vespalib/src/tests/fuzzy/.gitignore4
-rw-r--r--vespalib/src/tests/fuzzy/CMakeLists.txt8
-rw-r--r--vespalib/src/tests/fuzzy/fuzzy.cpp33
3 files changed, 45 insertions, 0 deletions
diff --git a/vespalib/src/tests/fuzzy/.gitignore b/vespalib/src/tests/fuzzy/.gitignore
new file mode 100644
index 00000000000..cd5ca9b3b88
--- /dev/null
+++ b/vespalib/src/tests/fuzzy/.gitignore
@@ -0,0 +1,4 @@
+.depend
+Makefile
+fuzzy_test
+vespalib_fuzzy_test_app
diff --git a/vespalib/src/tests/fuzzy/CMakeLists.txt b/vespalib/src/tests/fuzzy/CMakeLists.txt
new file mode 100644
index 00000000000..f58602296a5
--- /dev/null
+++ b/vespalib/src/tests/fuzzy/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_fuzzy_test_app TEST
+ SOURCES
+ fuzzy.cpp
+ DEPENDS
+ vespalib
+ )
+vespa_add_test(NAME vespalib_fuzzy_test_app COMMAND vespalib_fuzzy_test_app)
diff --git a/vespalib/src/tests/fuzzy/fuzzy.cpp b/vespalib/src/tests/fuzzy/fuzzy.cpp
new file mode 100644
index 00000000000..9ffb77b3742
--- /dev/null
+++ b/vespalib/src/tests/fuzzy/fuzzy.cpp
@@ -0,0 +1,33 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/fuzzy/fuzzy.h>
+
+using namespace vespalib;
+
+
+TEST("require that levenstein distance works") {
+ EXPECT_EQUAL(0u, Fuzzy::levenstein_distance("abc", "abc", 2).value());
+ EXPECT_EQUAL(0u, Fuzzy::levenstein_distance("abc", "ABC", 2).value());
+ EXPECT_EQUAL(1u, Fuzzy::levenstein_distance("abc", "abd", 2).value());
+ EXPECT_EQUAL(1u, Fuzzy::levenstein_distance("ABC", "abd", 2).value());
+ EXPECT_EQUAL(2u, Fuzzy::levenstein_distance("ABC", "add", 2).value());
+ EXPECT_FALSE(Fuzzy::levenstein_distance("ABC", "ddd", 2).has_value());
+}
+
+TEST("require that extracting of a prefix works") {
+ Fuzzy fuzzy(Fuzzy::folded_codepoints("prefix"), 2, 2);
+ EXPECT_EQUAL("pr", fuzzy.getPrefix());
+}
+
+TEST("require that empty prefix works") {
+ Fuzzy fuzzy(Fuzzy::folded_codepoints("prefix"), 0, 2);
+ EXPECT_EQUAL("", fuzzy.getPrefix());
+}
+
+TEST("require that longer prefix size works") {
+ Fuzzy fuzzy(Fuzzy::folded_codepoints("prefix"), 100, 2);
+ EXPECT_EQUAL("prefix", fuzzy.getPrefix());
+}
+
+
+TEST_MAIN() { TEST_RUN_ALL(); }