def testCPermutation(self): test_perm = (0,1,2,5,6,3,4) qtp = CPermutation.create(test_perm) self.assertRaises(Exception, CPermutation.create,(list(test_perm))) self.assertEqual(qtp.series_inverse(), CPermutation.create(invert_permutation(test_perm))) self.assertEqual(qtp.block_structure, (1,1,1,4)) id1 = circuit_identity(1) self.assertEqual(qtp.get_blocks(), (id1, id1, id1, CPermutation.create((2,3,0,1)))) self.assertEqual(CPermutation((1,0,3,2)).get_blocks(), (CPermutation((1,0)), CPermutation((1,0)))) nt = len(test_perm) self.assertEqual(qtp << qtp.series_inverse(), circuit_identity(nt)) self.assertEqual(permute(list(invert_permutation(test_perm)), test_perm), list(range(nt)))
def testPermutation(self): n = 5 self.assertEqual(CPermutation.create(()), circuit_identity(0)) invalid_permutation = (1,1) self.assertRaises(Exception, CPermutation.create, (invalid_permutation,)) p_id = tuple(range(n)) self.assertEqual(CPermutation.create(p_id), circuit_identity(n)) self.assertEqual(map_signals({0:1,1:0}, 2), (1,0)) self.assertEqual(map_signals({0:5,1:0}, 6), (5,0,1,2,3,4)) self.assertEqual(map_signals({0:5,1:0, 3:2}, 6), invert_permutation(map_signals({5:0,0:1, 2:3}, 6)))
def testCPermutation(self): self.assertEqual(parse_circuit_strings('P_sigma(0,2,1)'), CPermutation((0, 2, 1))) self.assertEqual(parse_circuit_strings('P_sigma(0,2,1,4,3)'), CPermutation((0, 2, 1, 4, 3)))
def testDrawCPermutation(self): self.assertCanBeDrawn(CPermutation((0, 2, 3, 1)))