import unittest

from cer import CER


__lowerCamelCase     :					Optional[Any]				  =						CER()







class __snake_case							(		unittest.TestCase						):




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''White House''']
     SCREAMING_SNAKE_CASE__     				= ['''white house''']
     # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18 ) < 1E-6 )




   def       __a		(       self     :							int ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''were wolf''']
     SCREAMING_SNAKE_CASE__     				= ['''werewolf''']
     # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.1_11_11_11 ) < 1E-6 )

     SCREAMING_SNAKE_CASE__     				= ['''werewolf''']
     SCREAMING_SNAKE_CASE__     				= ['''weae     wolf''']
     # S = 1, D = 1, I = 0, N = 8, CER = 0.25
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.25 ) < 1E-6 )

     # consecutive whitespaces case 1
     SCREAMING_SNAKE_CASE__     				= ['''were wolf''']
     SCREAMING_SNAKE_CASE__     				= ['''were               wolf''']
     # S = 0, D = 0, I = 0, N = 9, CER = 0
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.0 ) < 1E-6 )

     # consecutive whitespaces case 2
     SCREAMING_SNAKE_CASE__     				= ['''were   wolf''']
     SCREAMING_SNAKE_CASE__     				= ['''were               wolf''']
     # S = 0, D = 0, I = 0, N = 9, CER = 0
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.0 ) < 1E-6 )




   def       __a		(       self     :							int ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''werewolf''']
     SCREAMING_SNAKE_CASE__     				= ['''weaewolf''']
     # S = 1, D = 0, I = 0, N = 8, CER = 0.125
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.1_25 ) < 1E-6 )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''werewolf''']
     SCREAMING_SNAKE_CASE__     				= ['''wereawolf''']
     # S = 0, D = 1, I = 0, N = 8, CER = 0.125
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.1_25 ) < 1E-6 )




   def       __a		(       self     :							List[str] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''werewolf''']
     SCREAMING_SNAKE_CASE__     				= ['''wereolf''']
     # S = 0, D = 0, I = 1, N = 8, CER = 0.125
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.1_25 ) < 1E-6 )




   def       __a		(       self     :							List[str] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''werewolf''']
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertEqual(_UpperCAmelCase			,      0.0 )




   def       __a		(       self     :							Union[str, Any] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''werewolf''', '''I am your father''']
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertEqual(_UpperCAmelCase			,      0.0 )

     SCREAMING_SNAKE_CASE__     				= ['''werewolf''', '''I am your father''', '''doge''']
     SCREAMING_SNAKE_CASE__     				= ['''werxwolf''', '''I       am your father''', '''doge''']
     # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.03_57_14_28 ) < 1E-6 )




   def       __a		(       self     :							int ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''My hovercraft''', '''is full of eels''']
     SCREAMING_SNAKE_CASE__     				= ['''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__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase			,      concatenate_texts=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.07_14_28 ) < 1E-6 )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''我能吞下玻璃而不伤身体''']
     SCREAMING_SNAKE_CASE__     				= [''' 能吞虾玻璃而 不霜身体啦''']
     # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45 ) < 1E-6 )

     SCREAMING_SNAKE_CASE__     				= ['''我能吞下玻璃''', '''而不伤身体''']
     SCREAMING_SNAKE_CASE__     				= ['''我    能 吞 下 玻 璃''', '''而不伤身体''']
     # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45_45 ) < 1E-6 )

     SCREAMING_SNAKE_CASE__     				= ['''我能吞下玻璃而不伤身体''']
     SCREAMING_SNAKE_CASE__     				= cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )
     self.assertFalse(_UpperCAmelCase			,      0.0 )




   def       __a		(       self     :							Union[str, Any] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= ['''''']
     SCREAMING_SNAKE_CASE__     				= ['''Hypothesis''']
     with self.assertRaises(_UpperCAmelCase ):
       cer.compute(predictions=_UpperCAmelCase			,      references=_UpperCAmelCase )


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








'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


UpperCamelCase_					=				{
    "configuration_flava": [
        "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "FlavaConfig",
        "FlavaImageCodebookConfig",
        "FlavaImageConfig",
        "FlavaMultimodalConfig",
        "FlavaTextConfig",
    ],
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCamelCase_					=				["FlavaFeatureExtractor"]
  UpperCamelCase_					=				["FlavaImageProcessor"]
  UpperCamelCase_					=				["FlavaProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCamelCase_					=				[
      "FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST",
      "FlavaForPreTraining",
      "FlavaImageCodebook",
      "FlavaImageModel",
      "FlavaModel",
      "FlavaMultimodalModel",
      "FlavaPreTrainedModel",
      "FlavaTextModel",
  ]

if TYPE_CHECKING:
  from .configuration_flava import (
      FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP,
      FlavaConfig,
      FlavaImageCodebookConfig,
      FlavaImageConfig,
      FlavaMultimodalConfig,
      FlavaTextConfig,
  )

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_flava import FlavaFeatureExtractor
    from .image_processing_flava import FlavaImageProcessor
    from .processing_flava import FlavaProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flava import (
        FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST,
        FlavaForPreTraining,
        FlavaImageCodebook,
        FlavaImageModel,
        FlavaModel,
        FlavaMultimodalModel,
        FlavaPreTrainedModel,
        FlavaTextModel,
    )

else:
  import sys

  UpperCamelCase_					=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)