Ejemplo n.º 1
0
class PartitionTests(unittest.TestCase):
    def setUp(self):
        self.partition = Partition([
            'a', 'd', 'a', 'a', 'b', 'a', 'b', 'c', 'c', 'd', 'd', 'd', 'd',
            'd'
        ])

    def test_restricted_growth_notation(self):
        expected = (0, 1, 0, 0, 2, 0, 2, 3, 3, 1, 1, 1, 1, 1)
        self.assertEqual(self.partition.partition_vector, expected)

    def test_membership_to_rgn(self):
        membership = [(0, 2, 3, 5), (1, 9, 10, 11, 12, 13), (4, 6), (7, 8)]
        inferred = Partition.from_membership(membership)
        self.assertEqual(inferred.partition_vector,
                         self.partition.partition_vector)

    def test_numbers(self):
        self.assertEqual(self.partition.num_elements(), 14)
        self.assertEqual(self.partition.num_groups(), 4)

    def test_get_membership(self):
        expected = [(0, 2, 3, 5), (1, 9, 10, 11, 12, 13), (4, 6), (7, 8)]
        self.assertEqual(self.partition.get_membership(), expected)

    def test_maximal(self):
        p1 = Partition([1, 1, 1, 1, 1, 1, 1, 1, 1])
        p2 = Partition([0, 1, 2, 3, 4, 5, 6, 7, 8])
        self.assertFalse(p1.is_maximal())
        self.assertTrue(p2.is_maximal())
        self.assertFalse(self.partition.is_maximal())

    def test_minimal(self):
        p1 = Partition([1, 1, 1, 1, 1, 1, 1, 1, 1])
        p2 = Partition([0, 1, 2, 3, 4, 5, 6, 7, 8])
        self.assertTrue(p1.is_minimal())
        self.assertFalse(p2.is_minimal())
        self.assertFalse(self.partition.is_minimal())

    def test_random(self):
        # Be aware, this has been known to spontaneously fail - problem with testing random things
        p = Partition.random([12, 12, 12], 12)
        self.assertEqual(p.num_groups(), 3)

    def test_equal(self):
        p1 = Partition([0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1])
        p2 = Partition([2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0])
        self.assertEqual(p1, p2)

    def test_not_equal(self):
        p1 = Partition([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1])
        p2 = Partition([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0])
        self.assertNotEqual(p1, p2)
Ejemplo n.º 2
0
Archivo: test.py Proyecto: kgori/treeCl
class PartitionTests(unittest.TestCase):
    def setUp(self):
        self.partition = Partition(['a', 'd', 'a', 'a', 'b', 'a', 'b', 'c', 'c', 'd', 'd', 'd', 'd', 'd'])

    def test_restricted_growth_notation(self):
        expected = (0, 1, 0, 0, 2, 0, 2, 3, 3, 1, 1, 1, 1, 1)
        self.assertEqual(self.partition.partition_vector, expected)

    def test_membership_to_rgn(self):
        membership = [(0, 2, 3, 5), (1, 9, 10, 11, 12, 13), (4, 6), (7, 8)]
        inferred = Partition.from_membership(membership)
        self.assertEqual(inferred.partition_vector, self.partition.partition_vector)

    def test_numbers(self):
        self.assertEqual(self.partition.num_elements(), 14)
        self.assertEqual(self.partition.num_groups(), 4)

    def test_get_membership(self):
        expected = [(0, 2, 3, 5), (1, 9, 10, 11, 12, 13), (4, 6), (7, 8)]
        self.assertEqual(self.partition.get_membership(), expected)

    def test_maximal(self):
        p1 = Partition([1, 1, 1, 1, 1, 1, 1, 1, 1])
        p2 = Partition([0, 1, 2, 3, 4, 5, 6, 7, 8])
        self.assertFalse(p1.is_maximal())
        self.assertTrue(p2.is_maximal())
        self.assertFalse(self.partition.is_maximal())

    def test_minimal(self):
        p1 = Partition([1, 1, 1, 1, 1, 1, 1, 1, 1])
        p2 = Partition([0, 1, 2, 3, 4, 5, 6, 7, 8])
        self.assertTrue(p1.is_minimal())
        self.assertFalse(p2.is_minimal())
        self.assertFalse(self.partition.is_minimal())

    def test_random(self):
        # Be aware, this has been known to spontaneously fail - problem with testing random things
        p = Partition.random([12, 12, 12], 12)
        self.assertEqual(p.num_groups(), 3)

    def test_equal(self):
        p1 = Partition([0,0,0,0,0,2,2,2,2,2,1,1,1,1,1])
        p2 = Partition([2,2,2,2,2,1,1,1,1,1,0,0,0,0,0])
        self.assertEqual(p1, p2)

    def test_not_equal(self):
        p1 = Partition([0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
        p2 = Partition([0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0])
        self.assertNotEqual(p1, p2)
Ejemplo n.º 3
0
Archivo: test.py Proyecto: kgori/treeCl
 def test_minimal(self):
     p1 = Partition([1, 1, 1, 1, 1, 1, 1, 1, 1])
     p2 = Partition([0, 1, 2, 3, 4, 5, 6, 7, 8])
     self.assertTrue(p1.is_minimal())
     self.assertFalse(p2.is_minimal())
     self.assertFalse(self.partition.is_minimal())
Ejemplo n.º 4
0
 def test_minimal(self):
     p1 = Partition([1, 1, 1, 1, 1, 1, 1, 1, 1])
     p2 = Partition([0, 1, 2, 3, 4, 5, 6, 7, 8])
     self.assertTrue(p1.is_minimal())
     self.assertFalse(p2.is_minimal())
     self.assertFalse(self.partition.is_minimal())