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

Enrico Zini enrico at costa.debian.org
Tue May 9 00:22:44 UTC 2006


Author: enrico
Date: Tue May  9 00:22:42 2006
New Revision: 1727

Modified:
   tagcoll/2.0/   (props changed)
   tagcoll/2.0/tagcoll/DerivedTags.cc
   tagcoll/2.0/tagcoll/InputMerger.cc
   tagcoll/2.0/tagcoll/InputMerger.h
   tagcoll/2.0/tagcoll/PatchCollection.cc
   tagcoll/2.0/tagcoll/PatchCollection.h
   tagcoll/2.0/tagcoll/Patches.tcc
   tagcoll/2.0/tagcoll/ReadonlyCollection.h
   tagcoll/2.0/tagcoll/TDBIndexer.cc
   tagcoll/2.0/tagcoll/TDBIndexer.h
   tagcoll/2.0/tagcoll/test-utils.cc
   tagcoll/2.0/tagcoll/test-utils.tcc
   tagcoll/2.0/tagcoll/tests/Makefile.am
   tagcoll/2.0/tagcoll/tests/test-utils.h
Log:
 r2614 at viaza:  enrico | 2006-05-07 20:18:03 -0500
 Refactored PatchCollection -- now it's also iterable!!
 Renamed overloaded collection methods to avoid messy conflicts with template names
 Tests on patchcollection fail now.


Modified: tagcoll/2.0/tagcoll/DerivedTags.cc
==============================================================================
--- tagcoll/2.0/tagcoll/DerivedTags.cc	(original)
+++ tagcoll/2.0/tagcoll/DerivedTags.cc	Tue May  9 00:22:42 2006
@@ -111,6 +111,7 @@
 }
 
 #include <tagcoll/TextFormat.tcc>
+#include <tagcoll/test-utils.tcc>
 
 #endif
 

Modified: tagcoll/2.0/tagcoll/InputMerger.cc
==============================================================================
--- tagcoll/2.0/tagcoll/InputMerger.cc	(original)
+++ tagcoll/2.0/tagcoll/InputMerger.cc	Tue May  9 00:22:42 2006
@@ -63,7 +63,7 @@
 }
 
 template<class ITEM, class TAG> template<typename TAGS>
-std::set<ITEM> InputMerger<ITEM, TAG>::getItems(const TAGS& tags) const
+std::set<ITEM> InputMerger<ITEM, TAG>::getCommonItems(const TAGS& tags) const
 {
 	std::set<ITEM> res;
 	for (typename map< ITEM, std::set<TAG> >::const_iterator i = coll.begin();
@@ -223,6 +223,9 @@
 }
 }
 
+#include <tagcoll/Patches.tcc>
+#include <tagcoll/test-utils.tcc>
+
 #endif
 
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/InputMerger.h
==============================================================================
--- tagcoll/2.0/tagcoll/InputMerger.h	(original)
+++ tagcoll/2.0/tagcoll/InputMerger.h	Tue May  9 00:22:42 2006
@@ -95,7 +95,7 @@
 	std::set<TAG> getTags(const ITEM& item) const;
 	std::set<ITEM> getItems(const TAG& tag) const;
 	template<typename TAGS>
-	std::set<ITEM> getItems(const TAGS& tag) const;
+	std::set<ITEM> getCommonItems(const TAGS& tag) const;
 
 	template<typename TAGS, typename OUT>
 	void outputHavingTags(const TAGS& tags, OUT& out) const;

