Exemplo n.º 1
0
def test_rhythmtreetools_RhythmTreeContainer___eq___03():

    a = rhythmtreetools.RhythmTreeContainer(children=[])
    b = rhythmtreetools.RhythmTreeContainer(preprolated_duration=2,
                                            children=[])
    c = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1,
        children=[rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)])
    d = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=2,
        children=[rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)])
    e = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=2,
        children=[rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)])

    assert a != b
    assert a != c
    assert a != d
    assert a != e
    assert b != c
    assert b != d
    assert b != e
    assert c != d
    assert c != e
    assert d != e
Exemplo n.º 2
0
def test_rhythmtreetools_RhythmTreeLeaf___eq___01():

    a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1, is_pitched=True)
    b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1, is_pitched=True)

    assert format(a) == format(b)
    assert a != b
Exemplo n.º 3
0
def test_rhythmtreetools_RhythmTreeNode_duration_01():

    tree = rhythmtreetools.RhythmTreeContainer(preprolated_duration=1, children=[
        rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1),
        rhythmtreetools.RhythmTreeContainer(preprolated_duration=2, children=[
            rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3),
            rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
        ]),
        rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    ])

    assert tree.duration == abjad.Duration(1)
    assert tree[0].duration == abjad.Duration(1, 5)
    assert tree[1].duration == abjad.Duration(2, 5)
    assert tree[1][0].duration == abjad.Duration(6, 25)
    assert tree[1][1].duration == abjad.Duration(4, 25)
    assert tree[2].duration == abjad.Duration(2, 5)

    tree[1].append(tree.pop())

    assert tree.duration == abjad.Duration(1)
    assert tree[0].duration == abjad.Duration(1, 3)
    assert tree[1].duration == abjad.Duration(2, 3)
    assert tree[1][0].duration == abjad.Duration(2, 7)
    assert tree[1][1].duration == abjad.Duration(4, 21)
    assert tree[1][2].duration == abjad.Duration(4, 21)

    tree.preprolated_duration = 19

    assert tree.duration == abjad.Duration(19)
    assert tree[0].duration == abjad.Duration(19, 3)
    assert tree[1].duration == abjad.Duration(38, 3)
    assert tree[1][0].duration == abjad.Duration(38, 7)
    assert tree[1][1].duration == abjad.Duration(76, 21)
    assert tree[1][2].duration == abjad.Duration(76, 21)
Exemplo n.º 4
0
def test_rhythmtreetools_RhythmTreeContainer___init___03():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    assert leaf_a.start_offset == 0
    assert leaf_a.parent is None

    assert leaf_b.start_offset == 0
    assert leaf_b.parent is None

    assert leaf_c.start_offset == 0
    assert leaf_c.parent is None

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=4, children=[leaf_a, leaf_b, leaf_c])

    assert container.children == (leaf_a, leaf_b, leaf_c)
    assert container.preprolated_duration == 4
    assert container.start_offset == 0
    assert container.parent is None

    assert leaf_a.start_offset == 0
    assert leaf_a.parent is container

    assert leaf_b.start_offset == 1
    assert leaf_b.parent is container

    assert leaf_c.start_offset == 3
    assert leaf_c.parent is container
Exemplo n.º 5
0
def test_rhythmtreetools_RhythmTreeContainer___eq___02():

    a = rhythmtreetools.RhythmTreeContainer(
        children=[rhythmtreetools.RhythmTreeLeaf()])
    b = rhythmtreetools.RhythmTreeContainer(
        children=[rhythmtreetools.RhythmTreeLeaf()])

    assert a == b
Exemplo n.º 6
0
def test_rhythmtreetools_RhythmTreeContainer___eq___02():

    a = rhythmtreetools.RhythmTreeContainer(
        children=[rhythmtreetools.RhythmTreeLeaf()])
    b = rhythmtreetools.RhythmTreeContainer(
        children=[rhythmtreetools.RhythmTreeLeaf()])

    assert format(a) == format(b)
    assert a != b
Exemplo n.º 7
0
def test_rhythmtreetools_RhythmTreeContainer___iter___01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, leaf_b, leaf_c])

    assert [x for x in container] == [leaf_a, leaf_b, leaf_c]
