


from typing import Any, Dict, Optional

import torch
import torch.nn.functional as F
from torch import nn

from ..utils import maybe_allow_in_graph
from .activations import get_activation
from .attention_processor import Attention
from .embeddings import CombinedTimestepLabelEmbeddings


@maybe_allow_in_graph
class   a__	(						nn.Module    ):

       def __init__(   self      :     Dict      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     Tuple=0.0      ,							lowerCamelCase_      :     Optional[int] = None      ,							lowerCamelCase_      :     str = "geglu"      ,							lowerCamelCase_      :     Optional[int] = None      ,							lowerCamelCase_      :     bool = False      ,							lowerCamelCase_      :     bool = False      ,							lowerCamelCase_      :     bool = False      ,							lowerCamelCase_      :     bool = False      ,							lowerCamelCase_      :     bool = True      ,							lowerCamelCase_      :     str = "layer_norm"      ,							lowerCamelCase_      :     bool = False      ,							):
            super().__init__()
            a_    :     Union[str, Any]										=    only_cross_attention

            a_    :     Tuple										=    (num_embeds_ada_norm is not None) and norm_type == """ada_norm_zero"""
            a_    :     List[str]										=    (num_embeds_ada_norm is not None) and norm_type == """ada_norm"""

            if norm_type in ("ada_norm", "ada_norm_zero") and num_embeds_ada_norm is None:
                 raise ValueError(
                     F'''`norm_type` is set to {norm_type}, but `num_embeds_ada_norm` is not defined. Please make sure to'''
                     F''' define `num_embeds_ada_norm` if setting `norm_type` to {norm_type}.'''    )

            # Define 3 blocks. Each block has its own normalization layer.
            # 1. Self-Attn
            if self.use_ada_layer_norm:
                 a_    :     Optional[Any]										=    AdaLayerNorm(lowerCamelCase_      ,							lowerCamelCase_    )
            elif self.use_ada_layer_norm_zero:
                 a_    :     Tuple										=    AdaLayerNormZero(lowerCamelCase_      ,							lowerCamelCase_    )
            else:
                 a_    :     Dict										=    nn.LayerNorm(lowerCamelCase_      ,							elementwise_affine=lowerCamelCase_    )
            a_    :     Optional[int]										=    Attention(
                query_dim=lowerCamelCase_      ,							heads=lowerCamelCase_      ,							dim_head=lowerCamelCase_      ,							dropout=lowerCamelCase_      ,							bias=lowerCamelCase_      ,							cross_attention_dim=cross_attention_dim if only_cross_attention else None      ,							upcast_attention=lowerCamelCase_      ,							)

            # 2. Cross-Attn
            if cross_attention_dim is not None or double_self_attention:
                 # We currently only use AdaLayerNormZero for self attention where there will only be one attention block.
                 # I.e. the number of returned modulation chunks from AdaLayerZero would not make sense if returned during
                 # the second cross attention block.
                 a_    :     List[Any]										=    (
                     AdaLayerNorm(lowerCamelCase_      ,							lowerCamelCase_    )
                     if self.use_ada_layer_norm
                     else nn.LayerNorm(lowerCamelCase_      ,							elementwise_affine=lowerCamelCase_    )
                 )
                 a_    :     Optional[int]										=    Attention(
                     query_dim=lowerCamelCase_      ,							cross_attention_dim=cross_attention_dim if not double_self_attention else None      ,							heads=lowerCamelCase_      ,							dim_head=lowerCamelCase_      ,							dropout=lowerCamelCase_      ,							bias=lowerCamelCase_      ,							upcast_attention=lowerCamelCase_      ,							)  # is self-attn if encoder_hidden_states is none
            else:
                 a_    :     Tuple										=    None
                 a_    :     Dict										=    None

            # 3. Feed-forward
            a_    :     int										=    nn.LayerNorm(lowerCamelCase_      ,							elementwise_affine=lowerCamelCase_    )
            a_    :     List[str]										=    FeedForward(lowerCamelCase_      ,							dropout=lowerCamelCase_      ,							activation_fn=lowerCamelCase_      ,							final_dropout=lowerCamelCase_    )

            # let chunk size default to None
            a_    :     List[Any]										=    None
            a_    :     Dict										=    0

       def 						UpperCAmelCase(   self      :     Optional[Any]      ,							lowerCamelCase_      :     Optional[int]      ,							lowerCamelCase_      :     int    ):
            # Sets chunk feed-forward
            a_    :     Optional[Any]										=    chunk_size
            a_    :     List[str]										=    dim

       def 						UpperCAmelCase(   self      :     Any      ,							lowerCamelCase_      :     torch.FloatTensor      ,							lowerCamelCase_      :     Optional[torch.FloatTensor] = None      ,							lowerCamelCase_      :     Optional[torch.FloatTensor] = None      ,							lowerCamelCase_      :     Optional[torch.FloatTensor] = None      ,							lowerCamelCase_      :     Optional[torch.LongTensor] = None      ,							lowerCamelCase_      :     Dict[str, Any] = None      ,							lowerCamelCase_      :     Optional[torch.LongTensor] = None      ,							):
            # Notice that normalization is always applied before the real computation in the following blocks.
            # 1. Self-Attention
            if self.use_ada_layer_norm:
                 a_    :     int										=    self.norma(lowerCamelCase_      ,							lowerCamelCase_    )
            elif self.use_ada_layer_norm_zero:
                 a_			,			a_			,			a_			,			a_			,			a_    :     List[Any]										=    self.norma(
                     lowerCamelCase_      ,							lowerCamelCase_      ,							lowerCamelCase_      ,							hidden_dtype=hidden_states.dtype    )
            else:
                 a_    :     Optional[Any]										=    self.norma(lowerCamelCase_    )

            a_    :     Any										=    cross_attention_kwargs if cross_attention_kwargs is not None else {}

            a_    :     Optional[Any]										=    self.attna(
                lowerCamelCase_      ,							encoder_hidden_states=encoder_hidden_states if self.only_cross_attention else None      ,							attention_mask=lowerCamelCase_      ,							**lowerCamelCase_      ,							)
            if self.use_ada_layer_norm_zero:
                 a_    :     Union[str, Any]										=    gate_msa.unsqueeze(1    ) * attn_output
            a_    :     Any										=    attn_output + hidden_states

            # 2. Cross-Attention
            if self.attna is not None:
                 a_    :     List[Any]										=    (
                     self.norma(lowerCamelCase_      ,							lowerCamelCase_    ) if self.use_ada_layer_norm else self.norma(lowerCamelCase_    )
                 )

                 a_    :     Union[str, Any]										=    self.attna(
                     lowerCamelCase_      ,							encoder_hidden_states=lowerCamelCase_      ,							attention_mask=lowerCamelCase_      ,							**lowerCamelCase_      ,							)
                 a_    :     str										=    attn_output + hidden_states

            # 3. Feed-forward
            a_    :     List[Any]										=    self.norma(lowerCamelCase_    )

            if self.use_ada_layer_norm_zero:
                 a_    :     int										=    norm_hidden_states * (1 + scale_mlp[:, None]) + shift_mlp[:, None]

            if self._chunk_size is not None:
                 # "feed_forward_chunk_size" can be used to save memory
                 if norm_hidden_states.shape[self._chunk_dim] % self._chunk_size != 0:
                      raise ValueError(
                          F'''`hidden_states` dimension to be chunked: {norm_hidden_states.shape[self._chunk_dim]} has to be divisible by chunk size: {self._chunk_size}. Make sure to set an appropriate `chunk_size` when calling `unet.enable_forward_chunking`.'''    )

                 a_    :     List[str]										=    norm_hidden_states.shape[self._chunk_dim] // self._chunk_size
                 a_    :     Any										=    torch.cat(
                     [self.ff(lowerCamelCase_    ) for hid_slice in norm_hidden_states.chunk(lowerCamelCase_      ,							dim=self._chunk_dim    )]      ,							dim=self._chunk_dim      ,							)
            else:
                 a_    :     Union[str, Any]										=    self.ff(lowerCamelCase_    )

            if self.use_ada_layer_norm_zero:
                 a_    :     Tuple										=    gate_mlp.unsqueeze(1    ) * ff_output

            a_    :     Dict										=    ff_output + hidden_states

            return hidden_states


