

import logging
import sys
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Union

import librosa
import torch
from datasets import DatasetDict, load_dataset
from packaging import version
from torch import nn

from transformers import (
    HfArgumentParser,
    Trainer,
    TrainingArguments,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaForPreTraining,
    is_apex_available,
    trainer_utils,
)
from transformers.models.wavaveca.modeling_wavaveca import _compute_mask_indices


if is_apex_available():
     from apex import amp

if version.parse(version.parse(torch.__version__).base_version) >= version.parse('1.6'):
     _lowerCAmelCase			:						str  					=     True
     from torch.cuda.amp import autocast


_lowerCAmelCase			:						List[str]  					=     logging.getLogger(__name__)


@dataclass
class      lowerCAmelCase					:


       '''simple docstring'''







       snake_case     				=						field(
           metadata={'help': 'Path to pretrained model or model identifier from huggingface.co/models'}					)
       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'Where do you want to store the pretrained models downloaded from huggingface.co'} ,					)
       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'Whether to freeze the feature extractor layers of the model.'}					)
       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'Whether to log verbose messages or not.'} ,					)
       snake_case     				=						field(
           default=2.0 ,					metadata={'help': 'Maximum temperature for gumbel softmax.'}					)
       snake_case     				=						field(
           default=0.5 ,					metadata={'help': 'Minimum temperature for gumbel softmax.'}					)
       snake_case     				=						field(
           default=0.9_9_9_9_9_5 ,					metadata={'help': 'Decay of gumbel temperature during training.'}					)







def a_		(							UpperCamelCase_ :				ModelArguments ,       UpperCamelCase_ :				TrainingArguments	)				-> int:







 """simple docstring"""

 logging.basicConfig(
     format='%(asctime)s - %(levelname)s - %(name)s - %(message)s' ,       datefmt='%m/%d/%Y %H:%M:%S' ,       handlers=[logging.StreamHandler(sys.stdout	)] ,       )
 lowerCamelCase       =     logging.WARNING
 if model_args.verbose_logging:
  lowerCamelCase       =     logging.DEBUG
 elif trainer_utils.is_main_process(training_args.local_rank	):
  lowerCamelCase       =     logging.INFO
 logger.setLevel(UpperCAmelCase__	)


@dataclass
class      lowerCAmelCase					:


       '''simple docstring'''







       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'The name of the dataset to use (via the datasets library).'}					)
       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'The configuration name of the dataset to use (via the datasets library).'}					)
       snake_case     				=						field(
           default='train' ,					metadata={
               'help': 'The name of the training data set split to use (via the datasets library). Defaults to \'train\''
           } ,					)
       snake_case     				=						field(
           default='validation' ,					metadata={
               'help': (
                   'The name of the validation data set split to use (via the datasets library). Defaults to \'validation\''
               )
           } ,					)
       snake_case     				=						field(
           default='file' ,					metadata={'help': 'Column in the dataset that contains speech file path. Defaults to \'file\''} ,					)
       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'Overwrite the cached preprocessed datasets or not.'}					)
       snake_case     				=						field(
           default=1 ,					metadata={
               'help': 'The percentage of the train set used as validation set in case there\'s no validation split'
           } ,					)
       snake_case     				=						field(
           default=__UpperCamelCase ,					metadata={'help': 'The number of processes to use for the preprocessing.'} ,					)
       snake_case     				=						field(
           default=2_0.0 ,					metadata={'help': 'Filter audio files that are longer than `max_duration_in_seconds` seconds'}					)


@dataclass
class      lowerCAmelCase					:


       '''simple docstring'''







       snake_case     				=						42
       snake_case     				=						42
       snake_case     				=						'longest'
       snake_case     				=						None
       snake_case     				=						None

       def __call__(						self       :	Union[str, Any]    ,						__snake_case       :	List[Dict[str, Union[List[int], torch.Tensor]]]  ) ->			Optional[int]:







        '''simple docstring'''

        lowerCamelCase       =     self.feature_extractor.pad(
            __UpperCamelCase    ,						max_length=self.max_length    ,						padding=self.padding    ,						pad_to_multiple_of=self.pad_to_multiple_of    ,						return_tensors='pt'    ,						)
        lowerCamelCase       =     self.model._get_feat_extract_output_lengths(batch['input_values'].shape[-1]  )

        lowerCamelCase       =     batch['input_values'].shape[0]

        # make sure that no loss is computed on padded inputs
        if batch["attention_mask"] is not None:
         # compute real output lengths according to convolution formula
         lowerCamelCase       =     self.model._get_feat_extract_output_lengths(batch['attention_mask'].sum(-1  )  ).to(
             torch.long  )

         lowerCamelCase       =     torch.zeros(
             (batch_size, mask_indices_seq_length)    ,						dtype=torch.long    ,						device=batch['input_values'].device  )

         # these two operations makes sure that all values
         # before the output lengths indices are attended to
         lowerCamelCase       =     1
         lowerCamelCase       =     attention_mask.flip([-1]  ).cumsum(-1  ).flip([-1]  ).bool()

        # sample randomly masked indices
        lowerCamelCase       =     _compute_mask_indices(
            (batch_size, mask_indices_seq_length)    ,						self.model.config.mask_time_prob    ,						self.model.config.mask_time_length    ,						attention_mask=__UpperCamelCase    ,						min_masks=2    ,						)

        return batch


