# Path: segeval/util/test.py
# class TestCase(unittest.TestCase):
# 
#     '''
#     A test case that supports performing assertAlmostEquals upon lists, tuples,
#     or dicts of values.
#     '''
# 
#     DECIMAL_PLACES = 4
# 
#     def assertEqualSet(self, first, second):
#         '''
#         Convert the arguments into a list of sets.
#         '''
#         return self.assertEqual([set(position) for position in first],
#                                 [set(position) for position in second])
# 
#     def assertAlmostEquals(self, first, second, places=DECIMAL_PLACES,
#                            msg=None):
#         '''
#         Automatically converts values to floats.
#         '''
# 
#         if isinstance(first, dict) and isinstance(second, dict):
#             for item in set(list(first.keys()) + list(second.keys())):
#                 if not msg:
#                     msg = '{0} != {1}'.format(first, second)
#                 if item not in first:
#                     raise Exception(
#                         '{0} not in {1}; expected {2}'.format(item, first,
#                                                               second))
#                 if item not in second:
#                     raise Exception(
#                         '{0} not in {1}; expected {2}'.format(item, second,
#                                                               first))
#                 self.assertAlmostEquals(first[item], second[item], places, msg)
#         elif (isinstance(first, list) or isinstance(first, tuple)) and \
#                 (isinstance(second, list) or isinstance(second, tuple)):
#             if len(first) != len(second):
#                 raise Exception(
#                     'Size mismatch; {0} != {1}'.format(first, second))
#             for item in zip(first, second):
#                 if not msg:
#                     msg = '{0} != {1}'.format(first, second)
#                 self.assertAlmostEquals(item[0], item[1], places, msg)
#         elif not isinstance(first, type(second)):
#             if not isinstance(first, float) and not isinstance(first, Decimal) and \
#                     not isinstance(second, float) and not isinstance(second, Decimal):
#                 raise Exception('Type mismatch; {0} != {1}'.format(
#                     type(first), type(second)))
#         else:
#             return unittest.TestCase.assertAlmostEquals(self,
#                                                         float(first),
#                                                         float(second),
#                                                         places=places,
#                                                         msg=msg)
# 
# Path: segeval/format.py
# def convert_positions_to_masses(positions):
#     '''
#     Convert an ordered sequence of boundary position labels into a
#     sequence of segment masses, e.g., ``[1,1,1,1,1,2,2,2,3,3,3,3,3]`` becomes
#     ``[5,3,5]``.
# 
#     :param segments: Ordered sequence of which segments a unit belongs to.
#     :type segments: tuple
# 
#     .. deprecated:: 1.0
#     '''
#     return tuple([len(list(group)) for _, group in groupby(positions)])
# 
# def convert_masses_to_positions(masses):
#     '''
#     Converts a sequence of segment masses into an ordered sequence of section
#     labels for each unit, e.g., ``[5,3,5]`` becomes
#     ``[1,1,1,1,1,2,2,2,3,3,3,3,3]``.
# 
#     :param masses: Segment mass sequence.
#     :type masses: tuple
#     '''
#     sequence = list()
#     for i, mass in enumerate(masses):
#         sequence.extend([i + 1] * mass)
#     return tuple(sequence)
# 
# def boundary_string_from_masses(masses):
#     '''
#     Creates a "boundary string", or sequence of boundary type sets from a list of segment masses, e.g., ``[5,3,5]`` becomes
#     ``[(),(),(),(),(1),(),(),(1),(),(),(),()]``.
# 
# 
#     :param masses: Segmentation masses.
#     :type masses: tuple
#     '''
#     string = [set() for _ in range(0, sum(masses) - 1)]
#     # Iterate over each position
#     pos = 0
#     for mass in masses:
#         cur_pos = pos + mass - 1
#         if cur_pos < len(string):
#             string[cur_pos].add(1)
#         pos += mass
#     # Return
#     return tuple([frozenset(pb) for pb in string])
# 
# def convert_nltk_to_masses(string, boundary_symbol='1'):
#     '''
#     Convert an `NLTK <http://nltk.org/>`_-formatted segmentation into masses, e.g., ``000001000100000`` becomes
#     ``[5,3,5]``.
# 
#     For more information, see `nltk.metrics.segmentation <http://nltk.org/api/nltk.metrics.html#module-nltk.metrics.segmentation>`_.
# 
#     :param string: NLTK-formatted segmentation.
#     :type string: str
#     :param boundary_symbol: String that represents a boundary.
#     :type boundary_symbol: str
#     '''
#     masses = [len(segment) + 1 for segment in string.split(boundary_symbol)]
#     return tuple(masses)


