Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_algorithm_returns_a_list_for_given_equivalence_class(self):
col = [10]
r = lambda item: item * item
partitioned = EquivalenceClassSetPartition.partition(col, r)
assert isinstance(partitioned[100], list)
def test_algorithm_returns_the_item_in_the_list_for_given_equivalence_class(self):
col = [10]
r = lambda item: item * item
partitioned = EquivalenceClassSetPartition.partition(col, r)
assert partitioned[100][0] == 10
def test_algorithm_returns_proper_equivalence_class(self):
col = [10]
r = lambda item: item * item
partitioned = EquivalenceClassSetPartition.partition(col, r)
assert partitioned.has_key(100)
def test_algorithm_returns_a_dictionary(self):
partitioned = EquivalenceClassSetPartition.partition([1], lambda item: item)
assert isinstance(partitioned, dict)
def __group_collection(self, collection, group_expression):
if isinstance(group_expression, NameExpression):
expr_name = group_expression.name
if "." in expr_name:
rel = lambda item: reduce(getattr, expr_name, item)
else:
rel = lambda item: getattr(item, expr_name)
else:
rel = lambda item: eval(str(query.group_expression))
return EquivalenceClassSetPartition.partition(collection, rel)