Modified: tagcoll/2.0/tagcoll/PatchCollection.cc
==============================================================================
--- tagcoll/2.0/tagcoll/PatchCollection.cc	(original)
+++ tagcoll/2.0/tagcoll/PatchCollection.cc	Tue May  9 00:22:42 2006
@@ -30,15 +30,6 @@
 namespace tagcoll
 {
 
-#if 0
-template<class ITEM, class TAG>
-void PatchCollection<ITEM, TAG>::consumeItem(const ITEM& item, const std::set<TAG>& tags)
-{
-	if (!tags.empty())
-		changes.addPatch(Patch<ITEM, TAG>(item, tags, std::set<TAG>()));
-}
-#endif
-
 template<typename ROCOLL>
 typename coll_traits<ROCOLL>::itemset_type PatchCollection<ROCOLL>::getItems(const Tag& tag) const
 {
@@ -48,13 +39,13 @@
 	// Check items in coll first
 	for (typename ItemSet::const_iterator i = items.begin(); i != items.end(); ++i)
 		// If they are unmodified, then we can trust coll.getItems
-		if (changes.find(*i) == changes.end())
+		if (m_changes.find(*i) == m_changes.end())
 			res |= *i;
 
 	// Then check items in the patch
-	for (typename Patches::const_iterator i = changes.begin();
-			i != changes.end(); i++)
-		if (set_contains(changes.patch(i->first, coll.getTags(i->first)), tag))
+	for (typename Patches::const_iterator i = m_changes.begin();
+			i != m_changes.end(); i++)
+		if (set_contains(m_changes.patch(i->first, coll.getTags(i->first)), tag))
 			res |= i->first;
 
 	return res;
@@ -100,12 +91,12 @@
 	for (typename ItemSet::const_iterator i = items.begin();
 			i != items.end(); i++)
 		// If they are unmodified, then we can trust coll.getItems
-		if (changes.find(*i) == changes.end())
+		if (m_changes.find(*i) == m_changes.end())
 			return true;
 
 	// Then check items in the patch
-	for (typename Patches::const_iterator i = changes.begin();
-			i != changes.end(); i++)
+	for (typename Patches::const_iterator i = m_changes.begin();
+			i != m_changes.end(); i++)
 		if (set_contains(i->second.getAdded(), tag))
 			return true;
 
@@ -116,8 +107,8 @@
 typename coll_traits<ROCOLL>::itemset_type PatchCollection<ROCOLL>::getTaggedItems() const
 {
 	ItemSet res(coll.getTaggedItems());
-	for (typename Patches::const_iterator i = changes.begin();
-			i != changes.end(); i++)
+	for (typename Patches::const_iterator i = m_changes.begin();
+			i != m_changes.end(); i++)
 		res |= i->first;
 	return res;
 }
@@ -185,9 +176,9 @@
 	for (typename Patches::const_iterator i = change.begin();
 			i != change.end(); i++)
 	{
-		Patches newChange(i->second);
+		Patch newChange(i->second);
 		newChange.removeRedundant(getTags(i->first));
-		changes.addPatch(newChange);
+		m_changes.addPatch(newChange);
 	}
 }
 
@@ -196,8 +187,8 @@
 {
 	int card = coll.getCardinality(tag);
 
-	for (typename Patches::const_iterator i = changes.begin();
-			i != changes.end(); i++)
+	for (typename Patches::const_iterator i = m_changes.begin();
+			i != m_changes.end(); i++)
 	{
 		if (set_contains(i->second.getAdded(), tag))
 			card++;
@@ -232,7 +223,7 @@
 
 	PatchCollection< InputMerger<string, string> > coll(startcoll);
 
-	output_test_collection(coll);
+	output_test_collection(inserter(coll));
 	test_readonly_collection(coll);
 }
 
@@ -250,7 +241,7 @@
 }
 }
 
