




'''simple docstring'''






import unittest

from cer import CER


lowercase	:      int				=       CER()

class   SCREAMING_SNAKE_CASE_		(       unittest.TestCase				):



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Optional[int]						=      ['''White House''']
        lowercase  :		str						=      ['''white house''']
        # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
        lowercase  :		List[str]						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8 ) < 1E-6 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Any						=      ['''were wolf''']
        lowercase  :		Optional[Any]						=      ['''werewolf''']
        # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
        lowercase  :		int						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1 ) < 1E-6 )

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

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

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



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		int						=      ['''werewolf''']
        lowercase  :		Any						=      ['''weaewolf''']
        # S = 1, D = 0, I = 0, N = 8, CER = 0.125
        lowercase  :		Tuple						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.1_2_5 ) < 1E-6 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Union[str, Any]						=      ['''werewolf''']
        lowercase  :		Optional[int]						=      ['''wereawolf''']
        # S = 0, D = 1, I = 0, N = 8, CER = 0.125
        lowercase  :		Any						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.1_2_5 ) < 1E-6 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		List[str]						=      ['''werewolf''']
        lowercase  :		Tuple						=      ['''wereolf''']
        # S = 0, D = 0, I = 1, N = 8, CER = 0.125
        lowercase  :		Dict						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.1_2_5 ) < 1E-6 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		List[str]						=      ['''werewolf''']
        lowercase  :		Dict						=      cer.compute(predictions=A   ,		references=A )
        self.assertEqual(A   ,		0.0 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		List[str]						=      ['''werewolf''', '''I am your father''']
        lowercase  :		int						=      cer.compute(predictions=A   ,		references=A )
        self.assertEqual(A   ,		0.0 )

        lowercase  :		Dict						=      ['''werewolf''', '''I am your father''', '''doge''']
        lowercase  :		Tuple						=      ['''werxwolf''', '''I       am your father''', '''doge''']
        # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
        lowercase  :		str						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8 ) < 1E-6 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		str						=      ['''My hovercraft''', '''is full of eels''']
        lowercase  :		int						=      ['''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
        lowercase  :		Tuple						=      cer.compute(predictions=A   ,		references=A   ,		concatenate_texts=A )
        self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8 ) < 1E-6 )



 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Optional[int]						=      ['''我能吞下玻璃而不伤身体''']
        lowercase  :		List[Any]						=      [''' 能吞虾玻璃而 不霜身体啦''']
        # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
        lowercase  :		int						=      cer.compute(predictions=A   ,		references=A )
        self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5 ) < 1E-6 )

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

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





 def    SCREAMING_SNAKE_CASE(  self ):






        '''simple docstring'''




        lowercase  :		Optional[int]						=      ['''''']
        lowercase  :		Union[str, Any]						=      ['''Hypothesis''']
        with self.assertRaises(A ):
               cer.compute(predictions=A   ,		references=A )


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










'''simple docstring'''






import math
from timeit import timeit




def 		a_( lowerCamelCase      )				->int:






       '''simple docstring'''




       lowercase  :		Dict						=      0
       lowercase  :		Union[str, Any]						=      abs(lowerCamelCase      )
       while True:
              lowercase  :		List[Any]						=      n // 10
              digits += 1
              if n == 0:
                     break
       return digits




def 		a_( lowerCamelCase      )				->int:






       '''simple docstring'''




       return 1 if n == 0 else math.floor(math.log(abs(lowerCamelCase      )   ,				10      ) + 1      )




def 		a_( lowerCamelCase      )				->int:






       '''simple docstring'''




       return len(str(abs(lowerCamelCase      )      )      )




def 		a_( )				->None:






       '''simple docstring'''




       from collections.abc import Callable

       def benchmark_a_function(lowerCamelCase   ,				lowerCamelCase      ) -> None:
              lowercase  :		str						=      f"""{func.__name__}({value})"""
              lowercase  :		Optional[Any]						=      timeit(f"""__main__.{call}"""   ,				setup='''import __main__'''      )
              print(f"""{call}: {func(lowerCamelCase      )} -- {timing} seconds"""      )

       for value in (26_2144, 1125_8999_0684_2624, 126_7650_6002_2822_9401_4967_0320_5376):
              for func in (num_digits, num_digits_fast, num_digits_faster):
                     benchmark_a_function(lowerCamelCase   ,				lowerCamelCase      )
              print()


if __name__ == "__main__":
      import doctest

      doctest.testmod()
      benchmark()




