# Path: segeval/similarity/distance/multipleboundary.py
# def boundary_edit_distance(boundary_string_a, boundary_string_b, n_t=2):
#     '''
#     Computes boundary edit distance between two boundary strings.  Returns a \
#     list of Addition, Substitution, and Transposition edit sets.
# 
#     :param boundary_string_a: Boundary string to compare; produced by :func:`boundary_string_from_masses`
#     :param boundary_string_b: See `boundary_string_a`
#     :param n_t: Maximum distance (in potential boundary positions) that a \
#         transposition may span
# 
#     :type boundary_string_a:  tuple
#     :type boundary_string_b:  tuple
#     :type n_t:  int
#     '''
# 
#     n_t = range(2, n_t + 1)
#     return __boundary_edit_distance__(boundary_string_a, boundary_string_b, n_t)
# 
# def __additions_substitutions__(d, a, b):
#     '''
#     Compute the number of additions and substitutions for a given pair of
#     boundary string positions using:
# 
#     :param d: Symmetric difference between the pair.
#     :param a: Difference between the pair; A / B.
#     :param b: Difference between the pair; B / A.
#     :type d: set
#     :type a: set
#     :type b: set
#     '''
# 
#     additions = abs(len(a) - len(b))
#     substitutions = (len(d) - additions) / 2
#     return additions, substitutions
# 
# def __additions_substitutions_sets__(d, a, b):
#     '''
#     Compute the sets of additions and substitutions for a given pair of
#     boundary string positions using:
# 
#     :param d: Symmetric difference between the pair.
#     :param a: Difference between the pair; A / B.
#     :param b: Difference between the pair; B / A.
#     :type d: set
#     :type a: set
#     :type b: set
#     '''
# 
#     substitutions = list()
#     delta = None
#     for perm_a in permutations(sorted(a)):
#         for perm_b in permutations(sorted(b)):
#             current_substitutions = zip(perm_a, perm_b)
#             current_substitutions = set(current_substitutions)
#             current_delta = sum(abs(a_i - b_i)
#                                 for a_i, b_i in current_substitutions)
#             if delta is None or current_delta < delta:
#                 delta = current_delta
#                 substitutions = current_substitutions
#     # Collect all substitutions
#     substituted = list()
#     added = list()
#     for a_i, b_i in substitutions:
#         substituted.append(a_i)
#         substituted.append(b_i)
#     additions = d - set(substituted)
#     # Add from a
#     for addition in a - set(substituted):
#         added.append(Addition(addition, 'a'))
#     # Add from b
#     for addition in b - set(substituted):
#         added.append(Addition(addition, 'b'))
#     assert len(added) is len(additions)
#     return added, set([Substitution(a_i, b_i) for a_i, b_i in set(substitutions)])
# 
# def __has_substitutions__(i, j, d, options_set):
#     '''
#     Determine whether two substitutions are present involving the boundary 'd'
#     at the positions 'i' and 'j'.
#     '''
# 
#     present = False
#     if i in options_set and d in options_set[i][0] and j in options_set and d in options_set[j][0]:
#         d_i, a_i, b_i = options_set[i]
#         d_j, a_j, b_j = options_set[j]
#         if __additions_substitutions__(d_i, a_i, b_i)[1] > 0 and \
#            __additions_substitutions__(d_j, a_j, b_j)[1] > 0:
#             present = True
#     return present


import unittest
from segeval.similarity.distance.multipleboundary import (
    boundary_edit_distance, __additions_substitutions__,
    __additions_substitutions_sets__, __has_substitutions__)

