aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-12-23 19:56:27 +0000
committerAvatar Fernando J. Pereda <ferdy@ferdyx.org> 2007-12-23 19:56:27 +0000
commitc513347286faf9d87880ee3923cef694684602a8 (patch)
tree46b7a38eb0914f4e4e22236d10728d301a7ccad6
parentb577ec33d28c3ef8a395974eaffc739068673b30 (diff)
downloadpaludis-c513347286faf9d87880ee3923cef694684602a8.tar.gz
paludis-c513347286faf9d87880ee3923cef694684602a8.tar.xz
Fix thinko in FuzzyCandidatesFinder and add test cases for it and for FuzzyRepositoriesFinder
-rw-r--r--paludis/files.m42
-rw-r--r--paludis/fuzzy_finder.cc3
-rw-r--r--paludis/fuzzy_finder_TEST.cc109
3 files changed, 111 insertions, 3 deletions
diff --git a/paludis/files.m4 b/paludis/files.m4
index 9f878ec..eb1b36a 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -25,7 +25,7 @@ add(`environment', `hh', `fwd', `cc')
add(`environment_implementation', `hh', `cc')
add(`environment_maker', `hh', `cc')
add(`find_unused_packages_task', `hh', `cc')
-add(`fuzzy_finder', `hh', `cc')
+add(`fuzzy_finder', `hh', `cc', `test')
add(`formatter', `hh', `fwd', `cc')
add(`handled_information', `hh', `fwd', `cc')
add(`hashed_containers', `hh', `cc', `test')
diff --git a/paludis/fuzzy_finder.cc b/paludis/fuzzy_finder.cc
index 442ed79..dababdd 100644
--- a/paludis/fuzzy_finder.cc
+++ b/paludis/fuzzy_finder.cc
@@ -87,8 +87,7 @@ FuzzyCandidatesFinder::FuzzyCandidatesFinder(const Environment & e, const std::s
real_generator = real_generator & query::Repository(*pds.repository_ptr());
}
- std::string package_0_cost(tolower_0_cost(package));
- DamerauLevenshtein distance_calculator(package);
+ DamerauLevenshtein distance_calculator(tolower_0_cost(package));
unsigned threshold(package.length() <= 4 ? 1 : 2);
diff --git a/paludis/fuzzy_finder_TEST.cc b/paludis/fuzzy_finder_TEST.cc
new file mode 100644
index 0000000..fbf8db2
--- /dev/null
+++ b/paludis/fuzzy_finder_TEST.cc
@@ -0,0 +1,109 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Fernando J. Pereda
+ *
+ * This file is part of the Paludis package manager. Paludis is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <paludis/fuzzy_finder.hh>
+#include <paludis/environments/test/test_environment.hh>
+#include <paludis/repositories/fake/fake_repository.hh>
+#include <paludis/repositories/fake/fake_installed_repository.hh>
+#include <paludis/repositories/fake/fake_package_id.hh>
+#include <paludis/util/wrapped_forward_iterator.hh>
+#include <paludis/package_database.hh>
+#include <test/test_framework.hh>
+#include <test/test_runner.hh>
+
+using namespace paludis;
+using namespace test;
+
+namespace test_cases
+{
+ struct FuzzyCandidatesFinderTest : TestCase
+ {
+ FuzzyCandidatesFinderTest() : TestCase("fuzzy candidates finder") { }
+
+ void run()
+ {
+ TestEnvironment e;
+
+ tr1::shared_ptr<FakeRepository> r1(new FakeRepository(&e, RepositoryName("r1")));
+ r1->add_version("some-cat", "foo", "1");
+ r1->add_version("other-cat", "foo", "1");
+ r1->add_version("some-cat", "bar", "1");
+ r1->add_version("some-cat", "one-two-three", "1");
+ e.package_database()->add_repository(1, r1);
+
+ tr1::shared_ptr<FakeRepository> r2(new FakeRepository(&e, RepositoryName("r2")));
+ e.package_database()->add_repository(2, r2);
+
+ FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), query::All());
+ TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
+
+ FuzzyCandidatesFinder f2(e, std::string("fio"), query::All());
+ TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 2);
+
+ FuzzyCandidatesFinder f3(e, std::string("bra"), query::All());
+ TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
+
+ FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), query::All());
+ TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 0);
+
+ FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), query::All());
+ TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
+
+ FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), query::All());
+ TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
+
+ }
+ } fuzzy_candidates_finder_test;
+
+ struct FuzzyRepositoriesFinderTest : TestCase
+ {
+ FuzzyRepositoriesFinderTest() : TestCase("fuzzy repositories finder") { }
+
+ void run()
+ {
+ TestEnvironment e;
+ PackageDatabase & p(*e.package_database());
+
+ p.add_repository(1, tr1::shared_ptr<FakeRepository>(new FakeRepository(&e, RepositoryName("my-main-repository"))));
+ p.add_repository(1, tr1::shared_ptr<FakeRepository>(new FakeRepository(&e, RepositoryName("x-new-repository"))));
+ p.add_repository(1, tr1::shared_ptr<FakeRepository>(new FakeRepository(&e, RepositoryName("bar-overlay"))));
+ p.add_repository(1, tr1::shared_ptr<FakeRepository>(new FakeRepository(&e, RepositoryName("baz-overlay"))));
+ p.add_repository(1, tr1::shared_ptr<FakeRepository>(new FakeRepository(&e, RepositoryName("sunrise"))));
+
+ FuzzyRepositoriesFinder f1(e, "my-main-respository");
+ TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
+
+ FuzzyRepositoriesFinder f2(e, "new-repository");
+ TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 1);
+ TEST_CHECK_EQUAL(stringify(*f2.begin()), "x-new-repository");
+
+ FuzzyRepositoriesFinder f3(e, "sunric3");
+ TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
+
+ FuzzyRepositoriesFinder f4(e, "bar-overlay");
+ TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 2);
+
+ FuzzyRepositoriesFinder f5(e, "foo");
+ TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
+
+ FuzzyRepositoriesFinder f6(e, "new-repositori");
+ TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
+ }
+ } fuzzy_repositories_finder_test;
+}