def check_equivalence_partition( classes, partitions, relation ):
	"""Checks that a partition is consistent under the relationship"""
	for o, c in partitions.iteritems():
		for _c in classes:
			assert (o in _c) ^ (not _c is c)
	for c1 in classes:
		for o1 in c1:
			for c2 in classes:
				for o2 in c2:
					assert (c1 is c2) ^ (not relation( o1, o2 ))
Checks that a partition is consistent under the relationship
recipes/Python/499354_Equivalence_partition/recipe-499354.py