Пример #1
0
class TestAlternatingGroup(unittest.TestCase):

    def setUp(self): pass

    def test_alt_5(self):
        self.N = 5
        self.group = Group()
        self.assertEqual(self.group.order(), 1)
        self.group.insert(Perm()(0, 1, 2))
        self.assertEqual(self.group.order(), 3)
        self.group.insert(Perm()(1, 2, 3))
        self.assertEqual(self.group.order(), 12)
        self.group.insert(Perm()(2, 3, 4))
        self.assertEqual(self.group.order(), 60)
        self.assertFalse(Perm()(0, 1) in self.group)
        self.assertTrue(Perm()(*range(self.N)) in self.group) # N is odd
        self.assertTrue(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 1)

    def test_alt_n(self):
        self.N = 5
        self.assertTrue(self.N > 2)
        self.group = Group()
        order = 1
        for i in range(self.N-2):
            self.group.insert(Perm()(i, i+1, i+2))
            order = order * (i+3)
            self.assertEqual(self.group.order(), order)
        self.assertTrue(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 1)

    def tearDown(self): pass
Пример #2
0
class TestAlternatingGroup(unittest.TestCase):
    def setUp(self):
        pass

    def test_alt_5(self):
        self.N = 5
        self.group = Group()
        self.assertEqual(self.group.order(), 1)
        self.group.insert(Perm()(0, 1, 2))
        self.assertEqual(self.group.order(), 3)
        self.group.insert(Perm()(1, 2, 3))
        self.assertEqual(self.group.order(), 12)
        self.group.insert(Perm()(2, 3, 4))
        self.assertEqual(self.group.order(), 60)
        self.assertFalse(Perm()(0, 1) in self.group)
        self.assertTrue(Perm()(*range(self.N)) in self.group)  # N is odd
        self.assertTrue(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 1)

    def test_alt_n(self):
        self.N = 5
        self.assertTrue(self.N > 2)
        self.group = Group()
        order = 1
        for i in range(self.N - 2):
            self.group.insert(Perm()(i, i + 1, i + 2))
            order = order * (i + 3)
            self.assertEqual(self.group.order(), order)
        self.assertTrue(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 1)

    def tearDown(self):
        pass
Пример #3
0
class TestSymmetricGroup(unittest.TestCase):

    def setUp(self): pass

    def test_sym_5(self):
        self.N = 5
        self.group = Group()
        self.assertEqual(self.group.order(), 1)
        self.group.insert(Perm()(0, 1))
        self.assertEqual(self.group.order(), 2)
        self.group.insert(Perm()(1, 2))
        self.assertEqual(self.group.order(), 6)
        self.group.insert(Perm()(2, 3))
        self.assertEqual(self.group.order(), 24)
        self.group.insert(Perm()(3, 4))
        self.assertEqual(self.group.order(), 120)
        self.assertTrue(Perm()(*range(self.N)) in self.group)
        self.assertTrue(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 1)

    def test_sym_n(self):
        self.N = 4
        self.group = Group()
        order = 1
        for i in range(self.N-1):
            self.group.insert(Perm()(i, i+1))
            order *= (i+2)
            self.assertEqual(self.group.order(), order)
        self.assertTrue(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 1)

    def tearDown(self): pass
Пример #4
0
class TestCyclicGroup(unittest.TestCase):

    def setUp(self):
        # The cyclic group from the paper by Knuth.
        self.N = 6
        self.H = Perm()(0, 1, 2, 4)(3, 5)
        self.group = Group()
        self.group.insert(self.H)

    def test_group(self):
        self.assertEqual(self.group.order(), 4)
        self.assertFalse(self.group.is_trivial())
        self.assertTrue(Perm() in self.group)
        self.assertTrue(self.H in self.group)
        points = range(self.N)
        self.assertFalse(Perm()(*points) in self.group)
        self.assertEqual(self.group.orbits(points), [[0, 4, 2, 1], [3, 5]])
        self.assertEqual(len(self.group.orbits(points)), 2)
        self.assertFalse(self.group.is_transitive(points))

    def test_cyclic6(self):
        points = range(5)
        C6 = Group()
        C6.insert(Perm()(0, 1, 2)(3, 4))
        self.assertEqual(C6.order(), 6)
        self.assertEqual(C6.orbits(points), [[0, 2, 1], [3, 4]])
        self.assertEqual(len(C6.orbits(points)), 2)
        self.assertFalse(C6.is_transitive(points))

    def tearDown(self): pass