class   a__	(						nn.Module    ):

       def __init__(   self      :     Tuple      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     Optional[int] = None      ,							lowerCamelCase_      :     int = 4      ,							lowerCamelCase_      :     float = 0.0      ,							lowerCamelCase_      :     str = "geglu"      ,							lowerCamelCase_      :     bool = False      ,							):
            super().__init__()
            a_    :     str										=    int(dim * mult    )
            a_    :     List[Any]										=    dim_out if dim_out is not None else dim

            if activation_fn == "gelu":
                 a_    :     Tuple										=    GELU(lowerCamelCase_      ,							lowerCamelCase_    )
            if activation_fn == "gelu-approximate":
                 a_    :     int										=    GELU(lowerCamelCase_      ,							lowerCamelCase_      ,							approximate="""tanh"""    )
            elif activation_fn == "geglu":
                 a_    :     List[str]										=    GEGLU(lowerCamelCase_      ,							lowerCamelCase_    )
            elif activation_fn == "geglu-approximate":
                 a_    :     Optional[Any]										=    ApproximateGELU(lowerCamelCase_      ,							lowerCamelCase_    )

            a_    :     Dict										=    nn.ModuleList([]    )
            # project in
            self.net.append(lowerCamelCase_    )
            # project dropout
            self.net.append(nn.Dropout(lowerCamelCase_    )    )
            # project out
            self.net.append(nn.Linear(lowerCamelCase_      ,							lowerCamelCase_    )    )
            # FF as used in Vision Transformer, MLP-Mixer, etc. have a final dropout
            if final_dropout:
                 self.net.append(nn.Dropout(lowerCamelCase_    )    )

       def 						UpperCAmelCase(   self      :     List[str]      ,							lowerCamelCase_      :     Optional[int]    ):
            for module in self.net:
                 a_    :     Union[str, Any]										=    module(lowerCamelCase_    )
            return hidden_states


