def test_correctness_randomized(self, variables, values): values = Multiset(values) for subst in commutative_sequence_variable_partition_iter(values, variables): assert len(variables) == len(subst) result_union = Multiset() for var in variables: assert len(subst[var.name]) >= var.minimum result_union.update(subst[var.name] * var.count) assert result_union == values
def test_correctness(self, variables, values, expected_iter_count): values = Multiset(values) variables = [VariableWithCount('var{:d}'.format(i), c, m, None) for i, (c, m) in enumerate(variables)] count = 0 for subst in commutative_sequence_variable_partition_iter(values, variables): assert len(variables) == len(subst), "Wrong number of variables in the substitution" result_union = Multiset() for var in variables: assert len(subst[var.name]) >= var.minimum, "Variable did not get its minimum number of expressions" result_union.update(subst[var.name] * var.count) assert result_union == values, "Substitution is not a partition of the values" count += 1 assert count == expected_iter_count, "Invalid number of substitution in the iterable"