





import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs




@pytest.mark.parametrize(
    '''kwargs, expected''' ,    [
        ({'''num_shards''': 0, '''max_num_jobs''': 1}, []),
        ({'''num_shards''': 10, '''max_num_jobs''': 1}, [range(10      )]),
        ({'''num_shards''': 10, '''max_num_jobs''': 10}, [range(__A ,    i + 1      ) for i in range(10      )]),
        ({'''num_shards''': 1, '''max_num_jobs''': 10}, [range(1      )]),
        ({'''num_shards''': 10, '''max_num_jobs''': 3}, [range(0 ,    4      ), range(4 ,    7      ), range(7 ,    10      )]),
        ({'''num_shards''': 3, '''max_num_jobs''': 10}, [range(0 ,    1      ), range(1 ,    2      ), range(2 ,    3      )]),
    ] ,    )
def    __UpperCAmelCase(      lowercase_ ,    lowercase_      ):
       _lowerCamelCase							:     int	=		_distribute_shards(**__A      )
       assert out == expected




@pytest.mark.parametrize(
    '''gen_kwargs, max_num_jobs, expected''' ,    [
        ({'''foo''': 0}, 10, [{'''foo''': 0}]),
        ({'''shards''': [0, 1, 2, 3]}, 1, [{'''shards''': [0, 1, 2, 3]}]),
        ({'''shards''': [0, 1, 2, 3]}, 4, [{'''shards''': [0]}, {'''shards''': [1]}, {'''shards''': [2]}, {'''shards''': [3]}]),
        ({'''shards''': [0, 1]}, 4, [{'''shards''': [0]}, {'''shards''': [1]}]),
        ({'''shards''': [0, 1, 2, 3]}, 2, [{'''shards''': [0, 1]}, {'''shards''': [2, 3]}]),
    ] ,    )
def    __UpperCAmelCase(      lowercase_ ,    lowercase_ ,    lowercase_      ):
       _lowerCamelCase							:     Dict	=		_split_gen_kwargs(__A ,    __A      )
       assert out == expected





@pytest.mark.parametrize(
    '''gen_kwargs, expected''' ,    [
        ({'''foo''': 0}, 1),
        ({'''shards''': [0]}, 1),
        ({'''shards''': [0, 1, 2, 3]}, 4),
        ({'''shards''': [0, 1, 2, 3], '''foo''': 0}, 4),
        ({'''shards''': [0, 1, 2, 3], '''other''': (0, 1)}, 4),
        ({'''shards''': [0, 1, 2, 3], '''shards2''': [0, 1]}, RuntimeError),
    ] ,    )
def    __UpperCAmelCase(      lowercase_ ,    lowercase_      ):




       if expected is RuntimeError:
              with pytest.raises(__A      ):
                     _number_of_shards_in_gen_kwargs(__A      )
       else:
              _lowerCamelCase							:     int	=		_number_of_shards_in_gen_kwargs(__A      )
              assert out == expected








_lowerCamelCase			       =      [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
_lowerCamelCase			       =      [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
_lowerCamelCase			       =      {
    0: 'Sunday',
    1: 'Monday',
    2: 'Tuesday',
    3: 'Wednesday',
    4: 'Thursday',
    5: 'Friday',
    6: 'Saturday',
}




def    __UpperCAmelCase(      lowercase_ ,    lowercase_ ,    lowercase_      ):
       assert len(str(lowercase_      )      ) > 2, "year should be in YYYY format"
       assert 1 <= month <= 12, "month should be between 1 to 12"
       assert 1 <= day <= 31, "day should be between 1 to 31"

       # Doomsday algorithm:
       _lowerCamelCase							:     List[Any]	=		year // 1_00
       _lowerCamelCase							:     Dict	=		(5 * (century % 4) + 2) % 7
       _lowerCamelCase							:     Tuple	=		year % 1_00
       _lowerCamelCase							:     int	=		centurian % 12
       _lowerCamelCase							:     List[Any]	=		(
           (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
       ) % 7
       _lowerCamelCase							:     List[Any]	=		(
           DOOMSDAY_NOT_LEAP[month - 1]
           if (year % 4 != 0) or (centurian == 0 and (year % 4_00) == 0)
           else DOOMSDAY_LEAP[month - 1]
       )
       _lowerCamelCase							:     Any	=		(dooms_day + day - day_anchor) % 7
       return WEEK_DAY_NAMES[week_day]


if __name__ == "__main__":
       import doctest

       doctest.testmod()

