[paludis-commits] r4099 - in trunk: . paludis
ferdy at svn.pioto.org
ferdy at svn.pioto.org
Sun Dec 23 19:56:50 UTC 2007
Author: ferdy
Date: 2007-12-23 19:56:27 +0000 (Sun, 23 Dec 2007)
New Revision: 4099
Added:
trunk/paludis/fuzzy_finder_TEST.cc
Modified:
trunk/ChangeLog
trunk/paludis/files.m4
trunk/paludis/fuzzy_finder.cc
Log:
Fix thinko in FuzzyCandidatesFinder and add test cases for it and for FuzzyRepositoriesFinder
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-12-23 11:12:47 UTC (rev 4098)
+++ trunk/ChangeLog 2007-12-23 19:56:27 UTC (rev 4099)
@@ -5,6 +5,11 @@
only listed in SVN log. For a summary of what has changed between releases,
see the NEWS file. This file is occasionally pruned to ChangeLog.old.bz2.
+2007-12-23 Fernando J. Pereda
+
+ * paludis/fuzzy_finder.cc, paludis/fuzzy_finder_TEST.cc: Fix a thinko and
+ add some test cases for FuzzyCandidatesFinder and FuzzyRepositoriesFinder.
+
2007-12-16 Bo Ørsted Andresen
* trunk/doc/overview/gettingstarted.html.part: Add repositories id to
Modified: trunk/paludis/files.m4
===================================================================
--- trunk/paludis/files.m4 2007-12-23 11:12:47 UTC (rev 4098)
+++ trunk/paludis/files.m4 2007-12-23 19:56:27 UTC (rev 4099)
@@ -25,7 +25,7 @@
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')
Modified: trunk/paludis/fuzzy_finder.cc
===================================================================
--- trunk/paludis/fuzzy_finder.cc 2007-12-23 11:12:47 UTC (rev 4098)
+++ trunk/paludis/fuzzy_finder.cc 2007-12-23 19:56:27 UTC (rev 4099)
@@ -87,8 +87,7 @@
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);
Added: trunk/paludis/fuzzy_finder_TEST.cc
===================================================================
--- trunk/paludis/fuzzy_finder_TEST.cc (rev 0)
+++ trunk/paludis/fuzzy_finder_TEST.cc 2007-12-23 19:56:27 UTC (rev 4099)
@@ -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;
+}
More information about the paludis-commits
mailing list