class      lowerCAmelCase					(     __UpperCamelCase					):


       '''simple docstring'''







       def __init__(						self       :	Optional[Any]    ,						*__snake_case       :	Dict    ,						__snake_case       :	List[Any]=1    ,						__snake_case       :	Tuple=0    ,						__snake_case       :	Union[str, Any]=1.0    ,						**__snake_case       :	List[Any]  ) ->			List[Any]:







        '''simple docstring'''

        super().__init__(*__UpperCamelCase    ,						**__UpperCamelCase  )
        lowerCamelCase       =     0
        lowerCamelCase       =     max_gumbel_temp
        lowerCamelCase       =     min_gumbel_temp
        lowerCamelCase       =     gumbel_temp_decay





       def 	lowerCamelCase__    (						self       :	List[Any]    ,						__snake_case       :	nn.Module    ,						__snake_case       :	Dict[str, Union[torch.Tensor, Any]]  ) ->			int:







        '''simple docstring'''

        model.train()
        lowerCamelCase       =     self._prepare_inputs(__UpperCamelCase  )

        if self.use_amp:
         with autocast():
          lowerCamelCase       =     self.compute_loss(__UpperCamelCase    ,						__UpperCamelCase  )
        else:
         lowerCamelCase       =     self.compute_loss(__UpperCamelCase    ,						__UpperCamelCase  )

        if self.args.n_gpu > 1 or self.deepspeed:
         if model.module.config.ctc_loss_reduction == "mean":
          lowerCamelCase       =     loss.mean()
         elif model.module.config.ctc_loss_reduction == "sum":
          lowerCamelCase       =     loss.sum() / (inputs['mask_time_indices']).sum()
         else:
          raise ValueError(F'''{model.config.ctc_loss_reduction} is not valid. Choose one of [\'mean\', \'sum\']'''  )

        if self.args.gradient_accumulation_steps > 1:
         lowerCamelCase       =     loss / self.args.gradient_accumulation_steps

        if self.use_amp:
         self.scaler.scale(__UpperCamelCase  ).backward()
        elif self.use_apex:
         with amp.scale_loss(__UpperCamelCase    ,						self.optimizer  ) as scaled_loss:
          scaled_loss.backward()
        elif self.deepspeed:
         self.deepspeed.backward(__UpperCamelCase  )
        else:
         loss.backward()

        self.num_update_step += 1
        # make sure gumbel softmax temperature is decayed
        if self.args.n_gpu > 1 or self.deepspeed:
         model.module.set_gumbel_temperature(
             max(self.max_gumbel_temp * self.gumbel_temp_decay**self.num_update_step    ,						self.min_gumbel_temp  )  )
        else:
         model.set_gumbel_temperature(
             max(self.max_gumbel_temp * self.gumbel_temp_decay**self.num_update_step    ,						self.min_gumbel_temp  )  )

        return loss.detach()







