

"""simple docstring"""





import unittest

from cer import CER


_SCREAMING_SNAKE_CASE       :  int        = CER()

class     __a   (      unittest.TestCase    ):

			"""simple docstring"""

			def    _lowerCAmelCase			(							self     :					Optional[int]						):
								UpperCamelCase__		:    Any         =['''White House''']
								UpperCamelCase__		:    Tuple         =['''white house''']
								# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
								UpperCamelCase__		:    Optional[int]         =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    _lowerCAmelCase			(							self     :					List[str]						):
								UpperCamelCase__		:    Tuple         =['''were wolf''']
								UpperCamelCase__		:    Union[str, Any]         =['''werewolf''']
								# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
								UpperCamelCase__		:    Union[str, Any]         =cer.compute(predictions=a_						,  references=a_						)
								self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1						) < 1e-6						)

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

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

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






			def    _lowerCAmelCase			(							self     :					Optional[Any]						):
								UpperCamelCase__		:    List[str]         =['''werewolf''']
								UpperCamelCase__		:    str         =['''weaewolf''']
								# S = 1, D = 0, I = 0, N = 8, CER = 0.125
								UpperCamelCase__		:    Tuple         =cer.compute(predictions=a_						,  references=a_						)
								self.assertTrue(abs(char_error_rate - 0.1_2_5						) < 1e-6						)






			def    _lowerCAmelCase			(							self     :					int						):
								UpperCamelCase__		:    Any         =['''werewolf''']
								UpperCamelCase__		:    Tuple         =['''wereawolf''']
								# S = 0, D = 1, I = 0, N = 8, CER = 0.125
								UpperCamelCase__		:    List[Any]         =cer.compute(predictions=a_						,  references=a_						)
								self.assertTrue(abs(char_error_rate - 0.1_2_5						) < 1e-6						)






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






			def    _lowerCAmelCase			(							self     :					Tuple						):
								UpperCamelCase__		:    Tuple         =['''werewolf''']
								UpperCamelCase__		:    Optional[int]         =cer.compute(predictions=a_						,  references=a_						)
								self.assertEqual(a_						,  0.0						)






			def    _lowerCAmelCase			(							self     :					Any						):
								UpperCamelCase__		:    Union[str, Any]         =['''werewolf''', '''I am your father''']
								UpperCamelCase__		:    Any         =cer.compute(predictions=a_						,  references=a_						)
								self.assertEqual(a_						,  0.0						)

								UpperCamelCase__		:    Tuple         =['''werewolf''', '''I am your father''', '''doge''']
								UpperCamelCase__		:    Tuple         =['''werxwolf''', '''I       am your father''', '''doge''']
								# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
								UpperCamelCase__		:    Optional[int]         =cer.compute(predictions=a_						,  references=a_						)
								self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8						) < 1e-6						)






			def    _lowerCAmelCase			(							self     :					Dict						):
								UpperCamelCase__		:    Optional[Any]         =['''My hovercraft''', '''is full of eels''']
								UpperCamelCase__		:    Any         =['''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
								UpperCamelCase__		:    Union[str, Any]         =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    _lowerCAmelCase			(							self     :					Optional[int]						):
								UpperCamelCase__		:    List[Any]         =['''我能吞下玻璃而不伤身体''']
								UpperCamelCase__		:    int         =[''' 能吞虾玻璃而 不霜身体啦''']
								# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
								UpperCamelCase__		:    str         =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						)

								UpperCamelCase__		:    int         =['''我能吞下玻璃''', '''而不伤身体''']
								UpperCamelCase__		:    Optional[Any]         =['''我    能 吞 下 玻 璃''', '''而不伤身体''']
								# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
								UpperCamelCase__		:    Dict         =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						)

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






			def    _lowerCAmelCase			(							self     :					Union[str, Any]						):
								UpperCamelCase__		:    int         =['''''']
								UpperCamelCase__		:    Dict         =['''Hypothesis''']
								with self.assertRaises(a_						):
													cer.compute(predictions=a_						,  references=a_						)


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





"""simple docstring"""





import unittest

from transformers.image_processing_utils import get_size_dict

class     __a   (      unittest.TestCase    ):

			"""simple docstring"""

			def    _lowerCAmelCase			(							self     :					Dict						):
								# Test a dict with the wrong keys raises an error
								UpperCamelCase__		:    str         ={'''wrong_key''': 224}
								with self.assertRaises(lowercase_						):
													get_size_dict(lowercase_						)

								UpperCamelCase__		:    Any         ={'''height''': 224}
								with self.assertRaises(lowercase_						):
													get_size_dict(lowercase_						)

								UpperCamelCase__		:    List[str]         ={'''width''': 224, '''shortest_edge''': 224}
								with self.assertRaises(lowercase_						):
													get_size_dict(lowercase_						)

								# Test a dict with the correct keys is returned as is
								UpperCamelCase__		:    int         ={'''height''': 224, '''width''': 224}
								UpperCamelCase__		:    str         =get_size_dict(lowercase_						)
								self.assertEqual(lowercase_						,  lowercase_						)

								UpperCamelCase__		:    List[Any]         ={'''shortest_edge''': 224}
								UpperCamelCase__		:    List[str]         =get_size_dict(lowercase_						)
								self.assertEqual(lowercase_						,  {'''shortest_edge''': 224}						)

								UpperCamelCase__		:    List[Any]         ={'''longest_edge''': 224, '''shortest_edge''': 224}
								UpperCamelCase__		:    Tuple         =get_size_dict(lowercase_						)
								self.assertEqual(lowercase_						,  {'''longest_edge''': 224, '''shortest_edge''': 224}						)

								# Test a single int value which  represents (size, size)
								UpperCamelCase__		:    Optional[int]         =get_size_dict(224						)
								self.assertEqual(lowercase_						,  {'''height''': 224, '''width''': 224}						)

								# Test a single int value which represents the shortest edge
								UpperCamelCase__		:    str         =get_size_dict(224						,  default_to_square=lowercase_						)
								self.assertEqual(lowercase_						,  {'''shortest_edge''': 224}						)

								# Test a tuple of ints which represents (height, width)
								UpperCamelCase__		:    List[str]         =get_size_dict((150, 200)						)
								self.assertEqual(lowercase_						,  {'''height''': 150, '''width''': 200}						)

								# Test a tuple of ints which represents (width, height)
								UpperCamelCase__		:    Optional[int]         =get_size_dict((150, 200)						,  height_width_order=lowercase_						)
								self.assertEqual(lowercase_						,  {'''height''': 200, '''width''': 150}						)

								# Test an int representing the shortest edge and max_size which represents the longest edge
								UpperCamelCase__		:    int         =get_size_dict(224						,  max_size=256						,  default_to_square=lowercase_						)
								self.assertEqual(lowercase_						,  {'''shortest_edge''': 224, '''longest_edge''': 256}						)

								# Test int with default_to_square=True and max_size fails
								with self.assertRaises(lowercase_						):
													get_size_dict(224						,  max_size=256						,  default_to_square=lowercase_						)


