def test_split_uniform_empty(self):
        """Test splitUniform on empty fiber"""
        empty = Fiber()
        split = empty.splitUniform(5)

        # 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_uniform_below(self):
        """Test splitUniformBelow"""

        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.splitUniformBelow(10, depth=0)

        f0_split = f0.splitUniform(10)
        f1_split = f1.splitUniform(10)

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

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

        #
        # 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
        #
        coords = 10
        split = f.splitUniform(coords)

        #
        # Check that flattening after splitting gives us the same answer
        #
        self.assertEqual(split.flattenRanks(style="absolute"), f)
    def test_split_uniform_relative_then_flatten(self):
        """Test that flattenRanks can undo splitUniform (relative)"""

        #
        # 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
        #
        coords = 10
        split = f.splitUniform(coords, relativeCoords=True)

        #
        # Check the split
        #
        self.assertEqual(split.flattenRanks(style="relative"), f)
    def test_split_uniform_relative(self):
        """Test splitUniform"""

        #
        # 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
        #
        split_ref_coords = [0, 10, 30, 40]

        css = [[0, 1, 9], [0, 2], [1], [1]]

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

        split_ref_payloads = []

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

        #
        # Do the split
        #
        coords = 10
        split = f.splitUniform(coords, relativeCoords=True)

        #
        # Check the split
        #
        for i, (sc, sp) in enumerate(split):
            self.assertEqual(sc, split_ref_coords[i])
            self.assertEqual(sp, split_ref_payloads[i])
예제 #6
0
from fibertree import Fiber

f = Fiber([0, 1, 2, 10, 12, 31, 41], [0, 10, 20, 100, 120, 310, 410])

print("Original fiber\n")
f.print()

#
# Unform coordiate-based split
#
coords = 10
print("Uniform coordinate split (groups of %s coordinates)\n" % coords)

fibers = f.splitUniform(coords)

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

#
# Non-unform coordiate-based split
#
splits = [0, 12, 31]
print(f"NonUniform coordinate split (splits at {splits})\n")

fibers = f.splitNonUniform(splits)

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

#
# Equal position-based split