class   a__	(						nn.Module    ):

       def __init__(   self      :     List[str]      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     str = "none"    ):
            super().__init__()
            a_    :     Optional[Any]										=    nn.Linear(lowerCamelCase_      ,							lowerCamelCase_    )
            a_    :     Union[str, Any]										=    approximate

       def 						UpperCAmelCase(   self      :     Tuple      ,							lowerCamelCase_      :     Optional[int]    ):
            if gate.device.type != "mps":
                 return F.gelu(lowerCamelCase_      ,							approximate=self.approximate    )
            # mps: gelu is not implemented for float16
            return F.gelu(gate.to(dtype=torch.floataa    )      ,							approximate=self.approximate    ).to(dtype=gate.dtype    )

       def 						UpperCAmelCase(   self      :     Tuple      ,							lowerCamelCase_      :     List[Any]    ):
            a_    :     List[Any]										=    self.proj(lowerCamelCase_    )
            a_    :     str										=    self.gelu(lowerCamelCase_    )
            return hidden_states


class   a__	(						nn.Module    ):

       def __init__(   self      :     List[str]      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int    ):
            super().__init__()
            a_    :     Union[str, Any]										=    nn.Linear(lowerCamelCase_      ,							dim_out * 2    )

       def 						UpperCAmelCase(   self      :     Union[str, Any]      ,							lowerCamelCase_      :     Any    ):
            if gate.device.type != "mps":
                 return F.gelu(lowerCamelCase_    )
            # mps: gelu is not implemented for float16
            return F.gelu(gate.to(dtype=torch.floataa    )    ).to(dtype=gate.dtype    )

       def 						UpperCAmelCase(   self      :     Optional[int]      ,							lowerCamelCase_      :     List[str]    ):
            a_			,			a_    :     List[str]										=    self.proj(lowerCamelCase_    ).chunk(2      ,							dim=-1    )
            return hidden_states * self.gelu(lowerCamelCase_    )


class   a__	(						nn.Module    ):

       def __init__(   self      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int    ):
            super().__init__()
            a_    :     List[str]										=    nn.Linear(lowerCamelCase_      ,							lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     Tuple      ,							lowerCamelCase_      :     List[str]    ):
            a_    :     Tuple										=    self.proj(lowerCamelCase_    )
            return x * torch.sigmoid(1.7_0_2 * x    )