-#include <tagcoll/Patches.tcc>
+#include <tagcoll/test-utils.tcc>
 
 #endif
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/PatchCollection.h
==============================================================================
--- tagcoll/2.0/tagcoll/PatchCollection.h	(original)
+++ tagcoll/2.0/tagcoll/PatchCollection.h	Tue May  9 00:22:42 2006
@@ -28,20 +28,26 @@
 
 namespace tagcoll
 {
+template<typename T1, typename T2> class PatchList;
 
-	/**
-	 * TODO: iterator is implementable if we consider that both the underlying
-	 * collection and the PatchList iterate items in sorted order: the iterator
-	 * can keep two iterators inside and present items as merges of sorted
-	 * sequences
-	 */
+template<typename ROCOLL>
+class PatchCollection;
+
+template<typename ROCOLL>
+struct coll_traits< PatchCollection<ROCOLL> >
+{
+	typedef typename coll_traits<ROCOLL>::item_type item_type;
+	typedef typename coll_traits<ROCOLL>::tag_type tag_type;
+	typedef typename coll_traits<ROCOLL>::tagset_type tagset_type;
+	typedef typename coll_traits<ROCOLL>::itemset_type itemset_type;
+};
 
 /**
  * Wraps a collection by intercepting all changes to it and preserving them as
  * a PatchList.
  */
 template<typename ROCOLL>
-class PatchCollection
+class PatchCollection : public Collection< PatchCollection<ROCOLL> >
 {
 public:
 	typedef Patch<
@@ -68,8 +74,95 @@
 #endif
 
 public:
+	typedef std::pair<Item, TagSet> value_type;
+
+	class const_iterator
+	{
+		typename ROCOLL::const_iterator ci;
+		typename Patches::const_iterator pi;
+		mutable const typename PatchCollection<ROCOLL>::value_type* cached_val;
+
+	protected:
+		const_iterator(const typename ROCOLL::const_iterator& ci, const typename Patches::const_iterator& pi)
+			: ci(ci), pi(pi), cached_val(0) {}
+	
+	public:
+		~const_iterator()
+		{
+			if (cached_val)
+				delete cached_val;
+		}
+		const typename PatchCollection<ROCOLL>::value_type& operator*() const
+		{
+			if (ci->first < pi->first)
+				return *ci;
+			else if (ci->first > pi->first)
+				return make_pair(pi->first, pi->second.getAdded());
+			else
+				return make_pair(ci->first, pi->second.apply(ci->second));
+		}
+		const typename PatchCollection<ROCOLL>::value_type* operator->() const
+		{
+			if (ci->first < pi->first)
+				cached_val = new typename PatchCollection<ROCOLL>::value_type(*ci);
+			else if (ci->first > pi->first)
+				cached_val = new typename PatchCollection<ROCOLL>::value_type(
+						make_pair(pi->first, pi->second.getAdded()));
+			else
+				cached_val = new typename PatchCollection<ROCOLL>::value_type(
+						make_pair(ci->first, pi->second.apply(ci->second)));
+			return cached_val;
+		}
+		const_iterator& operator++()
+		{
+			if (ci->first < pi->first)
+				++ci;
+			else if (ci->first > pi->first)
+				++pi;
+			else
+			{
+				++ci;
+				++pi;
+			}
+			if (cached_val)
+			{
+				delete cached_val;
+				cached_val = 0;
+			}
+			return *this;
+		}
+		bool operator==(const const_iterator& iter) const
+		{
+			return ci == iter.ci && pi == iter.pi;
+		}
+		bool operator!=(const const_iterator& iter) const
+		{
+			return ci != iter.ci || pi != iter.pi;
+		}
+		
+		friend class PatchCollection<ROCOLL>;
+	};
+	const_iterator begin() const { return const_iterator(coll.begin(), m_changes.begin()); }
+	const_iterator end() const { return const_iterator(coll.end(), m_changes.end()); }
+
 	PatchCollection(const ROCOLL& coll) : coll(coll) {}
 
+	template<typename ITEMS, typename TAGS>
+	void insert(const ITEMS& items, const TAGS& tags)
+	{
+		if (tags.empty())
+			return;
+		for (typename ITEMS::const_iterator i = items.begin();
+				i != items.end(); ++i)
+			m_changes.addPatch(Patch(*i, tags, TagSet()));
+	}
+
+	template<typename ITEMS>
+	void insert(const ITEMS& items, const wibble::Empty<Tag>& tags)
+	{
+		// Nothing to do in this case
+	}
+
 	/**
 	 * Get the changes that have been applied to this collection
 	 */
@@ -94,10 +187,10 @@
 
 	TagSet getTags(const Item& item) const
 	{
-		return changes.patch(item, coll.getTags(item));
+		return m_changes.patch(item, coll.getTags(item));
 	}
 	template<typename ITEMS>
-	TagSet getTags(const Item& items) const
+	TagSet getMergedTags(const ITEMS& items) const
 	{
 		using namespace wibble::operators;
 		TagSet res;
@@ -108,7 +201,7 @@
 	}
 	ItemSet getItems(const typename coll_traits<ROCOLL>::tag_type& tag) const;
 	template<typename TAGS>
-	ItemSet getItems(const TAGS& tags) const
+	ItemSet getCommonItems(const TAGS& tags) const
 	{
 		using namespace wibble::operators;
 		ItemSet res;
@@ -126,7 +219,15 @@
 	void applyChange(const Patches& change);
 
 #if 0
-	virtual void output(Consumer<ITEM, TAG>& consumer) const;
+	template<typename OUT>
+	void output(OUT out) const
+	{
+		for (const_iterator i = begin(); i != end(); ++i)
+		{
+			*out = *i;
+			++out;
+		}
+	}
 #endif
 };
 

Modified: tagcoll/2.0/tagcoll/Patches.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/Patches.tcc	(original)
+++ tagcoll/2.0/tagcoll/Patches.tcc	Tue May  9 00:22:42 2006
@@ -18,6 +18,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
 
+#ifndef TAGCOLL_PATCHES_CPP
+#define TAGCOLL_PATCHES_CPP
+
 #include <tagcoll/Patches.h>
 
 using namespace std;
@@ -51,13 +54,13 @@
 void PatchList<ITEM, TAG>::addPatch(const COLL1& im1, const COLL2& im2)
 {
 	for (typename COLL1::const_iterator i1 = im1.begin();
-			i1 = im1.end(); ++i1)
+			i1 != im1.end(); ++i1)
 	{
-		std::set<TAG> ts2 = im2.getTags(i1.first);
-		std::set<TAG> added = ts2 - i1.second;
-		std::set<TAG> removed = i1.second - ts2;
+		std::set<TAG> ts2 = im2.getTags(i1->first);
+		std::set<TAG> added = ts2 - i1->second;
+		std::set<TAG> removed = i1->second - ts2;
 		if (!added.empty() || !removed.empty())
-			addPatch(Patch<ITEM, TAG>(i1.first, added, removed));
+			addPatch(Patch<ITEM, TAG>(i1->first, added, removed));
 	}
 }
 
@@ -107,4 +110,6 @@
 
 }
 
+#endif
+
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/ReadonlyCollection.h
==============================================================================
--- tagcoll/2.0/tagcoll/ReadonlyCollection.h	(original)
+++ tagcoll/2.0/tagcoll/ReadonlyCollection.h	Tue May  9 00:22:42 2006
@@ -111,7 +111,7 @@
 	 */
 	bool hasTag(const typename coll_traits<Self>::tag_type& tag) const
 	{
-		return !getItems(tag).empty();
+		return !static_cast<const Self*>(this)->getItems(tag).empty();
 	}
 
 	/**
@@ -129,13 +129,13 @@
 	 *   exist.
 	 */
 	template<typename ITEMS>
-	typename coll_traits<Self>::tagset_type getTags(const ITEMS& items) const
+	typename coll_traits<Self>::tagset_type getMergedTags(const ITEMS& items) const
 	{
 		using namespace wibble::operators;
 		typename coll_traits<Self>::tagset_type res;
 		for (typename ITEMS::const_iterator i = items.begin();
 				i != items.end(); i++)
-			res |= getTags(*i);
+			res |= static_cast<const Self*>(this)->getTags(*i);
 		return res;
 	}
 
