"""simple docstring"""







import unittest

from cer import CER


lowerCamelCase      : Optional[Any]       =CER()






class 							__snake_case(					unittest.TestCase	):


    '''simple docstring'''





    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[Any]								=		['White House']
         __A					:					List[Any]								=		['white house']
         # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
         __A					:					List[str]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18	) < 1e-6	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Tuple								=		['were wolf']
         __A					:					List[str]								=		['werewolf']
         # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
         __A					:					Dict								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.1_11_11_11	) < 1e-6	)

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

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

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




         '''simple docstring'''



         __A					:					Dict								=		['werewolf']
         __A					:					Dict								=		['weaewolf']
         # S = 1, D = 0, I = 0, N = 8, CER = 0.125
         __A					:					List[Any]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.1_25	) < 1e-6	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[int]								=		['werewolf']
         __A					:					List[Any]								=		['wereawolf']
         # S = 0, D = 1, I = 0, N = 8, CER = 0.125
         __A					:					List[Any]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.1_25	) < 1e-6	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Union[str, Any]								=		['werewolf']
         __A					:					Tuple								=		['wereolf']
         # S = 0, D = 0, I = 1, N = 8, CER = 0.125
         __A					:					Tuple								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.1_25	) < 1e-6	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[int]								=		['werewolf']
         __A					:					Optional[Any]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertEqual(__lowerCamelCase					,       0.0	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[Any]								=		['werewolf', 'I am your father']
         __A					:					Optional[Any]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertEqual(__lowerCamelCase					,       0.0	)

         __A					:					List[Any]								=		['werewolf', 'I am your father', 'doge']
         __A					:					Dict								=		['werxwolf', 'I       am your father', 'doge']
         # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
         __A					:					Union[str, Any]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.03_57_14_28	) < 1e-6	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Optional[Any]								=		['My hovercraft', 'is full of eels']
         __A					:					Dict								=		['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					:					Any								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase					,       concatenate_texts=__lowerCamelCase	)
         self.assertTrue(abs(char_error_rate - 0.07_14_28	) < 1e-6	)
    def 						_a							(  self	):




         '''simple docstring'''



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

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

         __A					:					Optional[int]								=		['我能吞下玻璃而不伤身体']
         __A					:					Optional[int]								=		cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)
         self.assertFalse(__lowerCamelCase					,       0.0	)

    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[str]								=		['']
         __A					:					List[Any]								=		['Hypothesis']
         with self.assertRaises(__lowerCamelCase	):
              cer.compute(predictions=__lowerCamelCase					,       references=__lowerCamelCase	)


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




"""simple docstring"""







def 						_lowercase				(  _SCREAMING_SNAKE_CASE				:				list[int]						)    ->     int:







     '''simple docstring'''


     if not isinstance(_SCREAMING_SNAKE_CASE  ,       _SCREAMING_SNAKE_CASE						) or not all(
         isinstance(_SCREAMING_SNAKE_CASE  ,       _SCREAMING_SNAKE_CASE						) and item >= 0 for item in citations						):
          raise ValueError('The citations should be a list of non negative integers.'						)

     citations.sort()
     __A					:					Any								=		len(_SCREAMING_SNAKE_CASE						)

     for i in range(_SCREAMING_SNAKE_CASE						):
          if citations[len_citations - 1 - i] <= i:
               return i

     return len_citations


if __name__ == "__main__":
       import doctest

       doctest.testmod()



