




"""simple docstring"""

import unittest

from cer import CER


__A							=     CER()
class      lowerCamelCase__      (					unittest.TestCase     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Any        =			["White House"]
					snake_case						:  Optional[int]        =			["white house"]
					# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
					snake_case						:  Any        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Any        =			["were wolf"]
					snake_case						:  Optional[Any]        =			["werewolf"]
					# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
					snake_case						:  str        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_11_11_11							) < 1E-6							)

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

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

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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			["werewolf"]
					snake_case						:  Optional[int]        =			["weaewolf"]
					# S = 1, D = 0, I = 0, N = 8, CER = 0.125
					snake_case						:  Optional[int]        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_25							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			["werewolf"]
					snake_case						:  Optional[Any]        =			["wereawolf"]
					# S = 0, D = 1, I = 0, N = 8, CER = 0.125
					snake_case						:  Optional[int]        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_25							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[str]        =			["werewolf"]
					snake_case						:  List[Any]        =			["wereolf"]
					# S = 0, D = 0, I = 1, N = 8, CER = 0.125
					snake_case						:  Tuple        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_25							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Dict        =			["werewolf"]
					snake_case						:  Dict        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertEqual(SCREAMING_SNAKE_CASE			,	0.0							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  str        =			["werewolf", "I am your father"]
					snake_case						:  Any        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertEqual(SCREAMING_SNAKE_CASE			,	0.0							)

					snake_case						:  List[Any]        =			["werewolf", "I am your father", "doge"]
					snake_case						:  List[str]        =			["werxwolf", "I       am your father", "doge"]
					# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
					snake_case						:  Tuple        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.03_57_14_28							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			["My hovercraft", "is full of eels"]
					snake_case						:  Union[str, 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
					snake_case						:  List[Any]        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE			,	concatenate_texts=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.07_14_28							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			["我能吞下玻璃而不伤身体"]
					snake_case						:  Union[str, Any]        =			[" 能吞虾玻璃而 不霜身体啦"]
					# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
					snake_case						:  Dict        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45							) < 1E-6							)

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

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



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[str]        =			[""]
					snake_case						:  Tuple        =			["Hypothesis"]
					with self.assertRaises(SCREAMING_SNAKE_CASE							):
							cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)


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







"""simple docstring"""

def 					UpperCamelCase__       (						lowercase__					:       int				):
		if not isinstance(lowercase__    ,       lowercase__				):
				raise ValueError("double_factorial() only accepts integral values"				)
		if n < 0:
				raise ValueError("double_factorial() not defined for negative values"				)
		return 1 if n <= 1 else n * double_factorial(n - 2				)


if __name__ == "__main__":
							import doctest

							doctest.testmod()