from segeval.util.test import TestCase
from segeval.format import (convert_positions_to_masses,
                            convert_masses_to_positions,
                            boundary_string_from_masses,
                            convert_nltk_to_masses)
        Test segment position sequence conversion from masses.
        '''
        self.assertEqual(convert_masses_to_positions([11]),
                         (1,1,1,1,1,1,1,1,1,1,1))

    def test_convert_masses_to_positions_all(self):
        '''
        Test segment position sequence conversion from masses.
        '''
        self.assertEqual(convert_masses_to_positions([1,1,1,1,1,1,1,1,1,1,1]),
                         (1,2,3,4,5,6,7,8,9,10,11))

    def test_boundary_string_from_masses_none(self):
        '''
        No boundaries.
        '''
        string = boundary_string_from_masses([3])
        self.assertEqual(string, (set(), set()))

    def test_boundary_string_from_masses_full(self):
        '''
        Few boundaries.
        '''
        string = boundary_string_from_masses([1,1,1,1])
        self.assertEqual(string, (set([1]), set([1]), set([1])))

    def test_boundary_string_from_masses_one(self):
        '''
        Few boundaries.
        '''

# Path: segeval/util/test.py
# class TestCase(unittest.TestCase):
# 
#     '''
#     A test case that supports performing assertAlmostEquals upon lists, tuples,
#     or dicts of values.
#     '''
# 
#     DECIMAL_PLACES = 4
# 
#     def assertEqualSet(self, first, second):
#         '''
#         Convert the arguments into a list of sets.
#         '''
#         return self.assertEqual([set(position) for position in first],
#                                 [set(position) for position in second])
# 
#     def assertAlmostEquals(self, first, second, places=DECIMAL_PLACES,
#                            msg=None):
#         '''
#         Automatically converts values to floats.
#         '''
# 
#         if isinstance(first, dict) and isinstance(second, dict):
#             for item in set(list(first.keys()) + list(second.keys())):
#                 if not msg:
#                     msg = '{0} != {1}'.format(first, second)
#                 if item not in first:
#                     raise Exception(
#                         '{0} not in {1}; expected {2}'.format(item, first,
#                                                               second))
#                 if item not in second:
#                     raise Exception(
#                         '{0} not in {1}; expected {2}'.format(item, second,
#                                                               first))
#                 self.assertAlmostEquals(first[item], second[item], places, msg)
#         elif (isinstance(first, list) or isinstance(first, tuple)) and \
#                 (isinstance(second, list) or isinstance(second, tuple)):
#             if len(first) != len(second):
#                 raise Exception(
#                     'Size mismatch; {0} != {1}'.format(first, second))
#             for item in zip(first, second):
#                 if not msg:
#                     msg = '{0} != {1}'.format(first, second)
#                 self.assertAlmostEquals(item[0], item[1], places, msg)
#         elif not isinstance(first, type(second)):
#             if not isinstance(first, float) and not isinstance(first, Decimal) and \
#                     not isinstance(second, float) and not isinstance(second, Decimal):
#                 raise Exception('Type mismatch; {0} != {1}'.format(
#                     type(first), type(second)))
#         else:
#             return unittest.TestCase.assertAlmostEquals(self,
#                                                         float(first),
#                                                         float(second),
#                                                         places=places,
#                                                         msg=msg)
# 
# Path: segeval/format.py
# def convert_positions_to_masses(positions):
#     '''
#     Convert an ordered sequence of boundary position labels into a
#     sequence of segment masses, e.g., ``[1,1,1,1,1,2,2,2,3,3,3,3,3]`` becomes
#     ``[5,3,5]``.
# 
#     :param segments: Ordered sequence of which segments a unit belongs to.
#     :type segments: tuple
# 
#     .. deprecated:: 1.0
#     '''
#     return tuple([len(list(group)) for _, group in groupby(positions)])
# 
# def convert_masses_to_positions(masses):
#     '''
#     Converts a sequence of segment masses into an ordered sequence of section
#     labels for each unit, e.g., ``[5,3,5]`` becomes
#     ``[1,1,1,1,1,2,2,2,3,3,3,3,3]``.
# 
#     :param masses: Segment mass sequence.
#     :type masses: tuple
#     '''
#     sequence = list()
#     for i, mass in enumerate(masses):
#         sequence.extend([i + 1] * mass)
#     return tuple(sequence)
# 
# def boundary_string_from_masses(masses):
#     '''
#     Creates a "boundary string", or sequence of boundary type sets from a list of segment masses, e.g., ``[5,3,5]`` becomes
#     ``[(),(),(),(),(1),(),(),(1),(),(),(),()]``.
# 
# 
#     :param masses: Segmentation masses.
#     :type masses: tuple
#     '''
#     string = [set() for _ in range(0, sum(masses) - 1)]
#     # Iterate over each position
#     pos = 0
#     for mass in masses:
#         cur_pos = pos + mass - 1
#         if cur_pos < len(string):
#             string[cur_pos].add(1)
#         pos += mass
#     # Return
#     return tuple([frozenset(pb) for pb in string])
# 
# def convert_nltk_to_masses(string, boundary_symbol='1'):
#     '''
#     Convert an `NLTK <http://nltk.org/>`_-formatted segmentation into masses, e.g., ``000001000100000`` becomes
#     ``[5,3,5]``.
# 
#     For more information, see `nltk.metrics.segmentation <http://nltk.org/api/nltk.metrics.html#module-nltk.metrics.segmentation>`_.
# 
#     :param string: NLTK-formatted segmentation.
#     :type string: str
#     :param boundary_symbol: String that represents a boundary.
#     :type boundary_symbol: str
#     '''
#     masses = [len(segment) + 1 for segment in string.split(boundary_symbol)]
#     return tuple(masses)


# Path: segeval/format_test.py
from segeval.util.test import TestCase
from segeval.format import (convert_positions_to_masses,
                            convert_masses_to_positions,
                            boundary_string_from_masses,
                            convert_nltk_to_masses)

        Test segment position sequence conversion from masses.
        '''
        self.assertEqual(convert_masses_to_positions([11]),
                         (1,1,1,1,1,1,1,1,1,1,1))

    def test_convert_masses_to_positions_all(self):
        '''
        Test segment position sequence conversion from masses.
        '''
        self.assertEqual(convert_masses_to_positions([1,1,1,1,1,1,1,1,1,1,1]),
                         (1,2,3,4,5,6,7,8,9,10,11))

    def test_boundary_string_from_masses_none(self):
        '''
        No boundaries.
        '''
        string = boundary_string_from_masses([3])
        self.assertEqual(string, (set(), set()))

    def test_boundary_string_from_masses_full(self):
        '''
        Few boundaries.
        '''
        string = boundary_string_from_masses([1,1,1,1])
        self.assertEqual(string, (set([1]), set([1]), set([1])))

    def test_boundary_string_from_masses_one(self):
        '''
        Few boundaries.
        '''

        string = boundary_string_from_masses([2,3])