# Path: tde/util/functions.py
# def unique(iterable):
#     seen = set()
#     seen_add = seen.add
#     for element in iterable:
#         if element in seen:
#             continue
#         seen_add(element)
#         yield element
# 
# def intersection(iterable1, iterable2):
#     set1 = set(iterable1)
#     seen = set()
#     seen_add = seen.add
#     for element in iterable2:
#         if element in seen:
#             continue
#         seen_add(element)
#         if element in set1:
#             yield element
# 
# def fname2speaker(corpus_type):
#     if corpus_type == 'buckeye':
#         return lambda x: path.splitext(path.basename(x))[0][:3]
#     elif corpus_type == 'xitsonga':
#         return lambda x: path.splitext(path.basename(x))[0].split('_')[2]
#     else:
#         raise NotImplementedError('no implementation of fname2speaker for {0}'
#                                   .format(corpus_type))


import pytest
from tde.util.functions import unique, intersection, fname2speaker


@pytest.mark.randomize(it=pytest.list_of(str))
def test_unique(it):
    assert (sorted(list(unique(it))) == sorted(list(set(it))))

def test_intersection():
    it1 = range(20)
    it2 = range(10, 30)
    assert (sorted(list(intersection(it1, it2))) ==
            sorted(list(set(it1) & set(it2))))

def test_fname2speaker():
    t = 'buckeye'
    assert (fname2speaker(t)('s2801a_1923810923') == 's28')
    with pytest.raises(NotImplementedError):

# Path: tde/util/functions.py
# def unique(iterable):
#     seen = set()
#     seen_add = seen.add
#     for element in iterable:
#         if element in seen:
#             continue
#         seen_add(element)
#         yield element
# 
# def intersection(iterable1, iterable2):
#     set1 = set(iterable1)
#     seen = set()
#     seen_add = seen.add
#     for element in iterable2:
#         if element in seen:
#             continue
#         seen_add(element)
#         if element in set1:
#             yield element
# 
# def fname2speaker(corpus_type):
#     if corpus_type == 'buckeye':
#         return lambda x: path.splitext(path.basename(x))[0][:3]
#     elif corpus_type == 'xitsonga':
#         return lambda x: path.splitext(path.basename(x))[0].split('_')[2]
#     else:
#         raise NotImplementedError('no implementation of fname2speaker for {0}'
#                                   .format(corpus_type))


# Path: tests/test_util_functions.py
import pytest
from tde.util.functions import unique, intersection, fname2speaker



@pytest.mark.randomize(it=pytest.list_of(str))
def test_unique(it):
    assert (sorted(list(unique(it))) == sorted(list(set(it))))

def test_intersection():
    it1 = range(20)
    it2 = range(10, 30)
    assert (sorted(list(intersection(it1, it2))) ==
            sorted(list(set(it1) & set(it2))))

def test_fname2speaker():
    t = 'buckeye'
    assert (fname2speaker(t)('s2801a_1923810923') == 's28')
    with pytest.raises(NotImplementedError):

        fname2speaker('somethingelse')