def setUp(self): self.perm6 = Perm({1: 2, 2: 1, 3: 3, 4: 5, 5: 6, 6: 4}) self.operm = Perm({}) self.permoc = Perm.from_cycle([]) self.perm1c = Perm.from_cycle([1]) self.perm2c = Perm.from_cycle([1, 2]) self.perm3c = Perm.from_cycle([1, 2, 3]) # huge list of hopefully lots of different kinds of permutation covering # lots of edge cases self.reg_perms = [ self.permoc, self.perm1c, self.perm2c, self.perm3c, *(Perm.from_cycle(range(j, j + i)) for i in range(4, 9) for j in range(9 - i)), *(Perm.from_cycle(range(j, j + i)[::-1]) for i in range(2, 9) for j in range(9 - i)), self.operm, self.perm6 ] # add some more random permutations to hopefully catch more edge cases, # but keep them in a separate list so I can also access a deterministic # list of permutations that I can guarantee properties of self.perms = [ *self.reg_perms, *(Perm.random(range(i)) for i in range(4, 20)) ] for _ in range(10): a, b = sample(self.perms, 2) self.perms.append(a * b)
def test_random(self): # check valid permutations are given for i in range(100): self.assertTrue(Perm.random(range(i)).is_permutation)