def test_split_unequal(self):
        """Test splitUnequal"""

        #
        # Create the fiber to be split
        #
        c = [0, 1, 9, 10, 12, 31, 41]
        p = [0, 10, 20, 100, 120, 310, 410]

        f = Fiber(c, p)

        #
        # Create list of reference fibers after the split
        #
        css = [[0], [1, 9], [10, 12, 31, 41]]

        pss = [[0], [10, 20], [100, 120, 310, 410]]

        split_ref = []

        for (cs, ps) in zip(css, pss):
            split_ref.append(Fiber(cs, ps))

        #
        # Do the split
        #
        sizes = [1, 2, 4]
        split = f.splitUnEqual(sizes)

        #
        # Check the split
        #
        for i, (sc, sp) in enumerate(split):
            self.assertEqual(sc, css[i][0])
            self.assertEqual(sp, split_ref[i])
    def test_split_unequal_empty(self):
        """Test splitUnEqual on empty fiber"""
        empty = Fiber()
        split = empty.splitUnEqual([1, 5, 17])

        # After we split, we need to make sure that we have actually added
        # another level to the empty fiber
        self.assertIsInstance(split.getDefault(), Fiber)
    def test_split_unequal_below(self):
        """Test splitUnEqualBelow"""

        c0 = [0, 1, 9, 10, 12, 31, 41]
        p0 = [ 0, 10, 20, 100, 120, 310, 410 ]
        f0 = Fiber(c0, p0)

        c1 = [1, 2, 10, 11, 13, 32, 42]
        p1 = [ 1, 11, 21, 101, 121, 311, 411 ]
        f1 = Fiber(c1, p1)

        c = [2, 4]
        f = Fiber(c, [f0, f1])

        f.splitUnEqualBelow([3, 3, 1], depth=0)

        f0_split = f0.splitUnEqual([3, 3, 1])
        f1_split = f1.splitUnEqual([3, 3, 1])

        f_ref = Fiber(c, [f0_split, f1_split])

        self.assertEqual(f, f_ref)
    def test_split_unequal_then_flatten(self):
        """Test that flattenRanks can undo splitUnequal"""

        #
        # Create the fiber to be split
        #
        c = [0, 1, 9, 10, 12, 31, 41]
        p = [0, 10, 20, 100, 120, 310, 410]

        f = Fiber(c, p)

        #
        # Do the split
        #
        sizes = [1, 2, 4]
        split = f.splitUnEqual(sizes)

        #
        # Check the split
        #
        self.assertEqual(split.flattenRanks(style="absolute"), f)
Exemple #5
0
#
# Equal position-based split
#
size = 2
print(f"Equal position split (groups of {size})\n")

fibers = f.splitEqual(size)

for c, s in fibers:
    s.print()

sizes = [1, 2, 4]
print(f"NonEqual position split (splits of sizes {sizes})\n")

fibers = f.splitUnEqual(sizes)

for c, s in fibers:
    s.print()

#
# Create multiple partitions
#

#
# Equal position-based split
#
size = 2
print(f"Two partitions with equal position split (groups of {size})\n")

fibers = f.splitEqual(size, partitions=2)