
'''simple docstring'''

import unittest

from cer import CER


__UpperCAmelCase												=   CER()


class 		_a     (							unittest.TestCase  ):







   """simple docstring"""




   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Dict								=		['''White House''']
    SCREAMING_SNAKE_CASE  :  Dict								=		['''white house''']
    # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.18_1818_1818      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		['''were wolf''']
    SCREAMING_SNAKE_CASE  :  str								=		['''werewolf''']
    # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
    SCREAMING_SNAKE_CASE  :  int								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.111_1111      ) < 1e-6      )

    SCREAMING_SNAKE_CASE  :  List[str]								=		['''werewolf''']
    SCREAMING_SNAKE_CASE  :  List[Any]								=		['''weae     wolf''']
    # S = 1, D = 1, I = 0, N = 8, CER = 0.25
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.25      ) < 1e-6      )

    # consecutive whitespaces case 1
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		['''were wolf''']
    SCREAMING_SNAKE_CASE  :  List[str]								=		['''were               wolf''']
    # S = 0, D = 0, I = 0, N = 9, CER = 0
    SCREAMING_SNAKE_CASE  :  str								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.0      ) < 1e-6      )

    # consecutive whitespaces case 2
    SCREAMING_SNAKE_CASE  :  Any								=		['''were   wolf''']
    SCREAMING_SNAKE_CASE  :  Tuple								=		['''were               wolf''']
    # S = 0, D = 0, I = 0, N = 9, CER = 0
    SCREAMING_SNAKE_CASE  :  str								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.0      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		['''werewolf''']
    SCREAMING_SNAKE_CASE  :  str								=		['''weaewolf''']
    # S = 1, D = 0, I = 0, N = 8, CER = 0.125
    SCREAMING_SNAKE_CASE  :  Tuple								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.125      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Any								=		['''werewolf''']
    SCREAMING_SNAKE_CASE  :  int								=		['''wereawolf''']
    # S = 0, D = 1, I = 0, N = 8, CER = 0.125
    SCREAMING_SNAKE_CASE  :  Tuple								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.125      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		['''werewolf''']
    SCREAMING_SNAKE_CASE  :  Dict								=		['''wereolf''']
    # S = 0, D = 0, I = 1, N = 8, CER = 0.125
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.125      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		['''werewolf''']
    SCREAMING_SNAKE_CASE  :  List[Any]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertEqual(lowerCamelCase__    ,0.0      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  int								=		['''werewolf''', '''I am your father''']
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertEqual(lowerCamelCase__    ,0.0      )

    SCREAMING_SNAKE_CASE  :  List[str]								=		['''werewolf''', '''I am your father''', '''doge''']
    SCREAMING_SNAKE_CASE  :  Any								=		['''werxwolf''', '''I       am your father''', '''doge''']
    # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
    SCREAMING_SNAKE_CASE  :  str								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.0357_1428      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  str								=		['''My hovercraft''', '''is full of eels''']
    SCREAMING_SNAKE_CASE  :  Any								=		['''My hovercraft is full''', ''' of eels''']
    # S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
    # whitespace at the front of " of eels" will be strip during preporcessing
    # so need to insert 2 whitespaces
    SCREAMING_SNAKE_CASE  :  Dict								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__    ,concatenate_texts=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.07_1428      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[str]								=		['''我能吞下玻璃而不伤身体''']
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		[''' 能吞虾玻璃而 不霜身体啦''']
    # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
    SCREAMING_SNAKE_CASE  :  List[str]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.45_4545_4545      ) < 1e-6      )

    SCREAMING_SNAKE_CASE  :  int								=		['''我能吞下玻璃''', '''而不伤身体''']
    SCREAMING_SNAKE_CASE  :  List[Any]								=		['''我    能 吞 下 玻 璃''', '''而不伤身体''']
    # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
    SCREAMING_SNAKE_CASE  :  Dict								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertTrue(abs(char_error_rate - 0.4545_4545_4545      ) < 1e-6      )

    SCREAMING_SNAKE_CASE  :  List[Any]								=		['''我能吞下玻璃而不伤身体''']
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )
    self.assertFalse(lowerCamelCase__    ,0.0      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  str								=		['''''']
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		['''Hypothesis''']
    with self.assertRaises(lowerCamelCase__      ):
     cer.compute(predictions=lowerCamelCase__    ,references=lowerCamelCase__      )


if __name__ == "__main__":
   unittest.main()






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


__UpperCamelCase							:							Dict    							=					{
    "configuration_dpr": ["DPR_PRETRAINED_CONFIG_ARCHIVE_MAP", "DPRConfig"],
    "tokenization_dpr": [
        "DPRContextEncoderTokenizer",
        "DPRQuestionEncoderTokenizer",
        "DPRReaderOutput",
        "DPRReaderTokenizer",
    ],
}


try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							Any    							=					[
           "DPRContextEncoderTokenizerFast",
           "DPRQuestionEncoderTokenizerFast",
           "DPRReaderTokenizerFast",
       ]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							str    							=					[
           "DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "DPRContextEncoder",
           "DPRPretrainedContextEncoder",
           "DPRPreTrainedModel",
           "DPRPretrainedQuestionEncoder",
           "DPRPretrainedReader",
           "DPRQuestionEncoder",
           "DPRReader",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase							:							int    							=					[
           "TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFDPRContextEncoder",
           "TFDPRPretrainedContextEncoder",
           "TFDPRPretrainedQuestionEncoder",
           "TFDPRPretrainedReader",
           "TFDPRQuestionEncoder",
           "TFDPRReader",
       ]


if TYPE_CHECKING:
       from .configuration_dpr import DPR_PRETRAINED_CONFIG_ARCHIVE_MAP, DPRConfig
       from .tokenization_dpr import (
           DPRContextEncoderTokenizer,
           DPRQuestionEncoderTokenizer,
           DPRReaderOutput,
           DPRReaderTokenizer,
       )

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_dpr_fast import (
                  DPRContextEncoderTokenizerFast,
                  DPRQuestionEncoderTokenizerFast,
                  DPRReaderTokenizerFast,
              )

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_dpr import (
                  DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  DPRContextEncoder,
                  DPRPretrainedContextEncoder,
                  DPRPreTrainedModel,
                  DPRPretrainedQuestionEncoder,
                  DPRPretrainedReader,
                  DPRQuestionEncoder,
                  DPRReader,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_dpr import (
                  TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFDPRContextEncoder,
                  TFDPRPretrainedContextEncoder,
                  TFDPRPretrainedQuestionEncoder,
                  TFDPRPretrainedReader,
                  TFDPRQuestionEncoder,
                  TFDPRReader,
              )

else:
       import sys

       __UpperCamelCase							:							Dict    							=					_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


