# -*- coding: utf-8 -*-

import math

import pydash as _

from . import fixtures
from .fixtures import parametrize


@parametrize('case,expected', [
    ((['a', 'b', 'c', 'd', 'e'], [0, 2, 4]), ['a', 'c', 'e']),
    ((['moe', 'larry', 'curly'], 0, 2), ['moe', 'curly']),
    (({'a': 1, 'b': 2, 'c': 3}, 'a', 'b'), [1, 2])
])
def test_at(case, expected):
    assert _.at(*case) == expected


@parametrize('case,expected', [
    (([1, 2, 3], 1), True),
    (([1, 2, 3], 1, 2), False),
    (({'name': 'fred', 'age': 40}, 'fred'), True),
    (('pebbles', 'eb'), True)
])
def test_contains(case, expected):
    assert _.contains(*case) == expected


@parametrize('case', [
    _.include
])
def test_contains_aliases(case):
    assert _.contains is case


@parametrize('case,expected', [
    (([4.3, 6.1, 6.4], lambda num: int(math.floor(num))), {4: 1, 6: 2}),
    (([{'one': 1}, {'one': 1}, {'two': 2}, {'one': 1}], {'one': 1}),
     {True: 3, False: 1}),
    (([{'one': 1}, {'one': 1}, {'two': 2}, {'one': 1}], 'one'),
     {1: 3, None: 1}),
    (({1: 0, 2: 0, 4: 3},), {0: 2, 3: 1})
])
def test_count_by(case, expected):
    assert _.count_by(*case) == expected


@parametrize('case,expected', [
    (([{'level1': {'level2': {'level3': {'value': 1}}}},
       {'level1': {'level2': {'level3': {'value': 2}}}},
       {'level1': {'level2': {'level3': {'value': 3}}}},
       {'level1': {'level2': {'level3': {'value': 4}}}},
       {'level1': {'level2': {}}},
        {}],
      'level1.level2.level3.value'),
     [1, 2, 3, 4, None, None])
])
def test_deep_pluck(case, expected):
    assert _.deep_pluck(*case) == expected


@parametrize('case,expected', [
    (([0, True, False, None, 1, 2, 3],), [True, 1, 2, 3]),