def a_		(							)				-> Any:







 """simple docstring"""

 lowerCamelCase       =     HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments)	)

 lowerCamelCase    ,						lowerCamelCase    ,						lowerCamelCase       =     parser.parse_args_into_dataclasses()
 configure_logger(UpperCAmelCase__ ,       UpperCAmelCase__	)

 # Downloading and loading a dataset from the hub.
 lowerCamelCase       =     load_dataset(data_args.dataset_name ,       data_args.dataset_config_name ,       cache_dir=model_args.cache_dir	)

 if "validation" not in datasets.keys():
  # make sure only "validation" and "train" keys remain"
  lowerCamelCase       =     DatasetDict()
  lowerCamelCase       =     load_dataset(
      data_args.dataset_name ,       data_args.dataset_config_name ,       split=f'''{data_args.train_split_name}[:{data_args.validation_split_percentage}%]''' ,       cache_dir=model_args.cache_dir ,       )
  lowerCamelCase       =     load_dataset(
      data_args.dataset_name ,       data_args.dataset_config_name ,       split=f'''{data_args.train_split_name}[{data_args.validation_split_percentage}%:]''' ,       cache_dir=model_args.cache_dir ,       )
 else:
  # make sure only "validation" and "train" keys remain"
  lowerCamelCase       =     DatasetDict()
  lowerCamelCase       =     load_dataset(
      data_args.dataset_name ,       data_args.dataset_config_name ,       split='validation' ,       cache_dir=model_args.cache_dir ,       )
  lowerCamelCase       =     load_dataset(
      data_args.dataset_name ,       data_args.dataset_config_name ,       split=f'''{data_args.train_split_name}''' ,       cache_dir=model_args.cache_dir ,       )

 # only normalized-inputs-training is supported
 lowerCamelCase       =     WavaVecaFeatureExtractor.from_pretrained(
     model_args.model_name_or_path ,       cache_dir=model_args.cache_dir ,       do_normalize=UpperCAmelCase__	)

 def prepare_dataset(UpperCamelCase_ :				Dict	):
  # check that all files have the correct sampling rate
  lowerCamelCase    ,						lowerCamelCase       =     librosa.load(batch[data_args.speech_file_column] ,       sr=feature_extractor.sampling_rate	)
  return batch

 # load audio files into numpy arrays
 lowerCamelCase       =     datasets.map(
     UpperCAmelCase__ ,       num_proc=data_args.preprocessing_num_workers ,       remove_columns=datasets['train'].column_names	)

 # filter audio files that are too long
 lowerCamelCase       =     vectorized_datasets.filter(
     lambda UpperCamelCase_	: len(data['speech']	) < int(data_args.max_duration_in_seconds * feature_extractor.sampling_rate	)	)

 def normalize(UpperCamelCase_ :				List[str]	):
  return feature_extractor(batch['speech'] ,       sampling_rate=feature_extractor.sampling_rate	)

 # normalize and transform to `BatchFeatures`
 lowerCamelCase       =     vectorized_datasets.map(
     UpperCAmelCase__ ,       batched=UpperCAmelCase__ ,       num_proc=data_args.preprocessing_num_workers ,       load_from_cache_file=not data_args.overwrite_cache ,       remove_columns=vectorized_datasets['train'].column_names ,       )

 # pretraining is only supported for "newer" stable layer norm architecture
 # apply_spec_augment has to be True, mask_feature_prob has to be 0.0
 lowerCamelCase       =     WavaVecaConfig.from_pretrained(
     model_args.model_name_or_path ,       cache_dir=model_args.cache_dir ,       gradient_checkpointing=training_args.gradient_checkpointing ,       )

 if not config.do_stable_layer_norm or config.feat_extract_norm != "layer":
  raise ValueError(
      'PreTraining is only supported for ``config.do_stable_layer_norm=True`` and'
      ' ``config.feat_extract_norm=\'layer\''	)

 lowerCamelCase       =     WavaVecaForPreTraining(UpperCAmelCase__	)

 lowerCamelCase       =     DataCollatorForWavaVecaPretraining(model=UpperCAmelCase__ ,       feature_extractor=UpperCAmelCase__	)

 lowerCamelCase       =     WavaVecaPreTrainer(
     model=UpperCAmelCase__ ,       data_collator=UpperCAmelCase__ ,       args=UpperCAmelCase__ ,       train_dataset=vectorized_datasets['train'] ,       eval_dataset=vectorized_datasets['validation'] ,       tokenizer=UpperCAmelCase__ ,       max_gumbel_temp=model_args.max_gumbel_temperature ,       min_gumbel_temp=model_args.min_gumbel_temperature ,       gumbel_temp_decay=model_args.gumbel_temperature_decay ,       )
 trainer.train()


if __name__ == "__main__":
     main()






import os
from itertools import chain
from random import randrange, shuffle

import pytest

from .sola import PokerHand

