[Debtags-commits] [svn] r1845 - in tagcoll/2.0: . tagcoll tagcoll/tests

Enrico Zini enrico at costa.debian.org
Mon Aug 14 17:35:00 UTC 2006


Author: enrico
Date: Mon Aug 14 17:34:58 2006
New Revision: 1845

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/Patches-tut.cc
   tagcoll/2.0/tagcoll/Patches.h
   tagcoll/2.0/tagcoll/Patches.tcc
   tagcoll/2.0/tagcoll/tests/test-utils.h
Log:
 r3148 at viaza:  enrico | 2006-08-14 18:34:49 +0100
 Moved the Patch<> constructor that needs wibble::operators into the .tcc file
 Added tests for Patch<>
 Fixed ensure_not_contains, which still had the old gen_ name


Modified: tagcoll/2.0/tagcoll/Patches-tut.cc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches-tut.cc	(original)
+++ tagcoll/2.0/tagcoll/Patches-tut.cc	Mon Aug 14 17:34:58 2006
@@ -22,6 +22,22 @@
 #include <tagcoll/Patches.h>
 #include <tagcoll/coll/simple.h>
 
+namespace std {
+
+template<typename TAG, typename _Traits>
+basic_ostream<char, _Traits>& operator<<(basic_ostream<char, _Traits>& out, const std::set<TAG>& tags)
+{
+	for (typename std::set<TAG>::const_iterator i = tags.begin();
+			i != tags.end(); i++)
+		if (i == tags.begin())
+			out << *i;
+		else
+			out << ", " << *i;
+	return out;
+}
+
+}
+
 namespace wibble {
 namespace tut {
 using namespace std;
@@ -33,9 +49,45 @@
 };
 TESTGRP(tagcoll_patches);
 
+
+
 template<> template<>
 void to::test<1>()
 {
+	// Instantiate an empty patch
+	Patch<string, string> a("foo");
+	ensure_equals(a.getAdded(), std::set<string>());
+	ensure_equals(a.getRemoved(), std::set<string>());
+
+	// Instantiate a non-empty patch
+	std::set<string> added;
+	std::set<string> removed;
+	added.insert("a");
+	added.insert("b");
+	removed.insert("c");
+	removed.insert("d");
+	Patch<string, string> b("foo", added, removed);
+
+	// Check that getReverse() actually returns the reverse patch
+	Patch<string, string> rb = b.getReverse();
+	ensure_equals(b.getAdded(), rb.getRemoved());
+	ensure_equals(b.getRemoved(), rb.getAdded());
+
+	// Check removeRedundant()
+	std::set<string> ts;
+	ts.insert("a");
+	ts.insert("c");
+	b.removeRedundant(ts);
+	ensure_not_contains(b.getAdded(), std::string("a"));
+	ensure_contains(b.getAdded(), std::string("b"));
+	ensure_contains(b.getRemoved(), std::string("c"));
+	ensure_not_contains(b.getRemoved(), std::string("d"));
+
+}
+
+template<> template<>
+void to::test<2>()
+{
 #if 0
 	string input_coll(
 			"a: b, c\n"
@@ -48,7 +100,7 @@
 			"b: b, c\n"
 			"c: \n"
 			"d: c::D, c::d, e::F\n"
-			);
+			`);
 	coll::Simple<string, string> result;
 #endif
 	PatchList<string, string> patches;

Modified: tagcoll/2.0/tagcoll/Patches.h
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.h	(original)
+++ tagcoll/2.0/tagcoll/Patches.h	Mon Aug 14 17:34:58 2006
@@ -46,8 +46,7 @@
 public:
 	Patch(const Patch<ITEM, TAG>& p) : item(p.item), added(p.added), removed(p.removed) {}
 	Patch(const ITEM& item) : item(item) {}
-	Patch(const ITEM& item, const std::set<TAG>& added, const std::set<TAG>& removed)
-		: item(item), added(added-removed), removed(removed-added) {}
+	Patch(const ITEM& item, const std::set<TAG>& added, const std::set<TAG>& removed);
 	~Patch() {}
 
 	void add(const TAG& tag)

Modified: tagcoll/2.0/tagcoll/Patches.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.tcc	(original)
+++ tagcoll/2.0/tagcoll/Patches.tcc	Mon Aug 14 17:34:58 2006
@@ -28,6 +28,12 @@
 
 namespace tagcoll {
 
+template <typename ITEM, typename TAG>
+Patch<ITEM, TAG>::Patch(const ITEM& item, const std::set<TAG>& added, const std::set<TAG>& removed)
+	: item(item), added(added-removed), removed(removed-added)
+{
+}
+
 template <class ITEM, class TAG>
 void PatchList<ITEM, TAG>::addPatch(const Patch<ITEM, TAG>& patch)
 {

Modified: tagcoll/2.0/tagcoll/tests/test-utils.h
==============================================================================
--- tagcoll/2.0/tagcoll/tests/test-utils.h	(original)
+++ tagcoll/2.0/tagcoll/tests/test-utils.h	Mon Aug 14 17:34:58 2006
@@ -58,7 +58,7 @@
 	}
 }
 
-#define gen_ensure_not_contains(a, b) \
+#define ensure_not_contains(a, b) \
 	_ensure_not_contains(wibble::tests::Location(__FILE__, __LINE__, #a " contains " #b), a, b)
 #define inner_ensure_not_contains(a, b) \
 	_ensure_not_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #a " contains " #b), a, b)



More information about the Debtags-commits mailing list