Exemple #1
0
def test_mathtools_next_integer_partition_01():

    assert mathtools.next_integer_partition((8, )) == (7, 1)
    assert mathtools.next_integer_partition((7, 1)) == (6, 2)
    assert mathtools.next_integer_partition((6, 2)) == (6, 1, 1)
    assert mathtools.next_integer_partition((6, 1, 1)) == (5, 3)
    assert mathtools.next_integer_partition((5, 3)) == (5, 2, 1)
    assert mathtools.next_integer_partition((5, 2, 1)) == (5, 1, 1, 1)
    assert mathtools.next_integer_partition((5, 1, 1, 1)) == (4, 4)
    assert mathtools.next_integer_partition((4, 4)) == (4, 3, 1)
Exemple #2
0
def test_mathtools_next_integer_partition_02():

    assert mathtools.next_integer_partition((4, 3, 1)) == (4, 2, 2)
    assert mathtools.next_integer_partition((4, 2, 2)) == (4, 2, 1, 1)
    assert mathtools.next_integer_partition((4, 2, 1, 1)) == (4, 1, 1, 1, 1)
    assert mathtools.next_integer_partition((4, 1, 1, 1, 1)) == (3, 3, 2)
    assert mathtools.next_integer_partition((3, 3, 2)) == (3, 3, 1, 1)
    assert mathtools.next_integer_partition((3, 3, 1, 1)) == (3, 2, 2, 1)
    assert mathtools.next_integer_partition((3, 2, 2, 1)) == (3, 2, 1, 1, 1)
Exemple #3
0
def yield_all_partitions_of_integer(n):
    r'''Yields all partitions of positive integer `n` in descending lex order:

    ::

        >>> for partition in mathtools.yield_all_partitions_of_integer(7):
        ...     partition
        ...
        (7,)
        (6, 1)
        (5, 2)
        (5, 1, 1)
        (4, 3)
        (4, 2, 1)
        (4, 1, 1, 1)
        (3, 3, 1)
        (3, 2, 2)
        (3, 2, 1, 1)
        (3, 1, 1, 1, 1)
        (2, 2, 2, 1)
        (2, 2, 1, 1, 1)
        (2, 1, 1, 1, 1, 1)
        (1, 1, 1, 1, 1, 1, 1)

    Returns generator of positive integer tuples of length at least ``1``.
    '''
    from abjad.tools import mathtools

    if not isinstance(n, int):
        message = 'must be integer.'
        raise TypeError(message)
    if not 0 < n:
        message = 'must be positive.'
        raise ValueError(message)

    partition = (n, )
    while partition is not None:
        yield partition
        partition = mathtools.next_integer_partition(partition)