lowercase   =	(
    '''4S 3H 2C 7S 5H''',
    '''9D 8H 2C 6S 7H''',
    '''2D 6D 9D TH 7D''',
    '''TC 8C 2S JH 6C''',
    '''JH 8S TH AH QH''',
    '''TS KS 5S 9S AC''',
    '''KD 6S 9D TH AD''',
    '''KS 8D 4D 9S 4S''',  # pair
    '''8C 4S KH JS 4D''',  # pair
    '''QH 8H KD JH 8S''',  # pair
    '''KC 4H KS 2H 8D''',  # pair
    '''KD 4S KC 3H 8S''',  # pair
    '''AH 8S AS KC JH''',  # pair
    '''3H 4C 4H 3S 2H''',  # 2 pairs
    '''5S 5D 2C KH KH''',  # 2 pairs
    '''3C KH 5D 5S KH''',  # 2 pairs
    '''AS 3C KH AD KH''',  # 2 pairs
    '''7C 7S 3S 7H 5S''',  # 3 of a kind
    '''7C 7S KH 2H 7H''',  # 3 of a kind
    '''AC KH QH AH AS''',  # 3 of a kind
    '''2H 4D 3C AS 5S''',  # straight (low ace)
    '''3C 5C 4C 2C 6H''',  # straight
    '''6S 8S 7S 5H 9H''',  # straight
    '''JS QS 9H TS KH''',  # straight
    '''QC KH TS JS AH''',  # straight (high ace)
    '''8C 9C 5C 3C TC''',  # flush
    '''3S 8S 9S 5S KS''',  # flush
    '''4C 5C 9C 8C KC''',  # flush
    '''JH 8H AH KH QH''',  # flush
    '''3D 2H 3H 2C 2D''',  # full house
    '''2H 2C 3S 3H 3D''',  # full house
    '''KH KC 3S 3H 3D''',  # full house
    '''JC 6H JS JD JH''',  # 4 of a kind
    '''JC 7H JS JD JH''',  # 4 of a kind
    '''JC KH JS JD JH''',  # 4 of a kind
    '''2S AS 4S 5S 3S''',  # straight flush (low ace)
    '''2D 6D 3D 4D 5D''',  # straight flush
    '''5C 6C 3C 7C 4C''',  # straight flush
    '''JH 9H TH KH QH''',  # straight flush
    '''JH AH TH KH QH''',  # royal flush (high ace straight flush)
)

lowercase   =	(
    ('''2H 3H 4H 5H 6H''', '''KS AS TS QS JS''', '''Loss'''),
    ('''2H 3H 4H 5H 6H''', '''AS AD AC AH JD''', '''Win'''),
    ('''AS AH 2H AD AC''', '''JS JD JC JH 3D''', '''Win'''),
    ('''2S AH 2H AS AC''', '''JS JD JC JH AD''', '''Loss'''),
    ('''2S AH 2H AS AC''', '''2H 3H 5H 6H 7H''', '''Win'''),
    ('''AS 3S 4S 8S 2S''', '''2H 3H 5H 6H 7H''', '''Win'''),
    ('''2H 3H 5H 6H 7H''', '''2S 3H 4H 5S 6C''', '''Win'''),
    ('''2S 3H 4H 5S 6C''', '''3D 4C 5H 6H 2S''', '''Tie'''),
    ('''2S 3H 4H 5S 6C''', '''AH AC 5H 6H AS''', '''Win'''),
    ('''2S 2H 4H 5S 4C''', '''AH AC 5H 6H AS''', '''Loss'''),
    ('''2S 2H 4H 5S 4C''', '''AH AC 5H 6H 7S''', '''Win'''),
    ('''6S AD 7H 4S AS''', '''AH AC 5H 6H 7S''', '''Loss'''),
    ('''2S AH 4H 5S KC''', '''AH AC 5H 6H 7S''', '''Loss'''),
    ('''2S 3H 6H 7S 9C''', '''7H 3C TH 6H 9S''', '''Loss'''),
    ('''4S 5H 6H TS AC''', '''3S 5H 6H TS AC''', '''Win'''),
    ('''2S AH 4H 5S 6C''', '''AD 4C 5H 6H 2C''', '''Tie'''),
    ('''AS AH 3H AD AC''', '''AS AH 2H AD AC''', '''Win'''),
    ('''AH AC 5H 5C QS''', '''AH AC 5H 5C KS''', '''Loss'''),
    ('''AH AC 5H 5C QS''', '''KH KC 5H 5C QS''', '''Win'''),
    ('''7C 7S KH 2H 7H''', '''3C 3S AH 2H 3H''', '''Win'''),
    ('''3C 3S AH 2H 3H''', '''7C 7S KH 2H 7H''', '''Loss'''),
    ('''6H 5H 4H 3H 2H''', '''5H 4H 3H 2H AH''', '''Win'''),
    ('''5H 4H 3H 2H AH''', '''5H 4H 3H 2H AH''', '''Tie'''),
    ('''5H 4H 3H 2H AH''', '''6H 5H 4H 3H 2H''', '''Loss'''),
    ('''AH AD KS KC AC''', '''AH KD KH AC KC''', '''Win'''),
    ('''2H 4D 3C AS 5S''', '''2H 4D 3C 6S 5S''', '''Loss'''),
    ('''2H 3S 3C 3H 2S''', '''3S 3C 2S 2H 2D''', '''Win'''),
    ('''4D 6D 5D 2D JH''', '''3S 8S 3H TC KH''', '''Loss'''),
    ('''4S 6C 8S 3S 7S''', '''AD KS 2D 7D 7C''', '''Loss'''),
    ('''6S 4C 7H 8C 3H''', '''5H JC AH 9D 9C''', '''Loss'''),
    ('''9D 9H JH TC QH''', '''3C 2S JS 5C 7H''', '''Win'''),
    ('''2H TC 8S AD 9S''', '''4H TS 7H 2C 5C''', '''Win'''),
    ('''9D 3S 2C 7S 7C''', '''JC TD 3C TC 9H''', '''Loss'''),
)

