diff --git a/PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl b/PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl new file mode 100644 index 0000000..1830169 Binary files /dev/null and b/PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl differ diff --git a/src/permpy/permset.py b/src/permpy/permset.py index 775fb3b..48648bb 100644 --- a/src/permpy/permset.py +++ b/src/permpy/permset.py @@ -58,7 +58,7 @@ def union(self, other): def get_random(self): """Return a random element from the set.""" - return random.sample(self, 1)[0] + return random.sample(list(self), 1)[0] def by_length(self): """Return a dictionary stratifying the permutations in `self`.""" diff --git a/src/permpy/permutation.py b/src/permpy/permutation.py index c5d2afc..dd15d79 100644 --- a/src/permpy/permutation.py +++ b/src/permpy/permutation.py @@ -1035,7 +1035,7 @@ def downset(self, min_length=0): return downset[::-1] - def downset_profile(self): + def downset_profile(self, min_length=0): """Return the downset profile of self. Notes @@ -1047,7 +1047,7 @@ def downset_profile(self): # downset = [set([pi])] profile = [len(new_perms)] - for new_length in range(len(self) - 1, -1, -1): + for new_length in range(len(self) - 1, min_length - 1, -1): old_perms = new_perms new_perms = dict() @@ -1059,7 +1059,6 @@ def downset_profile(self): else: new_perms[tau] = i - # downset.append(new_perms) profile.append(len(new_perms)) return profile[::-1] diff --git a/tests/test_permutation.py b/tests/test_permutation.py index ccd2d9d..302c5df 100644 --- a/tests/test_permutation.py +++ b/tests/test_permutation.py @@ -40,7 +40,7 @@ def test_direct_sum(): (q, q): Perm(31247568), (q, r): Perm(31245), } - for ((r, s), intended) in cases.items(): + for (r, s), intended in cases.items(): direct_sum = r + s assert direct_sum == intended, ( f"Expected the direct sum of {r} and {s} to be {intended}," @@ -59,7 +59,7 @@ def test_skew_sum(): (q, q): Perm(75683124), (q, r): Perm(42351), } - for ((r, s), intended) in cases.items(): + for (r, s), intended in cases.items(): skew_sum = r - s assert skew_sum == intended, ( f"Expected the skew sum of {r} and {s} to be {intended}," @@ -120,7 +120,7 @@ def test_containment(): def test_pow(): p = Perm(12345) for n in range(-5, 0, 5): - result = p ** n + result = p**n assert p == result, ( f"The identity permutation raised to the power {n}" f" resulted in {result}, not the identity permutation." @@ -129,7 +129,7 @@ def test_pow(): q = Perm(41352) powers = [Perm(12345), q, Perm(54321), Perm(25314), Perm(12345)] for exp, val in enumerate(powers): - assert q ** exp == val, f"Perm({q})^{exp} should be {val}, but it's {q**exp}!" + assert q**exp == val, f"Perm({q})^{exp} should be {val}, but it's {q**exp}!" def test_perm_to_ind(): @@ -433,3 +433,14 @@ def test_involved_in(): assert ( result == expected ), f"Perm({p}).involved_in({q}) is {result}, but it should be {expected}." + + +def test_involved_in(): + cases = [ + (Perm(123), [set([Perm()]), set([Perm(1)]), set([Perm(12)]), set([Perm(123)])]), + ] + for perm, expected in cases: + result = perm.downset() + assert ( + result == expected + ), f"Perm({perm}).downset() is {result}, but it should be {expected}."