

import unittest

from cer import CER


__a						:str            = CER()

class      _a				( unittest.TestCase							):





      def 		__A  (      self       :							List[str]  ):
            A_	     =							["White House"]
            A_	     =							["white house"]
            # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.1_818_181_818  ) < 1E-6  )





      def 		__A  (      self       :							Union[str, Any]  ):
            A_	     =							["were wolf"]
            A_	     =							["werewolf"]
            # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.1_111_111  ) < 1E-6  )

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

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

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





      def 		__A  (      self       :							List[Any]  ):
            A_	     =							["werewolf"]
            A_	     =							["weaewolf"]
            # S = 1, D = 0, I = 0, N = 8, CER = 0.125
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.125  ) < 1E-6  )





      def 		__A  (      self       :							Dict  ):
            A_	     =							["werewolf"]
            A_	     =							["wereawolf"]
            # S = 0, D = 1, I = 0, N = 8, CER = 0.125
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.125  ) < 1E-6  )





      def 		__A  (      self       :							Optional[Any]  ):
            A_	     =							["werewolf"]
            A_	     =							["wereolf"]
            # S = 0, D = 0, I = 1, N = 8, CER = 0.125
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.125  ) < 1E-6  )





      def 		__A  (      self       :							Any  ):
            A_	     =							["werewolf"]
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertEqual(UpperCAmelCase	, 0.0  )





      def 		__A  (      self       :							Union[str, Any]  ):
            A_	     =							["werewolf", "I am your father"]
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertEqual(UpperCAmelCase	, 0.0  )

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





      def 		__A  (      self       :							str  ):
            A_	     =							["My hovercraft", "is full of eels"]
            A_	     =							["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
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase	, concatenate_texts=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.071_428  ) < 1E-6  )





      def 		__A  (      self       :							List[str]  ):
            A_	     =							["我能吞下玻璃而不伤身体"]
            A_	     =							[" 能吞虾玻璃而 不霜身体啦"]
            # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
            A_	     =							cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )
            self.assertTrue(abs(char_error_rate - 0.4_545_454_545  ) < 1E-6  )

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

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







      def 		__A  (      self       :							Optional[int]  ):
            A_	     =							[""]
            A_	     =							["Hypothesis"]
            with self.assertRaises(UpperCAmelCase  ):
                  cer.compute(predictions=UpperCAmelCase	, references=UpperCAmelCase  )


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


import warnings

from ...utils import logging
from .image_processing_mobilenet_va import MobileNetVaImageProcessor


__a						:Optional[int]            = logging.get_logger(__name__)

class      _a				( snake_case_							):




      """simple docstring"""

      def __init__(      self       :							List[Any]	, *UpperCAmelCase       :							Any	, **UpperCAmelCase       :							int  ):
            warnings.warn(
                "The class MobileNetV2FeatureExtractor is deprecated and will be removed in version 5 of Transformers."
                " Please use MobileNetV2ImageProcessor instead."	, UpperCAmelCase	, )
            super().__init__(*UpperCAmelCase	, **UpperCAmelCase  )