Exemplo n.º 8
0
def test_rhythmtreetools_RhythmTreeLeaf___eq___02():

    a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1, is_pitched=True)
    b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1, is_pitched=False)
    c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2, is_pitched=True)
    d = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2, is_pitched=False)

    assert a != b
    assert a != c
    assert a != d
    assert b != c
    assert b != d
    assert c != d
def test_rhythmtreetools_RhythmTreeContainer_children_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    subcontainer = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=2, children=[leaf_b, leaf_c])
    leaf_d = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, subcontainer, leaf_d])

    assert container.children == (leaf_a, subcontainer, leaf_d)
def test_rhythmtreetools_RhythmTreeContainer_rtm_format_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    subcontainer = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=2, children=[leaf_b, leaf_c])
    leaf_d = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)
    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, subcontainer, leaf_d])

    assert subcontainer.rtm_format == '(2 (3 2))'
    assert container.rtm_format == '(1 (3 (2 (3 2)) 1))'
def test_rhythmtreetools_RhythmTreeContainer___contains___01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    subcontainer = rhythmtreetools.RhythmTreeContainer(preprolated_duration=1,
                                                       children=[leaf_b])

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, subcontainer])

    assert leaf_a in container
    assert leaf_b not in container
    assert leaf_c not in container
def test_rhythmtreetools_RhythmTreeNode_depth_01():

    container = rhythmtreetools.RhythmTreeContainer()
    assert container.depth == 0

    leaf = rhythmtreetools.RhythmTreeLeaf()
    assert leaf.depth == 0

    container.append(leaf)
    assert leaf.depth == 1

    subcontainer = rhythmtreetools.RhythmTreeContainer()
    assert subcontainer.depth == 0

    container.append(subcontainer)
    assert subcontainer.depth == 1

    subcontainer.append(leaf)
    assert leaf.depth == 2

    subsubcontainer = rhythmtreetools.RhythmTreeContainer()
    assert subsubcontainer.depth == 0

    subcontainer.append(subsubcontainer)
    assert subsubcontainer.depth == 2

    subsubcontainer.append(leaf)
    assert leaf.depth == 3
def test_rhythmtreetools_RhythmTreeContainer_insert_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)

    container = rhythmtreetools.RhythmTreeContainer()
    assert container.children == ()

    container.insert(0, leaf_a)
    assert container.children == (leaf_a,)

    container.insert(0, leaf_b)
    assert container.children == (leaf_b, leaf_a)

    container.insert(1, leaf_c)
    assert container.children == (leaf_b, leaf_c, leaf_a)
def test_rhythmtreetools_RhythmTreeContainer_index_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    subcontainer = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=2, children=[leaf_b, leaf_c])
    leaf_d = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)
    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, subcontainer, leaf_d])

    assert container.index(leaf_a) == 0
    assert container.index(subcontainer) == 1
    assert container.index(leaf_d) == 2

    pytest.raises(ValueError, 'container.index(leaf_b)')
    pytest.raises(ValueError, 'container.index(leaf_c)')
Exemplo n.º 15
0
 def p_leaf__INTEGER(self, p):
     r'''leaf : DURATION
     '''
     from abjad.tools import rhythmtreetools
     p[0] = rhythmtreetools.RhythmTreeLeaf(
         preprolated_duration=abs(p[1]),
         is_pitched=0 < p[1],
     )
Exemplo n.º 16
0
def test_rhythmtreetools_RhythmTreeLeaf___copy___01():

    leaf = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    copied = copy.copy(leaf)

    assert format(leaf) == format(copied)
    assert leaf is not copied
Exemplo n.º 17
0
def test_rhythmtreetools_RhythmTreeLeaf___copy___02():

    leaf = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2, is_pitched=True)

    copied = copy.copy(leaf)

    assert leaf == copied
    assert leaf is not copied
def test_rhythmtreetools_RhythmTreeContainer_extend_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    leaf_d = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    container = rhythmtreetools.RhythmTreeContainer()

    assert container.children == ()

    container.extend([leaf_a])
    assert container.children == (leaf_a, )

    container.extend([leaf_b, leaf_c, leaf_d])
    assert container.children == (leaf_a, leaf_b, leaf_c, leaf_d)

    container.extend([leaf_a, leaf_c])
    assert container.children == (leaf_b, leaf_d, leaf_a, leaf_c)
