aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-18 23:17:25 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-18 23:17:25 +0000
commit5aafada448e858a6a4f821ea11f0151f118af606 (patch)
treef91c03ff0f1a04ac89ece2bb46238b2c15fab52b
parent4b0894ca1c253be381faa9d8e4727f405a271f81 (diff)
downloadpaludis-5aafada448e858a6a4f821ea11f0151f118af606.tar.gz
paludis-5aafada448e858a6a4f821ea11f0151f118af606.tar.xz
Make CompareByAll comparisons work correctly.
-rw-r--r--paludis/util/compare.hh8
-rw-r--r--paludis/util/smart_record_TEST.cc68
2 files changed, 72 insertions, 4 deletions
diff --git a/paludis/util/compare.hh b/paludis/util/compare.hh
index f7560f1..3784251 100644
--- a/paludis/util/compare.hh
+++ b/paludis/util/compare.hh
@@ -45,7 +45,7 @@ namespace paludis
{
if (t1 < t2)
return -1;
- else if (t2 > t1)
+ else if (t1 > t2)
return 1;
else
return 0;
@@ -64,7 +64,7 @@ namespace paludis
{
if (t1 < t2)
return -1;
- else if (t2 > t1)
+ else if (t1 > t2)
return 1;
else
return 0;
@@ -83,7 +83,7 @@ namespace paludis
{
if (t1 < t2)
return -1;
- else if (t2 > t1)
+ else if (t1 > t2)
return 1;
else
return 0;
@@ -102,7 +102,7 @@ namespace paludis
{
if (t1 < t2)
return -1;
- else if (t2 > t1)
+ else if (t1 > t2)
return 1;
else
return 0;
diff --git a/paludis/util/smart_record_TEST.cc b/paludis/util/smart_record_TEST.cc
index a551169..d9614df 100644
--- a/paludis/util/smart_record_TEST.cc
+++ b/paludis/util/smart_record_TEST.cc
@@ -20,6 +20,8 @@
#include <paludis/util/smart_record.hh>
#include <test/test_framework.hh>
#include <test/test_runner.hh>
+#include <vector>
+#include <iterator>
using namespace paludis;
using namespace test;
@@ -52,6 +54,22 @@ namespace
};
typedef MakeSmartRecord<PersonRecordTag>::Type Person;
+
+ enum PairKeys
+ {
+ first,
+ second
+ };
+
+ struct PairTag :
+ SmartRecordTag<comparison_mode::FullComparisonTag, comparison_method::SmartRecordCompareByAllTag>,
+ SmartRecordKeys<PairKeys, 2>,
+ SmartRecordKey<first, int>,
+ SmartRecordKey<second, int>
+ {
+ };
+
+ typedef MakeSmartRecord<PairTag>::Type Pair;
}
namespace test_cases
@@ -123,5 +141,55 @@ namespace test_cases
TEST_CHECK_EQUAL(p2.get<age>(), 42);
}
} test_list_constructed_record;
+
+ struct PairTest : TestCase
+ {
+ PairTest() : TestCase("pair") { }
+
+ void run()
+ {
+ std::vector<Pair> v;
+ v.push_back(Pair(0, 0));
+ v.push_back(Pair(0, 1));
+ v.push_back(Pair(0, 2));
+ v.push_back(Pair(1, 0));
+ v.push_back(Pair(1, 1));
+ v.push_back(Pair(1, 2));
+ v.push_back(Pair(2, 0));
+
+ std::vector<Pair>::iterator v1(v.begin()), v_end(v.end());
+ for ( ; v1 != v_end ; ++v1)
+ {
+ TestMessageSuffix s1("v1:" + stringify(v1->get<first>()) + "/"
+ + stringify(v1->get<second>()), true);
+ std::vector<Pair>::iterator v2(v.begin());
+ for ( ; v2 != v_end ; ++v2)
+ {
+ TestMessageSuffix s2("v2:" + stringify(v2->get<first>()) + "/"
+ + stringify(v2->get<second>()), true);
+
+ if (std::distance(v.begin(), v1) < std::distance(v.begin(), v2))
+ {
+ TEST_CHECK(*v1 < *v2);
+ TEST_CHECK(*v2 > *v1);
+ TEST_CHECK(*v1 != *v2);
+ TEST_CHECK(*v2 != *v1);
+ }
+ else if (std::distance(v.begin(), v1) > std::distance(v.begin(), v2))
+ {
+ TEST_CHECK(*v2 < *v1);
+ TEST_CHECK(*v1 > *v2);
+ TEST_CHECK(*v2 != *v1);
+ TEST_CHECK(*v1 != *v2);
+ }
+ else
+ {
+ TEST_CHECK(*v2 == *v1);
+ TEST_CHECK(*v1 == *v2);
+ }
+ }
+ }
+ }
+ } test_pair;
}