Пример #5
0
class TestCyclicGroup(unittest.TestCase):
    def setUp(self):
        # The cyclic group from the paper by Knuth.
        self.N = 6
        self.H = Perm()(0, 1, 2, 4)(3, 5)
        self.group = Group()
        self.group.insert(self.H)

    def test_group(self):
        self.assertEqual(self.group.order(), 4)
        self.assertFalse(self.group.is_trivial())
        self.assertTrue(Perm() in self.group)
        self.assertTrue(self.H in self.group)
        points = range(self.N)
        self.assertFalse(Perm()(*points) in self.group)
        self.assertEqual(self.group.orbits(points), [[0, 4, 2, 1], [3, 5]])
        self.assertEqual(len(self.group.orbits(points)), 2)
        self.assertFalse(self.group.is_transitive(points))

    def test_cyclic6(self):
        points = range(5)
        C6 = Group()
        C6.insert(Perm()(0, 1, 2)(3, 4))
        self.assertEqual(C6.order(), 6)
        self.assertEqual(C6.orbits(points), [[0, 2, 1], [3, 4]])
        self.assertEqual(len(C6.orbits(points)), 2)
        self.assertFalse(C6.is_transitive(points))

    def tearDown(self):
        pass
Пример #6
0
 def test_cyclic6(self):
     points = range(5)
     C6 = Group()
     C6.insert(Perm()(0, 1, 2)(3, 4))
     self.assertEqual(C6.order(), 6)
     self.assertEqual(C6.orbits(points), [[0, 2, 1], [3, 4]])
     self.assertEqual(len(C6.orbits(points)), 2)
     self.assertFalse(C6.is_transitive(points))
Пример #7
0
 def test_cyclic6(self):
     points = range(5)
     C6 = Group()
     C6.insert(Perm()(0, 1, 2)(3, 4))
     self.assertEqual(C6.order(), 6)
     self.assertEqual(C6.orbits(points), [[0, 2, 1], [3, 4]])
     self.assertEqual(len(C6.orbits(points)), 2)
     self.assertFalse(C6.is_transitive(points))
Пример #8
0
class TestCyclicGroup(unittest.TestCase):

    def setUp(self):
        # The cyclic group from the paper by Knuth.
        self.N = 6
        self.H = Perm()(0, 1, 2, 4)(3, 5)
        self.group = Group()
        self.group.insert(self.H)

    def test_group(self):
        self.assertEqual(self.group.order(), 4)
        self.assertFalse(self.group.is_trivial())
        self.assertTrue(Perm() in self.group)
        self.assertTrue(self.H in self.group)
        self.assertFalse(Perm()(*range(self.N)) in self.group)
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(len(self.group.orbits(range(self.N))), 2)

    def tearDown(self): pass
Пример #9
0
class TestGroupOrbits(unittest.TestCase):
    def setUp(self):
        pass

    def test_orbits1(self):
        self.N = 3
        self.group = Group()
        self.group.insert(Perm()(0, 1))
        self.assertEqual(self.group.orbits(range(self.N)), [[0, 1], [2]])
        self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertTrue(
            self.group.is_transitive(points=range(self.N), strict=False))

    def test_orbits2(self):
        self.N = 4
        self.group = Group()
        self.group.insert(Perm()(0, 1))
        self.group.insert(Perm()(2, 3))
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(self.group.orbits(range(self.N)), [[0, 1], [2, 3]])
        self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
        self.assertEqual(self.group.orbits([0, 1, 2]), [[0, 1], [2, 3]])

    def test_orbits3(self):  # grupa cykliczna
        self.N = 10
        self.group = Group()
        self.group.insert(Perm()(*range(self.N)))
        self.assertTrue(self.group.is_transitive(points=range(self.N)))

    def test_orbits4(self):
        self.N = 10
        self.group = Group()
        self.group.insert(Perm()(0, 1, 2))
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertTrue(
            self.group.is_transitive(strict=False, points=range(self.N)))

    def tearDown(self):
        pass
Пример #10
0
class TestGroupOrbits(unittest.TestCase):

    def setUp(self): pass

    def test_orbits1(self):
        self.N = 3
        self.group = Group()
        self.group.insert(Perm()(0,1))
        self.assertEqual(self.group.orbits(range(self.N)), [[0, 1],[2]])
        self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertTrue(self.group.is_transitive(points=range(self.N), strict=False))

    def test_orbits2(self):
        self.N = 4
        self.group = Group()
        self.group.insert(Perm()(0, 1))
        self.group.insert(Perm()(2, 3))
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertEqual(self.group.orbits(range(self.N)), [[0, 1],[2, 3]])
        self.assertEqual(self.group.orbits([0, 1]), [[0, 1]])
        self.assertEqual(self.group.orbits([0, 1, 2]), [[0, 1],[2, 3]])

    def test_orbits3(self):  # grupa cykliczna
        self.N = 10
        self.group = Group()
        self.group.insert(Perm()(*range(self.N)))
        self.assertTrue(self.group.is_transitive(points=range(self.N)))

    def test_orbits4(self):
        self.N = 10
        self.group = Group()
        self.group.insert(Perm()(0, 1, 2))
        self.assertFalse(self.group.is_transitive(points=range(self.N)))
        self.assertTrue(self.group.is_transitive(strict=False, points=range(self.N)))

    def tearDown(self): pass