



import unittest

from cer import CER


A__						:						List[str]          =      CER()



class        __snake_case		(  unittest.TestCase		):




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




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

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

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

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




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




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




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




							def      UpperCAmelCase__    ( self  : Optional[int]):
									lowerCAmelCase_    :  Union[str, Any]             =				['''werewolf''']
									lowerCAmelCase_    :  Optional[int]             =				cer.compute(predictions=A_       ,       references=A_)
									self.assertEqual(A_       ,       0.0)




							def      UpperCAmelCase__    ( self  : Optional[int]):
									lowerCAmelCase_    :  Optional[int]             =				['''werewolf''', '''I am your father''']
									lowerCAmelCase_    :  List[str]             =				cer.compute(predictions=A_       ,       references=A_)
									self.assertEqual(A_       ,       0.0)

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




							def      UpperCAmelCase__    ( self  : List[Any]):
									lowerCAmelCase_    :  Optional[int]             =				['''My hovercraft''', '''is full of eels''']
									lowerCAmelCase_    :  Optional[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
									lowerCAmelCase_    :  List[str]             =				cer.compute(predictions=A_       ,       references=A_       ,       concatenate_texts=A_)
									self.assertTrue(abs(char_error_rate - 0.07_1428) < 1e-6)




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

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

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







							def      UpperCAmelCase__    ( self  : List[Any]):
									lowerCAmelCase_    :  Union[str, Any]             =				['''''']
									lowerCAmelCase_    :  Optional[int]             =				['''Hypothesis''']
									with self.assertRaises(A_):
											cer.compute(predictions=A_       ,       references=A_)


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










import warnings

from ...utils import logging
from .image_processing_detr import DetrImageProcessor


A__						:						str          =      logging.get_logger(__name__)



class        __snake_case		(  UpperCamelCase_		):




							def __init__( self  : Union[str, Any]       ,       *A_  : int       ,       **A_  : List[str]):
									warnings.warn(
									    '''The class DetrFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
									    ''' Please use DetrImageProcessor instead.'''       ,       A_       ,       )
									super().__init__(*A_       ,       **A_)





