# Path: diplomacy/engine/digest.py
# def find_convoys(units, fleets):
#     """
#     Generates pairs consisting of a cluster of adjacent non-coastal
#     fleets, and the coastal territories that are reachable via convoy
#     from that cluster.  This is necessary to determine legal orders.
# 
#     """
#     fleets = [f for f in fleets if not has_land(f)]
#     index = {f: {f} for f in fleets}
# 
#     # Calculate the connected sets of fleets
#     for f1, f2 in combinations(fleets, 2):
#         # If this pair is not adjacent, ignore it
#         if f2 not in borders(f1):
#             continue
# 
#         # If the sets for each of these fleets are not already the same set,
#         # merge them and update the index
#         if index[f1] != index[f2]:
#             index[f1] |= index[f2]
#             index.update((x, index[f1]) for x in index[f2])
# 
#     groups = {frozenset(S) for S in index.values()}
# 
#     armies = {u['subregion'] for u in units if u['u_type'] == 'A'}
# 
#     convoyable = []
#     for gset in groups:
#         coasts = {
#             sr for f in gset
#             for b in borders(f)
#             for sr in territory_parts(get_territory(b))
#             if is_land(sr)
#         }
#         if coasts & armies:
#             convoyable.append((set(gset), coasts))
# 
#     return convoyable
# 
# Path: diplomacy/engine/utils.py
# def get_territory(sr_token):
#     if not sr_token:
#         return u''
#     return sr_token.split(u'.')[0]
# 
# def territory_display(t_token):
#     return standard.territories.get(t_token, u'')
# 
# def unit_display(sr_token):
#     if sr_token not in standard.subregions:
#         return u''
#     T, subname, sr_type = standard.subregions[sr_token]
#     base = u"{} {}".format(convert[sr_type], T)
#     return u"{} ({})".format(base, subname) if subname else base
# 
# def subregion_token(sr_tuple):
#     return standard.inv_subregions.get(sr_tuple, u'')
# 
# def power_token(p_str):
#     return standard.inv_powers.get(p_str, u'')


import re
from django.test import TestCase
from django.utils import six
from ..engine.digest import find_convoys
from ..engine.utils import (get_territory, territory_display, unit_display, subregion_token,
                            power_token)
                             'F Baltic Sea',
                             'F Gulf of Bothnia',
                             'A Gascony',
                             'A Sweden')}

        parsed = self.parse_units(units)
        fleets = [u['subregion'] for u in parsed if u['u_type'] == 'F']
        legal = find_convoys(parsed, fleets)

        self.assertEqual(len(legal), 2)
        (seas1, lands1), (seas2, lands2) = legal
        if len(seas1) == 2:
            seas1, seas2 = seas2, seas1
            lands1, lands2 = lands2, lands1

        self.assertEqual(len(seas1), 3)
        self.assertCountEqual(
            [unit_display(sr) for sr in seas1],
            units['England'][:3]
        )

        self.assertEqual(len(lands1), 10)
        self.assertCountEqual(
            [territory_display(get_territory(sr)) for sr in lands1],
            ['Tunisia', 'North Africa', 'London', 'Wales', 'Spain',
             'Brest', 'Gascony', 'Picardy', 'Belgium', 'Portugal']
        )

        self.assertEqual(len(seas2), 2)
        self.assertCountEqual(

# Path: diplomacy/engine/digest.py
# def find_convoys(units, fleets):
#     """
#     Generates pairs consisting of a cluster of adjacent non-coastal
#     fleets, and the coastal territories that are reachable via convoy
#     from that cluster.  This is necessary to determine legal orders.
# 
#     """
#     fleets = [f for f in fleets if not has_land(f)]
#     index = {f: {f} for f in fleets}
# 
#     # Calculate the connected sets of fleets
#     for f1, f2 in combinations(fleets, 2):
#         # If this pair is not adjacent, ignore it
#         if f2 not in borders(f1):
#             continue
# 
#         # If the sets for each of these fleets are not already the same set,
#         # merge them and update the index
#         if index[f1] != index[f2]:
#             index[f1] |= index[f2]
#             index.update((x, index[f1]) for x in index[f2])
# 
#     groups = {frozenset(S) for S in index.values()}
# 
#     armies = {u['subregion'] for u in units if u['u_type'] == 'A'}
# 
#     convoyable = []
#     for gset in groups:
#         coasts = {
#             sr for f in gset
#             for b in borders(f)
#             for sr in territory_parts(get_territory(b))
#             if is_land(sr)
#         }
#         if coasts & armies:
#             convoyable.append((set(gset), coasts))
# 
#     return convoyable
# 
# Path: diplomacy/engine/utils.py
# def get_territory(sr_token):
#     if not sr_token:
#         return u''
#     return sr_token.split(u'.')[0]
# 
# def territory_display(t_token):
#     return standard.territories.get(t_token, u'')
# 
# def unit_display(sr_token):
#     if sr_token not in standard.subregions:
#         return u''
#     T, subname, sr_type = standard.subregions[sr_token]
#     base = u"{} {}".format(convert[sr_type], T)
#     return u"{} ({})".format(base, subname) if subname else base
# 
# def subregion_token(sr_tuple):
#     return standard.inv_subregions.get(sr_tuple, u'')
# 
# def power_token(p_str):
#     return standard.inv_powers.get(p_str, u'')


# Path: diplomacy/tests/test_local.py
import re
from django.test import TestCase
from django.utils import six
from ..engine.digest import find_convoys
from ..engine.utils import (get_territory, territory_display, unit_display, subregion_token,
                            power_token)

                             'F Baltic Sea',
                             'F Gulf of Bothnia',
                             'A Gascony',
                             'A Sweden')}

        parsed = self.parse_units(units)
        fleets = [u['subregion'] for u in parsed if u['u_type'] == 'F']
        legal = find_convoys(parsed, fleets)

        self.assertEqual(len(legal), 2)
        (seas1, lands1), (seas2, lands2) = legal
        if len(seas1) == 2:
            seas1, seas2 = seas2, seas1
            lands1, lands2 = lands2, lands1

        self.assertEqual(len(seas1), 3)
        self.assertCountEqual(
            [unit_display(sr) for sr in seas1],
            units['England'][:3]
        )

        self.assertEqual(len(lands1), 10)
        self.assertCountEqual(
            [territory_display(get_territory(sr)) for sr in lands1],
            ['Tunisia', 'North Africa', 'London', 'Wales', 'Spain',
             'Brest', 'Gascony', 'Picardy', 'Belgium', 'Portugal']
        )

        self.assertEqual(len(seas2), 2)
        self.assertCountEqual(

            [unit_display(sr) for sr in seas2],