class   a__	(						nn.Module    ):

       def __init__(   self      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int    ):
            super().__init__()
            a_    :     Union[str, Any]										=    nn.Embedding(lowerCamelCase_      ,							lowerCamelCase_    )
            a_    :     Any										=    nn.SiLU()
            a_    :     str										=    nn.Linear(lowerCamelCase_      ,							embedding_dim * 2    )
            a_    :     Any										=    nn.LayerNorm(lowerCamelCase_      ,							elementwise_affine=lowerCamelCase_    )

       def 						UpperCAmelCase(   self      :     List[str]      ,							lowerCamelCase_      :     str      ,							lowerCamelCase_      :     Union[str, Any]    ):
            a_    :     str										=    self.linear(self.silu(self.emb(lowerCamelCase_    )    )    )
            a_			,			a_    :     Any										=    torch.chunk(lowerCamelCase_      ,							2    )
            a_    :     int										=    self.norm(lowerCamelCase_    ) * (1 + scale) + shift
            return x


class   a__	(						nn.Module    ):

       def __init__(   self      :     str      ,							lowerCamelCase_      :     Dict      ,							lowerCamelCase_      :     List[Any]    ):
            super().__init__()

            a_    :     Any										=    CombinedTimestepLabelEmbeddings(lowerCamelCase_      ,							lowerCamelCase_    )

            a_    :     Optional[Any]										=    nn.SiLU()
            a_    :     int										=    nn.Linear(lowerCamelCase_      ,							6 * embedding_dim      ,							bias=lowerCamelCase_    )
            a_    :     int										=    nn.LayerNorm(lowerCamelCase_      ,							elementwise_affine=lowerCamelCase_      ,							eps=1E-6    )

       def 						UpperCAmelCase(   self      :     int      ,							lowerCamelCase_      :     Optional[int]      ,							lowerCamelCase_      :     str      ,							lowerCamelCase_      :     Optional[int]      ,							lowerCamelCase_      :     Union[str, Any]=None    ):
            a_    :     Optional[int]										=    self.linear(self.silu(self.emb(lowerCamelCase_      ,							lowerCamelCase_      ,							hidden_dtype=lowerCamelCase_    )    )    )
            a_			,			a_			,			a_			,			a_			,			a_			,			a_    :     List[Any]										=    emb.chunk(6      ,							dim=1    )
            a_    :     List[str]										=    self.norm(lowerCamelCase_    ) * (1 + scale_msa[:, None]) + shift_msa[:, None]
            return x, gate_msa, shift_mlp, scale_mlp, gate_mlp


class   a__	(						nn.Module    ):

       def __init__(   self      :     List[str]      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     int      ,							lowerCamelCase_      :     Optional[str] = None      ,							lowerCamelCase_      :     float = 1E-5    ):
            super().__init__()
            a_    :     int										=    num_groups
            a_    :     Optional[Any]										=    eps

            if act_fn is None:
                 a_    :     Optional[Any]										=    None
            else:
                 a_    :     int										=    get_activation(lowerCamelCase_    )

            a_    :     List[str]										=    nn.Linear(lowerCamelCase_      ,							out_dim * 2    )

       def 						UpperCAmelCase(   self      :     Dict      ,							lowerCamelCase_      :     List[Any]      ,							lowerCamelCase_      :     List[str]    ):
            if self.act:
                 a_    :     List[str]										=    self.act(lowerCamelCase_    )
            a_    :     str										=    self.linear(lowerCamelCase_    )
            a_    :     Tuple										=    emb[:, :, None, None]
            a_			,			a_    :     Optional[int]										=    emb.chunk(2      ,							dim=1    )

            a_    :     int										=    F.group_norm(lowerCamelCase_      ,							self.num_groups      ,							eps=self.eps    )
            a_    :     Optional[Any]										=    x * (1 + scale) + shift
            return x







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

import pytest

from .sola import PokerHand

__lowerCamelCase        =     (
    '''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)
)

__lowerCamelCase        =     (
    ('''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'''),
)

__lowerCamelCase        =     (
    ('''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),
)

__lowerCamelCase        =     (
    ('''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),
)

__lowerCamelCase        =     (
    ('''2H 4D 3C AS 5S''', True, [5, 4, 3, 2, 14]),
    ('''2H 5D 3C AS 5S''', False, [14, 5, 5, 3, 2]),
    ('''JH QD KC AS TS''', False, [14, 13, 12, 11, 10]),
    ('''9D 3S 2C 7S 7C''', False, [9, 7, 7, 3, 2]),
)

__lowerCamelCase        =     (
    ('''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),
)

