Example #1
0
 def get_children_of_item(self, item, generations=1):
     '''
     Get all the child items of `item`.
     
     If `generations` is `1`, the children will be returned; if it's `2`,
     the grand-children will be returned, etc.
     '''
     if generations == 0:
         return tuple(item)
     
     (first_child, cookie) = self.GetFirstChild(item)
     children = []
     
     current_child = first_child
     while current_child.IsOk():
         children.append(current_child)
         (current_child, cookie) = self.GetNextChild(item, cookie)
     
     if generations == 1:
         return tuple(children)
     else:
         return tuple(
             sequence_tools.flatten(
                 self.get_children_of_item(
                     child,
                     generations=generations-1
                 ) for child in children
             )
         )
 def assert_correct_members(partitions):
     '''
     Assert that the `partitions` contain exactly all of `r`'s members.
     '''
     members = sequence_tools.flatten(partitions)
     assert len(members) == len(r)
     assert set(members) == set(r)
 def assert_correct_members(partitions):
     '''
     Assert that the `partitions` contain exactly all of `r`'s members.
     '''
     members = sequence_tools.flatten(partitions)
     assert len(members) == len(r)
     assert set(members) == set(r)
Example #4
0
def test():
    '''Test the basic workings of `sequence_tools.flatten`.'''
    assert flatten([]) == flatten(()) == []
    assert flatten([[1], [2], [3]]) == flatten(([1], [2], [3])) == [1, 2, 3]
    assert flatten(((1,), (2,), (3,))) == flatten([(1,), (2,), (3,)]) == \
           (1, 2, 3)
def test_all_sizes():
    '''Test using `n=None` so combinations of all sizes are returned.'''
    assert list(combinations(xrange(4))) == sequence_tools.flatten(
        list(combinations(xrange(4), i)) for i in xrange(1, 4+1)
    )
Example #6
0
def test():
    '''Test the basic workings of `sequence_tools.flatten`.'''
    assert flatten([]) == flatten(()) == []
    assert flatten([[1], [2], [3]]) == flatten(([1], [2], [3])) == [1, 2, 3]
    assert flatten(((1,), (2,), (3,))) == flatten([(1,), (2,), (3,)]) == \
           (1, 2, 3)
Example #7
0
def test_all_sizes():
    '''Test using `n=None` so combinations of all sizes are returned.'''
    assert list(combinations(xrange(4))) == sequence_tools.flatten(
        list(combinations(xrange(4), i)) for i in xrange(1, 4 + 1))