@@ -152,17 +152,17 @@
 	 *   The items found, or an empty set if no items have that tag
 	 */
 	template<typename TAGS>
-	typename coll_traits<Self>::itemset_type getItems(const TAGS& tags) const 
+	typename coll_traits<Self>::itemset_type getCommonItems(const TAGS& tags) const 
 	{
 		using namespace wibble::operators;
 		if (tags.empty())
-			return Self::itemset_type();
+			return typename coll_traits<Self>::itemset_type();
 
 		typename TAGS::const_iterator i = tags.begin();
-		typename Self::itemset_type res = getItemsHavingTag(*i);
+		typename coll_traits<Self>::itemset_type res = static_cast<const Self*>(this)->getItems(*i);
 
 		for ( ; i != tags.end(); ++i)
-			res &= getItemsHavingTag(*i);
+			res &= static_cast<const Self*>(this)->getItems(*i);
 
 		return res;
 	}
@@ -202,7 +202,7 @@
 	typename coll_traits<Self>::tagset_type getCompanionTags(const TAGS& tags) const
 	{
 		using namespace wibble::operators;
-		return getTagsOfItems(getItemsHavingTags(tags)) - tags;
+		return getMergedTags(getCommonItems(tags)) - tags;
 	}
 
 	/**
@@ -265,10 +265,10 @@
 	template<typename OUT>
 	void output(OUT out) const
 	{
-		for (typename Self::const_iterator i = this->begin();
-				i != this->end(); ++i)
+		for (typename Self::const_iterator i = static_cast<const Self*>(this)->begin();
+				i != static_cast<const Self*>(this)->end(); ++i)
 		{
-			*out = *i;
+			*out = make_pair(wibble::singleton(i->first), i->second);
 			++out;
 		}
 	}

Modified: tagcoll/2.0/tagcoll/TDBIndexer.cc
==============================================================================
--- tagcoll/2.0/tagcoll/TDBIndexer.cc	(original)
+++ tagcoll/2.0/tagcoll/TDBIndexer.cc	Tue May  9 00:22:42 2006
@@ -156,7 +156,7 @@
 {
 	TDBIndexer<string, string> coll;
 
-	output_test_collection(coll);
+	output_test_collection(inserter(coll));
 	test_readonly_collection(coll);
 }
 
@@ -171,5 +171,8 @@
 }
 }
 
+#include <tagcoll/test-utils.tcc>
+#include <tagcoll/Patches.tcc>
+
 #endif
 // vim:set ts=4 sw=4:

Modified: tagcoll/2.0/tagcoll/TDBIndexer.h
==============================================================================
--- tagcoll/2.0/tagcoll/TDBIndexer.h	(original)
+++ tagcoll/2.0/tagcoll/TDBIndexer.h	Tue May  9 00:22:42 2006
@@ -76,6 +76,30 @@
 	iterator begin() { return items.begin(); }
 	iterator end() { return items.end(); }
 
+	template<typename ITEMS, typename TAGS>
+	void insert(const ITEMS& items, const TAGS& tags)
+	{
+		for (typename ITEMS::const_iterator i = items.begin();
+				i != items.end(); ++i)
+		{
+			typename std::map< ITEM, std::set<TAG> >::iterator iter = this->items.find(*i);
+			if (iter == this->items.end())
+				this->items.insert(std::make_pair(*i, std::set<TAG>() | tags));
+			else
+				iter->second |= tags;
+		}
+
+		for (typename TAGS::const_iterator i = tags.begin();
+				i != tags.end(); ++i)
+		{
+			typename std::map< TAG, std::set<ITEM> >::iterator iter = this->tags.find(*i);
+			if (iter == this->tags.end())
+				this->tags.insert(std::make_pair(*i, std::set<ITEM>() | items));
+			else
+				iter->second |= items;
+		}
+	}
+
 	std::set<TAG> getTags(const ITEM& item) const;
 	std::set<ITEM> getItems(const TAG& tag) const;
 

Modified: tagcoll/2.0/tagcoll/test-utils.cc
==============================================================================
--- tagcoll/2.0/tagcoll/test-utils.cc	(original)
+++ tagcoll/2.0/tagcoll/test-utils.cc	Tue May  9 00:22:42 2006
@@ -41,354 +41,10 @@
 	textformat::parse(input, consumer(cons));
 }
 
-void __tc_ensure_coll_equals(const Location& loc,
-		const tagcoll::ReadonlyCollection<string, string>& c1, const tagcoll::ReadonlyCollection<string, string>& c2)
-{
-	PatchList<string, string> p;
-	p.addPatch(c1, c2);
-	if (!p.empty())
-	{
-		string f = "collections differ.  Patch:\n";
-		for (PatchList<string, string>::const_iterator i = p.begin();
-				i != p.end(); i++)
-		{
-			f += i->first;
-			f += ": ";
-			bool first = true;
-			for (std::set<string>::const_iterator j = i->second.getAdded().begin();
-					j != i->second.getAdded().end(); j++)
-				if (first)
-				{
-					f += "+" + *j;
-					first = false;
-				} else {
-					f += ", +" + *j;
-				}
-			for (std::set<string>::const_iterator j = i->second.getRemoved().begin();
-					j != i->second.getRemoved().end(); j++)
-				if (first)
-				{
-					f += "-" + *j;
-					first = false;
-				} else {
-					f += ", -" + *j;
-				}
-			f += "\n";
-		}
-		
-		throw wibble::tut::failure(loc.msg(f));
-	}
-}
-
-void __test_readonly_collection(const Location& loc, ReadonlyCollection<string, string>& tc)
-{
-	std::set<string> s, s1;
-
-	// hasTag
-	inner_ensure(tc.hasTag("tomato"));
-	inner_ensure(tc.hasTag("mozzarella"));
-	inner_ensure(tc.hasTag("mushrooms"));
-	inner_ensure(tc.hasTag("garlic"));
-	inner_ensure(tc.hasTag("rosemerry"));
-	inner_ensure(!tc.hasTag("ketchup"));
-
-	// getTags(item)
-	s = tc.getTags("funghi");
-	inner_ensure_contains(s, string("tomato"));
-	inner_ensure_contains(s, string("mozzarella"));
-	inner_ensure_contains(s, string("mushrooms"));
-	inner_ensure_not_contains(s, string("garlic"));
-	inner_ensure_not_contains(s, string("rosemerry"));
-
-	s = tc.getTags("margherita");
-	inner_ensure_contains(s, string("tomato"));
-	inner_ensure_contains(s, string("mozzarella"));
-	inner_ensure_not_contains(s, string("mushrooms"));
-	inner_ensure_not_contains(s, string("garlic"));
-	inner_ensure_not_contains(s, string("rosemerry"));
-
-	s = tc.getTags("rosmarino");
-	inner_ensure_not_contains(s, string("tomato"));
-	inner_ensure_not_contains(s, string("mozzarella"));
-	inner_ensure_not_contains(s, string("mushrooms"));
-	inner_ensure_contains(s, string("garlic"));
-	inner_ensure_contains(s, string("rosemerry"));
-
-	s = tc.getTags("marinara");
-	inner_ensure_contains(s, string("tomato"));
-	inner_ensure_not_contains(s, string("mozzarella"));
-	inner_ensure_not_contains(s, string("mushrooms"));
-	inner_ensure_contains(s, string("garlic"));
-	inner_ensure_not_contains(s, string("rosemerry"));
-
-	s = tc.getTags("gnocco");
-	inner_ensure(s.empty());
-
-	// getTags(items)
-	s1.clear();
-	s1.insert("funghi"); s1.insert("margherita");
-	s = tc.getTags(s1);
-	inner_ensure_contains(s, string("tomato"));
-	inner_ensure_contains(s, string("mozzarella"));
-	inner_ensure_contains(s, string("mushrooms"));
-	inner_ensure_not_contains(s, string("garlic"));
-	inner_ensure_not_contains(s, string("rosemerry"));
-
-	s1.clear();
-	s1.insert("rosmarino"); s1.insert("margherita");
-	s = tc.getTags(s1);
-	inner_ensure_contains(s, string("tomato"));
-	inner_ensure_contains(s, string("mozzarella"));
-	inner_ensure_not_contains(s, string("mushrooms"));
-	inner_ensure_contains(s, string("garlic"));
-	inner_ensure_contains(s, string("rosemerry"));
-
-	s1.clear();
-	s1.insert("funghi"); s1.insert("margherita"); s1.insert("marinara");
-	s = tc.getTags(s1);
-	inner_ensure_contains(s, string("tomato"));
-	inner_ensure_contains(s, string("mozzarella"));
-	inner_ensure_contains(s, string("mushrooms"));
-	inner_ensure_contains(s, string("garlic"));
-	inner_ensure_not_contains(s, string("rosemerry"));
-
-	// getItems(tag)
-	s = tc.getItems("tomato");
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_contains(s, string("margherita"));
-	inner_ensure_contains(s, string("funghi"));
-	inner_ensure_not_contains(s, string("rosmarino"));
-	inner_ensure_contains(s, string("marinara"));
-
-	s = tc.getItems("mozzarella");
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_contains(s, string("margherita"));
-	inner_ensure_contains(s, string("funghi"));
-	inner_ensure_not_contains(s, string("rosmarino"));
-	inner_ensure_not_contains(s, string("marinara"));
-
-	s = tc.getItems("mushrooms");
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_not_contains(s, string("margherita"));
-	inner_ensure_contains(s, string("funghi"));
-	inner_ensure_not_contains(s, string("rosmarino"));
-	inner_ensure_not_contains(s, string("marinara"));
-
-	s = tc.getItems("garlic");
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_not_contains(s, string("margherita"));
-	inner_ensure_not_contains(s, string("funghi"));
-	inner_ensure_contains(s, string("rosmarino"));
-	inner_ensure_contains(s, string("marinara"));
-
-	s = tc.getItems("rosemerry");
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_not_contains(s, string("margherita"));
-	inner_ensure_not_contains(s, string("funghi"));
-	inner_ensure_contains(s, string("rosmarino"));
-	inner_ensure_not_contains(s, string("marinara"));
-
-	// getItems(tags)
-	s1.clear();
-	s1.insert("tomato"); s1.insert("mozzarella");
-	s = tc.getItems(s1);
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_contains(s, string("margherita"));
-	inner_ensure_contains(s, string("funghi"));
-	inner_ensure_not_contains(s, string("rosmarino"));
-	inner_ensure_not_contains(s, string("marinara"));
-
-	s1.clear();
-	s1.insert("garlic"); s1.insert("rosemerry");
-	s = tc.getItems(s1);
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_not_contains(s, string("margherita"));
-	inner_ensure_not_contains(s, string("funghi"));
-	inner_ensure_contains(s, string("rosmarino"));
-	inner_ensure_not_contains(s, string("marinara"));
-
-	s1.clear();
-	s1.insert("tomato"); s1.insert("rosemerry");
-	s = tc.getItems(s1);
-	inner_ensure_not_contains(s, string("gnocco"));
-	inner_ensure_not_contains(s, string("margherita"));
-	inner_ensure_not_contains(s, string("funghi"));
-	inner_ensure_not_contains(s, string("rosmarino"));
-	inner_ensure_not_contains(s, string("marinara"));
-
-	// TODO:    virtual std::set<ITEM> getTaggedItems() const = 0;
-	// TODO:    virtual std::set<TAG> getAllTags() const = 0;
-	// TODO:    virtual int getCardinality(const TAG& tag) const
-	// TODO:    virtual std::set<TAG> getCompanionTags(const std::set<TAG>& tags) const
-	// TODO:    virtual std::set<ITEM> getRelatedItems(const std::set<TAG>& tags, int maxdistance = 1) const
-
-	// void output(Consumer<ITEM, TAG>& consumer) const
-	InputMerger<string, string> coll1;
-	tc.output(coll1);
-	inner_ensure_coll_equals(tc, coll1);
-
-	// TODO:    virtual void outputHavingTags(const std::set<TAG>& tags, Consumer<ITEM, TAG>& consumer) const
-}
-
-void __test_collection(const Location& loc, Collection<string, string>& tc)
-{
-	// Test handling of untagged items (they are not stored)
-	tc.consume("untagged");
-	inner_ensure(tc.getTags("untagged").empty());
-	
-	// Test handling of tagged items
-	std::set<string> tagset;
-	tagset.insert("tag1"); tagset.insert("tag2");
-	tc.consume("tagged", tagset);
-	inner_ensure_contains(tc.getTaggedItems(), string("tagged"));
-	//inner_ensure(tc.hasTag("tag1"));
-	//inner_ensure(tc.hasTag("tag2"));
-	tagset = tc.getTags("tagged");
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	std::set<string> itemset = tc.getItems("tag1");
-	inner_ensure_contains(itemset, string("tagged"));
-	itemset = tc.getItems("tag2");
-	inner_ensure_contains(itemset, string("tagged"));
-	tagset = tc.getAllTags();
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	tagset.clear();
-	tagset.insert("tag1");
-	tagset = tc.getCompanionTags(tagset);
-	inner_ensure_not_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-
-	// Test handling of changes
-	PatchList<string, string> change;
-	Patch<string, string> p("tagged");
-	tagset.clear();
-	p.remove("tag1");
-	p.remove("tag2");
-	change.addPatch(p);
-
-	tc.applyChange(change);
-	
-	// "tagged" should now be untagged
-	inner_ensure(tc.getTags("tagged").empty());
-
-	tc.applyChange(change.getReverse());
-
-	// "tagged" should now be as before
-	//inner_ensure(tc.hasTag("tag1"));
-	//inner_ensure(tc.hasTag("tag2"));
-	tagset = tc.getTags("tagged");
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	itemset = tc.getItems("tag1");
-	inner_ensure_contains(itemset, string("tagged"));
-	itemset = tc.getItems("tag2");
-	inner_ensure_contains(itemset, string("tagged"));
-	tagset = tc.getAllTags();
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	tagset.clear();
-	tagset.insert("tag1");
-	tagset = tc.getCompanionTags(tagset);
-	inner_ensure_not_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-
-	// Try a patch that adds a tag
-	change = PatchList<string, string>();
-	p = Patch<string, string>("tagged");
-	p.add("tag3");
-	change.addPatch(p);
-	tc.applyChange(change);
-
-	//inner_ensure(tc.hasTag("tag1"));
-	//inner_ensure(tc.hasTag("tag2"));
-	//inner_ensure(tc.hasTag("tag3"));
-	tagset = tc.getTags("tagged");
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-	itemset = tc.getItems("tag1");
-	inner_ensure_contains(itemset, string("tagged"));
-	itemset = tc.getItems("tag2");
-	inner_ensure_contains(itemset, string("tagged"));
-	itemset = tc.getItems("tag3");
-	inner_ensure_contains(itemset, string("tagged"));
-	tagset = tc.getAllTags();
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-	tagset.clear();
-	tagset.insert("tag1");
-	tagset = tc.getCompanionTags(tagset);
-	inner_ensure_not_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-
-	// Try a patch that adds some items
-	change = PatchList<string, string>();
-	p = Patch<string, string>("tagged1");
-	p.add("tag1");
-	p.add("tag2");
-	p.add("tag4");
-	change.addPatch(p);
-	tc.applyChange(change);
-
-	tagset = tc.getTags("tagged1");
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_not_contains(tagset, string("tag3"));
-	inner_ensure_contains(tagset, string("tag4"));
-	itemset = tc.getItems("tag1");
-	inner_ensure_contains(itemset, string("tagged1"));
-	itemset = tc.getItems("tag2");
-	inner_ensure_contains(itemset, string("tagged1"));
-	itemset = tc.getItems("tag3");
-	inner_ensure_not_contains(itemset, string("tagged1"));
-	itemset = tc.getItems("tag4");
-	inner_ensure_not_contains(itemset, string("tagged"));
-	inner_ensure_contains(itemset, string("tagged1"));
-	tagset = tc.getAllTags();
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-	inner_ensure_contains(tagset, string("tag4"));
-	tagset.clear();
-	tagset.insert("tag1");
-	tagset = tc.getCompanionTags(tagset);
-	inner_ensure_not_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-	inner_ensure_contains(tagset, string("tag4"));
-
-	// And reverse it
-	tc.applyChange(change.getReverse());
-
-	itemset = tc.getItems("tag1");
-	inner_ensure_not_contains(itemset, string("tagged1"));
-	itemset = tc.getItems("tag2");
-	inner_ensure_not_contains(itemset, string("tagged1"));
-	itemset = tc.getItems("tag3");
-	inner_ensure_not_contains(itemset, string("tagged1"));
-	inner_ensure(tc.getItems("tag4") == std::set<string>());
-	tagset = tc.getAllTags();
-	inner_ensure_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-	inner_ensure_not_contains(tagset, string("tag4"));
-	tagset.clear();
-	tagset.insert("tag1");
-	tagset = tc.getCompanionTags(tagset);
-	inner_ensure_not_contains(tagset, string("tag1"));
-	inner_ensure_contains(tagset, string("tag2"));
-	inner_ensure_contains(tagset, string("tag3"));
-	inner_ensure_not_contains(tagset, string("tag4"));
-}
-
 }
 }
 
 #include <tagcoll/TextFormat.tcc>
-#include <tagcoll/Patches.tcc>
 
 #endif
 

Modified: tagcoll/2.0/tagcoll/test-utils.tcc
==============================================================================
--- tagcoll/2.0/tagcoll/test-utils.tcc	(original)
+++ tagcoll/2.0/tagcoll/test-utils.tcc	Tue May  9 00:22:42 2006
@@ -25,6 +25,7 @@
 
 #include <tests/test-utils.h>
 #include <tagcoll/Patches.h>
+#include <tagcoll/InputMerger.h>
 #include <wibble/operators.h>
 
 namespace tagcoll {
@@ -35,8 +36,19 @@
 using namespace wibble::operators;
 using namespace wibble::tests;
 	
+// Quick way of building a singleton string from a string literal
+static inline wibble::Singleton<string> tss(const std::string& str)
+{
+	return wibble::singleton(str);
+}
+
+static inline wibble::Empty<string> empty()
+{
+	return wibble::Empty<string>();
+}
+
 template<typename COLL1, typename COLL2>
-void __tc_ensure_coll_equals(const Location& loc, const COLL1& c1, const COLL2& c2);
+void __tc_ensure_coll_equals(const Location& loc, const COLL1& c1, const COLL2& c2)
 {
 	PatchList<string, string> p;
 	p.addPatch(c1, c2);
@@ -80,27 +92,27 @@
 	std::set<string> tagset;
 
 	tagset.clear();
-	*tc = make_pair(string("gnocco"), wibble::empty<std::string>());
+	*tc = make_pair(tss("gnocco"), wibble::Empty<std::string>());
 	++tc;
 
 	tagset.clear();
 	tagset.insert("tomato"); tagset.insert("mozzarella");
-	*tc = make_pair(string("margherita"), tagset);
+	*tc = make_pair(tss("margherita"), tagset);
 	++tc;
 
 	tagset.clear();
 	tagset.insert("tomato"); tagset.insert("mozzarella"); tagset.insert("mushrooms");
-	*tc = make_pair(string("funghi"), tagset);
+	*tc = make_pair(tss("funghi"), tagset);
 	++tc;
 
 	tagset.clear();
 	tagset.insert("garlic"); tagset.insert("rosemerry");
-	*tc = make_pair(string("rosmarino"), tagset);
+	*tc = make_pair(tss("rosmarino"), tagset);
 	++tc;
 
 	tagset.clear();
 	tagset.insert("garlic"); tagset.insert("tomato");
-	*tc = make_pair(string("marinara"), tagset);
+	*tc = make_pair(tss("marinara"), tagset);
 	++tc;
 }
 
@@ -152,7 +164,7 @@
 	// getTags(items)
 	s1.clear();
 	s1.insert("funghi"); s1.insert("margherita");
-	s = tc.getTags(s1);
+	s = tc.getMergedTags(s1);
 	inner_ensure_contains(s, string("tomato"));
 	inner_ensure_contains(s, string("mozzarella"));
 	inner_ensure_contains(s, string("mushrooms"));
@@ -161,7 +173,7 @@
 
 	s1.clear();
 	s1.insert("rosmarino"); s1.insert("margherita");
-	s = tc.getTags(s1);
+	s = tc.getMergedTags(s1);
 	inner_ensure_contains(s, string("tomato"));
 	inner_ensure_contains(s, string("mozzarella"));
 	inner_ensure_not_contains(s, string("mushrooms"));
@@ -170,7 +182,7 @@
 
 	s1.clear();
 	s1.insert("funghi"); s1.insert("margherita"); s1.insert("marinara");
-	s = tc.getTags(s1);
+	s = tc.getMergedTags(s1);
 	inner_ensure_contains(s, string("tomato"));
 	inner_ensure_contains(s, string("mozzarella"));
 	inner_ensure_contains(s, string("mushrooms"));
@@ -216,7 +228,7 @@
 	// getItems(tags)
 	s1.clear();
 	s1.insert("tomato"); s1.insert("mozzarella");
-	s = tc.getItems(s1);
+	s = tc.getCommonItems(s1);
 	inner_ensure_not_contains(s, string("gnocco"));
 	inner_ensure_contains(s, string("margherita"));
 	inner_ensure_contains(s, string("funghi"));
@@ -225,7 +237,7 @@
 
 	s1.clear();
 	s1.insert("garlic"); s1.insert("rosemerry");
-	s = tc.getItems(s1);
+	s = tc.getCommonItems(s1);
 	inner_ensure_not_contains(s, string("gnocco"));
 	inner_ensure_not_contains(s, string("margherita"));
 	inner_ensure_not_contains(s, string("funghi"));
@@ -234,7 +246,7 @@
 
 	s1.clear();
 	s1.insert("tomato"); s1.insert("rosemerry");
-	s = tc.getItems(s1);
+	s = tc.getCommonItems(s1);
 	inner_ensure_not_contains(s, string("gnocco"));
 	inner_ensure_not_contains(s, string("margherita"));
 	inner_ensure_not_contains(s, string("funghi"));
@@ -249,22 +261,23 @@
 
 	// void output(Consumer<ITEM, TAG>& consumer) const
 	InputMerger<string, string> coll1;
-	tc.output(coll1);
+	tc.output(inserter(coll1));
 	inner_ensure_coll_equals(tc, coll1);
 
 	// TODO:    virtual void outputHavingTags(const std::set<TAG>& tags, Consumer<ITEM, TAG>& consumer) const
 }
 
+template<typename COLL>
 void __test_collection(const Location& loc, COLL& tc)
 {
 	// Test handling of untagged items (they are not stored)
-	tc.consume("untagged");
+	tc.insert(tss("untagged"), wibble::Empty<string>());
 	inner_ensure(tc.getTags("untagged").empty());
 	
 	// Test handling of tagged items
 	std::set<string> tagset;
 	tagset.insert("tag1"); tagset.insert("tag2");
-	tc.consume("tagged", tagset);
+	tc.insert(tss("tagged"), tagset);
 	inner_ensure_contains(tc.getTaggedItems(), string("tagged"));
 	//inner_ensure(tc.hasTag("tag1"));
 	//inner_ensure(tc.hasTag("tag2"));
@@ -412,6 +425,8 @@
 }
 }
 
+#include <tagcoll/Patches.tcc>
+
 #endif
 
 #endif

Modified: tagcoll/2.0/tagcoll/tests/Makefile.am
==============================================================================
--- tagcoll/2.0/tagcoll/tests/Makefile.am	(original)
+++ tagcoll/2.0/tagcoll/tests/Makefile.am	Tue May  9 00:22:42 2006
@@ -5,16 +5,16 @@
 # test-textformat.cc
 libtagcoll_test_LDADD = -dlpreopen ../libtagcoll.la ../tagexpr/libtagexpr.la
 
-noinst_PROGRAMS = normalize mkgraph
+#noinst_PROGRAMS = normalize mkgraph
 # test-tagset
 
-normalize_SOURCES = \
-	normalize.cc
-normalize_LDADD = ../libtagcoll.la
-
-mkgraph_SOURCES = \
-	mkgraph.cc
-mkgraph_LDADD = ../libtagcoll.la
+#normalize_SOURCES = \
+#	normalize.cc
+#normalize_LDADD = ../libtagcoll.la
+
+#mkgraph_SOURCES = \
+#	mkgraph.cc
+#mkgraph_LDADD = ../libtagcoll.la
 
 #test_tagset_SOURCES = \
 	#test-tagset.cc

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	Tue May  9 00:22:42 2006
@@ -3,6 +3,9 @@
  * @author Peter Rockai (mornfall) <mornfall at danill.sk>
  * @brief Utility functions for the unit tests
  */
+#ifndef TAGCOLL_TEST_UTILS_H
+#define TAGCOLL_TEST_UTILS_H
+
 #include <wibble/tests.h>
 
 #include <string>
@@ -142,3 +145,5 @@
     }
 }
 */
+
+#endif



More information about the Debtags-commits mailing list