Skip to content

Commit

Permalink
Added small test
Browse files Browse the repository at this point in the history
  • Loading branch information
engenmt committed Nov 6, 2023
1 parent 94a2a59 commit f04ecb1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Binary file added PyYAML-6.0-cp311-cp311-macosx_11_0_arm64.whl
Binary file not shown.
2 changes: 1 addition & 1 deletion src/permpy/permset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""
Expand Down
5 changes: 2 additions & 3 deletions src/permpy/permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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]
Expand Down
19 changes: 15 additions & 4 deletions tests/test_permutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},"
Expand All @@ -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},"
Expand Down Expand Up @@ -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."
Expand All @@ -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():
Expand Down Expand Up @@ -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}."

0 comments on commit f04ecb1

Please sign in to comment.