Exemplo n.º 19
0
def test_rhythmtreetools_RhythmTreeContainer_remove_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, leaf_b, leaf_c])
    assert container.children == (leaf_a, leaf_b, leaf_c)
    assert leaf_a.parent is container
    assert leaf_b.parent is container
    assert leaf_c.parent is container

    container.remove(leaf_a)
    assert container.children == (leaf_b, leaf_c)
    assert leaf_a.parent is None

    container.remove(leaf_c)
    assert container.children == (leaf_b,)
    assert leaf_c.parent is None
Exemplo n.º 20
0
def test_rhythmtreetools_RhythmTreeContainer___getitem___01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1)

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, leaf_b, leaf_c])

    assert container[0] is leaf_a
    assert container[1] is leaf_b
    assert container[2] is leaf_c

    pytest.raises(Exception, 'container[3]')

    assert container[-1] is leaf_c
    assert container[-2] is leaf_b
    assert container[-3] is leaf_a

    pytest.raises(Exception, 'container[-4]')
Exemplo n.º 21
0
def test_rhythmtreetools_RhythmTreeContainer_pop_01():

    leaf_a = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_b = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3)
    leaf_c = rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)

    container = rhythmtreetools.RhythmTreeContainer(
        preprolated_duration=1, children=[leaf_a, leaf_b, leaf_c])
    assert container.children == (leaf_a, leaf_b, leaf_c)
    assert leaf_a.parent is container
    assert leaf_b.parent is container
    assert leaf_c.parent is container

    result = container.pop()
    assert container.children == (leaf_a, leaf_b)
    assert result is leaf_c
    assert result.parent is None

    result = container.pop(0)
    assert container.children == (leaf_b, )
    assert result is leaf_a
    assert result.parent is None
def test_rhythmtreetools_RhythmTreeNode_offset_01():

    tree = rhythmtreetools.RhythmTreeContainer(preprolated_duration=1, children=[
        rhythmtreetools.RhythmTreeLeaf(preprolated_duration=1),
        rhythmtreetools.RhythmTreeContainer(preprolated_duration=2, children=[
            rhythmtreetools.RhythmTreeLeaf(preprolated_duration=3),
            rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
        ]),
        rhythmtreetools.RhythmTreeLeaf(preprolated_duration=2)
    ])

    assert tree.start_offset == abjad.Offset(0)
    assert tree[0].start_offset == abjad.Offset(0)
    assert tree[1].start_offset == abjad.Offset(1, 5)
    assert tree[1][0].start_offset == abjad.Offset(1, 5)
    assert tree[1][1].start_offset == abjad.Offset(11, 25)
    assert tree[2].start_offset == abjad.Offset(3, 5)

    node = tree.pop()

    assert node.start_offset == abjad.Offset(0)

    tree[1].append(node)

    assert tree.start_offset == abjad.Offset(0)
    assert tree[0].start_offset == abjad.Offset(0)
    assert tree[1].start_offset == abjad.Offset(1, 3)
    assert tree[1][0].start_offset == abjad.Offset(1, 3)
    assert tree[1][1].start_offset == abjad.Offset(13, 21)
    assert tree[1][2].start_offset == abjad.Offset(17, 21)

    tree.preprolated_duration = 19

    assert tree.start_offset == abjad.Offset(0)
    assert tree[0].start_offset == abjad.Offset(0)
    assert tree[1].start_offset == abjad.Offset(19, 3)
    assert tree[1][0].start_offset == abjad.Offset(19, 3)
    assert tree[1][1].start_offset == abjad.Offset(247, 21)
    assert tree[1][2].start_offset == abjad.Offset(323, 21)