lowercase   =	(
    ('''2H 3H 4H 5H 6H''', True),
    ('''AS AH 2H AD AC''', False),
    ('''2H 3H 5H 6H 7H''', True),
    ('''KS AS TS QS JS''', True),
    ('''8H 9H QS JS TH''', False),
    ('''AS 3S 4S 8S 2S''', True),
)

lowercase   =	(
    ('''2H 3H 4H 5H 6H''', True),
    ('''AS AH 2H AD AC''', False),
    ('''2H 3H 5H 6H 7H''', False),
    ('''KS AS TS QS JS''', True),
    ('''8H 9H QS JS TH''', True),
)

lowercase   =	(
    ('''2H 4D 3C AS 5S''', True, [5, 4, 3, 2, 1_4]),
    ('''2H 5D 3C AS 5S''', False, [1_4, 5, 5, 3, 2]),
    ('''JH QD KC AS TS''', False, [1_4, 1_3, 1_2, 1_1, 1_0]),
    ('''9D 3S 2C 7S 7C''', False, [9, 7, 7, 3, 2]),
)

lowercase   =	(
    ('''JH AH TH KH QH''', 0),
    ('''JH 9H TH KH QH''', 0),
    ('''JC KH JS JD JH''', 7),
    ('''KH KC 3S 3H 3D''', 6),
    ('''8C 9C 5C 3C TC''', 0),
    ('''JS QS 9H TS KH''', 0),
    ('''7C 7S KH 2H 7H''', 3),
    ('''3C KH 5D 5S KH''', 2),
    ('''QH 8H KD JH 8S''', 1),
    ('''2D 6D 9D TH 7D''', 0),
)

lowercase   =	(
    ('''JH AH TH KH QH''', 2_3),
    ('''JH 9H TH KH QH''', 2_2),
    ('''JC KH JS JD JH''', 2_1),
    ('''KH KC 3S 3H 3D''', 2_0),
    ('''8C 9C 5C 3C TC''', 1_9),
    ('''JS QS 9H TS KH''', 1_8),
    ('''7C 7S KH 2H 7H''', 1_7),
    ('''3C KH 5D 5S KH''', 1_6),
    ('''QH 8H KD JH 8S''', 1_5),
    ('''2D 6D 9D TH 7D''', 1_4),
)



def   __lowerCAmelCase    (				)	->     List[str]:
							lowerCamelCase_	, lowerCamelCase_					=       randrange(len(UpperCAmelCase__							)							), randrange(len(UpperCAmelCase__							)							)
							lowerCamelCase_					=       ["""Loss""", """Tie""", """Win"""][(play >= oppo) + (play > oppo)]
							lowerCamelCase_	, lowerCamelCase_					=       SORTED_HANDS[play], SORTED_HANDS[oppo]
							return hand, other, expected



def   __lowerCAmelCase    (				UpperCAmelCase__					:   int = 1_0_0							)	->     Optional[int]:
							return (generate_random_hand() for _ in range(UpperCAmelCase__							))



@pytest.mark.parametrize("""hand, expected"""      ,					UpperCAmelCase__							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   Union[str, Any]      ,					UpperCAmelCase__					:   Union[str, Any]							)	->     List[Any]:
							assert PokerHand(UpperCAmelCase__							)._is_flush() == expected



