|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
|
|
from nemo.collections.common.parts.utils import flatten |
|
|
|
|
|
|
|
|
class TestListUtils: |
|
|
@pytest.mark.unit |
|
|
def test_flatten(self): |
|
|
"""Test flattening an iterable with different values: str, bool, int, float, complex. |
|
|
""" |
|
|
test_cases = [] |
|
|
test_cases.append({'input': ['aa', 'bb', 'cc'], 'golden': ['aa', 'bb', 'cc']}) |
|
|
test_cases.append({'input': ['aa', ['bb', 'cc']], 'golden': ['aa', 'bb', 'cc']}) |
|
|
test_cases.append({'input': ['aa', [['bb'], [['cc']]]], 'golden': ['aa', 'bb', 'cc']}) |
|
|
test_cases.append({'input': ['aa', [[1, 2], [[3]], 4]], 'golden': ['aa', 1, 2, 3, 4]}) |
|
|
test_cases.append({'input': [True, [2.5, 2.0 + 1j]], 'golden': [True, 2.5, 2.0 + 1j]}) |
|
|
|
|
|
for n, test_case in enumerate(test_cases): |
|
|
assert flatten(test_case['input']) == test_case['golden'], f'Test case {n} failed!' |
|
|
|