Exemplo n.º 23
0
def test_rhythmtreetools_RhythmTreeNode_proper_parentage_01():

    leaf = rhythmtreetools.RhythmTreeLeaf()
    subsubcontainer = rhythmtreetools.RhythmTreeContainer()
    subcontainer = rhythmtreetools.RhythmTreeContainer()
    container = rhythmtreetools.RhythmTreeContainer()

    container.append(subcontainer)
    subcontainer.append(subsubcontainer)
    subsubcontainer.append(leaf)

    assert leaf.proper_parentage == (subsubcontainer, subcontainer, container)
    assert subsubcontainer.proper_parentage == (subcontainer, container)
    assert subcontainer.proper_parentage == (container, )
    assert container.proper_parentage == ()
def test_rhythmtreetools_RhythmTreeNode_root_01():

    leaf = rhythmtreetools.RhythmTreeLeaf()
    subsubcontainer = rhythmtreetools.RhythmTreeContainer()
    subcontainer = rhythmtreetools.RhythmTreeContainer()
    container = rhythmtreetools.RhythmTreeContainer()

    container.append(subcontainer)
    subcontainer.append(subsubcontainer)
    subsubcontainer.append(leaf)

    assert leaf.root == container
    assert subsubcontainer.root == container
    assert subcontainer.root == container
    assert container.root == container
def test_rhythmtreetools_RhythmTreeNode_improper_parentage_01():

    container = rhythmtreetools.RhythmTreeContainer()
    assert container.improper_parentage == (container, )

    leaf = rhythmtreetools.RhythmTreeLeaf()
    assert leaf.improper_parentage == (leaf, )

    container.append(leaf)
    assert leaf.improper_parentage == (leaf, container)

    subcontainer = rhythmtreetools.RhythmTreeContainer(preprolated_duration=1,
                                                       children=[leaf])
    container.append(subcontainer)
    assert leaf.improper_parentage == (leaf, subcontainer, container)
def test_rhythmtreetools_RhythmTreeNode_parent_01():

    leaf = rhythmtreetools.RhythmTreeLeaf()
    container = rhythmtreetools.RhythmTreeContainer()
    subcontainer = rhythmtreetools.RhythmTreeContainer()

    assert leaf.parent is None
    assert container.parent is None
    assert subcontainer.parent is None

    container.append(leaf)
    assert leaf.parent is container

    container.append(subcontainer)
    assert subcontainer.parent is container
    assert leaf.parent is container
    assert container.parent is None

    subcontainer.append(leaf)
    assert leaf.parent is subcontainer
    assert subcontainer.parent is container
    assert container.parent is None

    pytest.raises(AssertionError, 'subcontainer.append(container)')
Exemplo n.º 27
0
 def recurse(
     node,
     factors,
     denominator,
     decrease_durations_monotonically,
 ):
     if factors:
         factor, factors = factors[0], factors[1:]
         preprolated_duration = \
             node.preprolated_duration.__div__(factor)
         #if factor in (2, 3, 4, 5):
         if factor in (2, 3, 4):
             if factors:
                 for _ in range(factor):
                     child = rhythmtreetools.RhythmTreeContainer(
                         preprolated_duration=preprolated_duration)
                     node.append(child)
                     recurse(
                         child,
                         factors,
                         denominator,
                         decrease_durations_monotonically,
                     )
             else:
                 for _ in range(factor):
                     node.append(
                         rhythmtreetools.RhythmTreeLeaf(
                             preprolated_duration=(1, denominator)))
         else:
             parts = [3]
             total = 3
             while total < factor:
                 if decrease_durations_monotonically:
                     parts.append(2)
                 else:
                     parts.insert(0, 2)
                 total += 2
             for part in parts:
                 grouping = rhythmtreetools.RhythmTreeContainer(
                     preprolated_duration=part * preprolated_duration)
                 if factors:
                     for _ in range(part):
                         child = rhythmtreetools.RhythmTreeContainer(
                             preprolated_duration=preprolated_duration)
                         grouping.append(child)
                         recurse(
                             child,
                             factors,
                             denominator,
                             decrease_durations_monotonically,
                         )
                 else:
                     for _ in range(part):
                         grouping.append(
                             rhythmtreetools.RhythmTreeLeaf(
                                 preprolated_duration=(1, denominator)))
                 node.append(grouping)
     else:
         node.extend([
             rhythmtreetools.RhythmTreeLeaf(
                 preprolated_duration=(1, denominator))
             for _ in range(node.preprolated_duration.numerator)
         ])