@pytest.mark.parametrize("""hand, expected"""      ,					UpperCAmelCase__							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   Tuple      ,					UpperCAmelCase__					:   List[Any]							)	->     int:
							assert PokerHand(UpperCAmelCase__							)._is_straight() == expected



@pytest.mark.parametrize("""hand, expected, card_values"""      ,					UpperCAmelCase__							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   List[str]      ,					UpperCAmelCase__					:   List[Any]      ,					UpperCAmelCase__					:   Union[str, Any]							)	->     Union[str, Any]:
							lowerCamelCase_					=       PokerHand(UpperCAmelCase__							)
							assert player._is_five_high_straight() == expected
							assert player._card_values == card_values



@pytest.mark.parametrize("""hand, expected"""      ,					UpperCAmelCase__							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   List[Any]      ,					UpperCAmelCase__					:   Dict							)	->     str:
							assert PokerHand(UpperCAmelCase__							)._is_same_kind() == expected



@pytest.mark.parametrize("""hand, expected"""      ,					UpperCAmelCase__							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   Any      ,					UpperCAmelCase__					:   Dict							)	->     Tuple:
							assert PokerHand(UpperCAmelCase__							)._hand_type == expected



@pytest.mark.parametrize("""hand, other, expected"""      ,					UpperCAmelCase__							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   int      ,					UpperCAmelCase__					:   Tuple      ,					UpperCAmelCase__					:   Union[str, Any]							)	->     Any:
							assert PokerHand(UpperCAmelCase__							).compare_with(PokerHand(UpperCAmelCase__							)							) == expected



@pytest.mark.parametrize("""hand, other, expected"""      ,					generate_random_hands()							)
def   __lowerCAmelCase    (				UpperCAmelCase__					:   Any      ,					UpperCAmelCase__					:   Tuple      ,					UpperCAmelCase__					:   Dict							)	->     List[str]:
							assert PokerHand(UpperCAmelCase__							).compare_with(PokerHand(UpperCAmelCase__							)							) == expected



def   __lowerCAmelCase    (				)	->     Tuple:
							lowerCamelCase_					=       [PokerHand(UpperCAmelCase__							) for hand in SORTED_HANDS]
							lowerCamelCase_					=       poker_hands.copy()
							shuffle(UpperCAmelCase__							)
							lowerCamelCase_					=       chain(sorted(UpperCAmelCase__							)							)
							for index, hand in enumerate(UpperCAmelCase__							):
														assert hand == poker_hands[index]



def   __lowerCAmelCase    (				)	->     List[Any]:
							# Test that five high straights are compared correctly.
							lowerCamelCase_					=       [PokerHand("""2D AC 3H 4H 5S"""							), PokerHand("""2S 3H 4H 5S 6C"""							)]
							pokerhands.sort(reverse=UpperCAmelCase__							)
							assert pokerhands[0].__str__() == "2S 3H 4H 5S 6C"



def   __lowerCAmelCase    (				)	->     List[str]:
							# Multiple calls to five_high_straight function should still return True
							# and shouldn't mutate the list in every call other than the first.
							lowerCamelCase_					=       PokerHand("""2C 4S AS 3D 5C"""							)
							lowerCamelCase_					=       True
							lowerCamelCase_					=       [5, 4, 3, 2, 1_4]
							for _ in range(1_0							):
														assert pokerhand._is_five_high_straight() == expected
														assert pokerhand._card_values == expected_card_values



def   __lowerCAmelCase    (				)	->     List[Any]:
							# Problem number 54 from Project Euler
							# Testing from poker_hands.txt file
							lowerCamelCase_					=       0
							lowerCamelCase_					=       os.path.abspath(os.path.dirname(UpperCAmelCase__							)							)
							lowerCamelCase_					=       os.path.join(UpperCAmelCase__      ,					"""poker_hands.txt"""							)
							with open(UpperCAmelCase__							) as file_hand:
														for line in file_hand:
																					lowerCamelCase_					=       line[:1_4].strip()
																					lowerCamelCase_					=       line[1_5:].strip()
																					lowerCamelCase_	, lowerCamelCase_					=       PokerHand(UpperCAmelCase__							), PokerHand(UpperCAmelCase__							)
																					lowerCamelCase_					=       player.compare_with(UpperCAmelCase__							)
																					if output == "Win":
																												answer += 1
							assert answer == 3_7_6