__lowerCamelCase        =     (
    ('''JH AH TH KH QH''', 23),
    ('''JH 9H TH KH QH''', 22),
    ('''JC KH JS JD JH''', 21),
    ('''KH KC 3S 3H 3D''', 20),
    ('''8C 9C 5C 3C TC''', 19),
    ('''JS QS 9H TS KH''', 18),
    ('''7C 7S KH 2H 7H''', 17),
    ('''3C KH 5D 5S KH''', 16),
    ('''QH 8H KD JH 8S''', 15),
    ('''2D 6D 9D TH 7D''', 14),
)



def  _a			(						):
     a_			,			a_    :     List[Any]										=    randrange(len(__UpperCamelCase ) ), randrange(len(__UpperCamelCase ) )
     a_    :     List[Any]										=    ["""Loss""", """Tie""", """Win"""][(play >= oppo) + (play > oppo)]
     a_			,			a_    :     Optional[Any]										=    SORTED_HANDS[play], SORTED_HANDS[oppo]
     return hand, other, expected



def  _a			(						__UpperCamelCase = 1_0_0 ):
     return (generate_random_hand() for _ in range(__UpperCamelCase ))



@pytest.mark.parametrize("""hand, expected"""  ,  __UpperCamelCase )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase ):
     assert PokerHand(__UpperCamelCase )._is_flush() == expected



@pytest.mark.parametrize("""hand, expected"""  ,  __UpperCamelCase )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase ):
     assert PokerHand(__UpperCamelCase )._is_straight() == expected



@pytest.mark.parametrize("""hand, expected, card_values"""  ,  __UpperCamelCase )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase ):
     a_    :     Union[str, Any]										=    PokerHand(__UpperCamelCase )
     assert player._is_five_high_straight() == expected
     assert player._card_values == card_values



@pytest.mark.parametrize("""hand, expected"""  ,  __UpperCamelCase )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase ):
     assert PokerHand(__UpperCamelCase )._is_same_kind() == expected



@pytest.mark.parametrize("""hand, expected"""  ,  __UpperCamelCase )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase ):
     assert PokerHand(__UpperCamelCase )._hand_type == expected



@pytest.mark.parametrize("""hand, other, expected"""  ,  __UpperCamelCase )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase ):
     assert PokerHand(__UpperCamelCase ).compare_with(PokerHand(__UpperCamelCase ) ) == expected



@pytest.mark.parametrize("""hand, other, expected"""  ,  generate_random_hands() )
def  _a			(						__UpperCamelCase  ,  __UpperCamelCase  ,  __UpperCamelCase ):
     assert PokerHand(__UpperCamelCase ).compare_with(PokerHand(__UpperCamelCase ) ) == expected



def  _a			(						):
     a_    :     int										=    [PokerHand(__UpperCamelCase ) for hand in SORTED_HANDS]
     a_    :     Dict										=    poker_hands.copy()
     shuffle(__UpperCamelCase )
     a_    :     Dict										=    chain(sorted(__UpperCamelCase ) )
     for index, hand in enumerate(__UpperCamelCase ):
          assert hand == poker_hands[index]



def  _a			(						):
     # Test that five high straights are compared correctly.
     a_    :     str										=    [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  _a			(						):
     # Multiple calls to five_high_straight function should still return True
     # and shouldn't mutate the list in every call other than the first.
     a_    :     List[str]										=    PokerHand("""2C 4S AS 3D 5C""" )
     a_    :     Dict										=    True
     a_    :     List[Any]										=    [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  _a			(						):
     # Problem number 54 from Project Euler
     # Testing from poker_hands.txt file
     a_    :     Tuple										=    0
     a_    :     Optional[Any]										=    os.path.abspath(os.path.dirname(__UpperCamelCase ) )
     a_    :     Optional[int]										=    os.path.join(__UpperCamelCase  ,  """poker_hands.txt""" )
     with open(__UpperCamelCase ) as file_hand:
          for line in file_hand:
               a_    :     Dict										=    line[:1_4].strip()
               a_    :     int										=    line[1_5:].strip()
               a_			,			a_    :     Optional[int]										=    PokerHand(__UpperCamelCase ), PokerHand(__UpperCamelCase )
               a_    :     str										=    player.compare_with(__UpperCamelCase )
               if output == "Win":
                    answer += 1
     assert answer == 3_7_6