.. moduleauthor:: Chris Fournier <chris.m.fournier@gmail.com>
'''
from __future__ import absolute_import


class TestMultipleBoundaries(unittest.TestCase):

    '''
    Test multiple boundary edit distance.
    '''

    def test_edit_distance_identity(self):
        '''
        Test a mixed example of additions, substitutions and transpositions.
        '''
        a = [set(), set([1]), set(), set(), set([1]), set(), set(), set(), set(), set()]
        b = a

        additions, substitutions, transpositions = boundary_edit_distance(a, b)
        self.assertEqual(([], [], []),
                         (additions, substitutions, transpositions))

    def test_edit_distance_compliment(self):
        '''
        Test a mixed example of additions, substitutions and transpositions.
        '''
        a = [set(), set(), set(), set(), set(), set(), set(), set(), set(), set()]
        b = [set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1])]


# Path: segeval/similarity/distance/multipleboundary.py
# def boundary_edit_distance(boundary_string_a, boundary_string_b, n_t=2):
#     '''
#     Computes boundary edit distance between two boundary strings.  Returns a \
#     list of Addition, Substitution, and Transposition edit sets.
# 
#     :param boundary_string_a: Boundary string to compare; produced by :func:`boundary_string_from_masses`
#     :param boundary_string_b: See `boundary_string_a`
#     :param n_t: Maximum distance (in potential boundary positions) that a \
#         transposition may span
# 
#     :type boundary_string_a:  tuple
#     :type boundary_string_b:  tuple
#     :type n_t:  int
#     '''
# 
#     n_t = range(2, n_t + 1)
#     return __boundary_edit_distance__(boundary_string_a, boundary_string_b, n_t)
# 
# def __additions_substitutions__(d, a, b):
#     '''
#     Compute the number of additions and substitutions for a given pair of
#     boundary string positions using:
# 
#     :param d: Symmetric difference between the pair.
#     :param a: Difference between the pair; A / B.
#     :param b: Difference between the pair; B / A.
#     :type d: set
#     :type a: set
#     :type b: set
#     '''
# 
#     additions = abs(len(a) - len(b))
#     substitutions = (len(d) - additions) / 2
#     return additions, substitutions
# 
# def __additions_substitutions_sets__(d, a, b):
#     '''
#     Compute the sets of additions and substitutions for a given pair of
#     boundary string positions using:
# 
#     :param d: Symmetric difference between the pair.
#     :param a: Difference between the pair; A / B.
#     :param b: Difference between the pair; B / A.
#     :type d: set
#     :type a: set
#     :type b: set
#     '''
# 
#     substitutions = list()
#     delta = None
#     for perm_a in permutations(sorted(a)):
#         for perm_b in permutations(sorted(b)):
#             current_substitutions = zip(perm_a, perm_b)
#             current_substitutions = set(current_substitutions)
#             current_delta = sum(abs(a_i - b_i)
#                                 for a_i, b_i in current_substitutions)
#             if delta is None or current_delta < delta:
#                 delta = current_delta
#                 substitutions = current_substitutions
#     # Collect all substitutions
#     substituted = list()
#     added = list()
#     for a_i, b_i in substitutions:
#         substituted.append(a_i)
#         substituted.append(b_i)
#     additions = d - set(substituted)
#     # Add from a
#     for addition in a - set(substituted):
#         added.append(Addition(addition, 'a'))
#     # Add from b
#     for addition in b - set(substituted):
#         added.append(Addition(addition, 'b'))
#     assert len(added) is len(additions)
#     return added, set([Substitution(a_i, b_i) for a_i, b_i in set(substitutions)])
# 
# def __has_substitutions__(i, j, d, options_set):
#     '''
#     Determine whether two substitutions are present involving the boundary 'd'
#     at the positions 'i' and 'j'.
#     '''
# 
#     present = False
#     if i in options_set and d in options_set[i][0] and j in options_set and d in options_set[j][0]:
#         d_i, a_i, b_i = options_set[i]
#         d_j, a_j, b_j = options_set[j]
#         if __additions_substitutions__(d_i, a_i, b_i)[1] > 0 and \
#            __additions_substitutions__(d_j, a_j, b_j)[1] > 0:
#             present = True
#     return present


# Path: segeval/similarity/distance/multipleboundary_test.py
import unittest
from segeval.similarity.distance.multipleboundary import (
    boundary_edit_distance, __additions_substitutions__,
    __additions_substitutions_sets__, __has_substitutions__)


.. moduleauthor:: Chris Fournier <chris.m.fournier@gmail.com>
'''
from __future__ import absolute_import


class TestMultipleBoundaries(unittest.TestCase):

    '''
    Test multiple boundary edit distance.
    '''

    def test_edit_distance_identity(self):
        '''
        Test a mixed example of additions, substitutions and transpositions.
        '''
        a = [set(), set([1]), set(), set(), set([1]), set(), set(), set(), set(), set()]
        b = a

        additions, substitutions, transpositions = boundary_edit_distance(a, b)
        self.assertEqual(([], [], []),
                         (additions, substitutions, transpositions))

    def test_edit_distance_compliment(self):
        '''
        Test a mixed example of additions, substitutions and transpositions.
        '''
        a = [set(), set(), set(), set(), set(), set(), set(), set(), set(), set()]
        b = [set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1]), set([1])]


        additions, substitutions, transpositions = boundary_edit_distance(a, b)