[Aptitude-svn-commit] r3803 - in branches/aptitude-0.3/aptitude: .
src/generic tests
Daniel Burrows
dburrows at costa.debian.org
Thu Aug 11 02:48:16 UTC 2005
Author: dburrows
Date: Thu Aug 11 02:48:13 2005
New Revision: 3803
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/generic/util.h
branches/aptitude-0.3/aptitude/tests/test_misc.cc
Log:
Add a generic functor to compare pairs without respect to order.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Thu Aug 11 02:48:13 2005
@@ -1,5 +1,9 @@
2005-08-10 Daniel Burrows <dburrows at debian.org>
+ * src/generic/util.h, tests/test_misc.cc:
+
+ Add a generic routine to compare pairs without respect to order.
+
* src/generic/problemresolver/model.tex:
Put both algorithms on one page.
Modified: branches/aptitude-0.3/aptitude/src/generic/util.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/util.h (original)
+++ branches/aptitude-0.3/aptitude/src/generic/util.h Thu Aug 11 02:48:13 2005
@@ -21,6 +21,7 @@
#define UTIL_H
#include <string>
+#include <utility>
// Strip whitespace from the beginning and end of a string.
void stripws(std::string &s);
@@ -32,4 +33,20 @@
std::wstring swsprintf(const wchar_t *format, ...);
std::wstring vswsprintf(const wchar_t *format, va_list ap);
+/** Compare pairs, with (a,b) considered eqivalent to (b,a). */
+template<typename T>
+struct orderless_lt
+{
+ bool operator()(const typename std::pair<T, T> &p1,
+ const typename std::pair<T, T> &p2)
+ {
+ const std::pair<const T, const T> p1sort
+ = (p1.first < p1.second) ? std::pair<const T, const T>(p1.first, p1.second) : std::pair<const T, const T>(p1.second, p1.first);
+ const std::pair<const T, const T> p2sort
+ = (p2.first < p2.second) ? std::pair<const T, const T>(p2.first, p2.second) : std::pair<const T, const T>(p2.second, p2.first);
+
+ return p1sort < p2sort;
+ }
+};
+
#endif
Modified: branches/aptitude-0.3/aptitude/tests/test_misc.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/tests/test_misc.cc (original)
+++ branches/aptitude-0.3/aptitude/tests/test_misc.cc Thu Aug 11 02:48:13 2005
@@ -26,6 +26,7 @@
CPPUNIT_TEST_SUITE(MiscTest);
CPPUNIT_TEST(testStripWS);
+ CPPUNIT_TEST(testOrderlessLt);
CPPUNIT_TEST_SUITE_END();
private:
@@ -52,6 +53,47 @@
assertStripWS("a ", "a");
assertStripWS(" a ", "a");
}
+
+ void testOrderlessLt()
+ {
+ orderless_lt<int> cmp;
+
+ std::pair<int, int> a(1, 2);
+ std::pair<int, int> b(2, 1);
+ std::pair<int, int> c(4, 1);
+ std::pair<int, int> d(1, 4);
+ std::pair<int, int> e(4, 6);
+
+ CPPUNIT_ASSERT(!cmp(a, a));
+ CPPUNIT_ASSERT(!cmp(b, b));
+ CPPUNIT_ASSERT(!cmp(c, c));
+ CPPUNIT_ASSERT(!cmp(d, d));
+ CPPUNIT_ASSERT(!cmp(e, e));
+
+ CPPUNIT_ASSERT(!cmp(a, b));
+ CPPUNIT_ASSERT( cmp(b, c));
+ CPPUNIT_ASSERT(!cmp(c, d));
+ CPPUNIT_ASSERT( cmp(d, e));
+ CPPUNIT_ASSERT(!cmp(e, a));
+
+ CPPUNIT_ASSERT( cmp(a, c));
+ CPPUNIT_ASSERT( cmp(b, d));
+ CPPUNIT_ASSERT( cmp(c, e));
+ CPPUNIT_ASSERT(!cmp(d, a));
+ CPPUNIT_ASSERT(!cmp(e, b));
+
+ CPPUNIT_ASSERT( cmp(a, d));
+ CPPUNIT_ASSERT( cmp(b, e));
+ CPPUNIT_ASSERT(!cmp(c, a));
+ CPPUNIT_ASSERT(!cmp(d, b));
+ CPPUNIT_ASSERT(!cmp(e, c));
+
+ CPPUNIT_ASSERT( cmp(a, e));
+ CPPUNIT_ASSERT(!cmp(b, a));
+ CPPUNIT_ASSERT(!cmp(c, b));
+ CPPUNIT_ASSERT(!cmp(d, c));
+ CPPUNIT_ASSERT(!cmp(e, d));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(MiscTest);
More information about the Aptitude-svn-commit
mailing list