


"""simple docstring"""
import unittest

from cer import CER


SCREAMING_SNAKE_CASE					:       Optional[Any]							   =							CER()



class      _UpperCAmelCase					(				unittest.TestCase							):






		'''simple docstring'''

		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		List[str]         =							['''White House''']
			__snake_case      :		str         =							['''white house''']
			# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
			__snake_case      :		Union[str, Any]         =							cer.compute(predictions=a_							,			references=a_   )
			self.assertTrue(abs(char_error_rate - 0.18_1818_1818   ) < 1E-6   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		str         =							['''were wolf''']
			__snake_case      :		Tuple         =							['''werewolf''']
			# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
			__snake_case      :		Optional[Any]         =							cer.compute(predictions=a_							,			references=a_   )
			self.assertTrue(abs(char_error_rate - 0.111_1111   ) < 1E-6   )

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

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

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Tuple         =							['''werewolf''']
			__snake_case      :		Optional[Any]         =							['''wereolf''']
			# S = 0, D = 0, I = 1, N = 8, CER = 0.125
			__snake_case      :		Dict         =							cer.compute(predictions=a_							,			references=a_   )
			self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		str         =							['''werewolf''']
			__snake_case      :		int         =							cer.compute(predictions=a_							,			references=a_   )
			self.assertEqual(a_							,			0.0   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		Tuple         =							['''My hovercraft''', '''is full of eels''']
			__snake_case      :		List[str]         =							['''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=a_							,			references=a_							,			concatenate_texts=a_   )
			self.assertTrue(abs(char_error_rate - 0.07_1428   ) < 1E-6   )



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

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

			__snake_case      :		Tuple         =							['''我能吞下玻璃''', '''而不伤身体''']
			__snake_case      :		Tuple         =							['''我    能 吞 下 玻 璃''', '''而不伤身体''']
			# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
			__snake_case      :		Union[str, Any]         =							cer.compute(predictions=a_							,			references=a_   )
			self.assertTrue(abs(char_error_rate - 0.4545_4545_4545   ) < 1E-6   )

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



		def 							SCREAMING_SNAKE_CASE    (self   ):





			'''simple docstring'''

			__snake_case      :		str         =							['''''']
			__snake_case      :		int         =							['''Hypothesis''']
			with self.assertRaises(a_   ):
				cer.compute(predictions=a_							,			references=a_   )


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









"""simple docstring"""
SCREAMING_SNAKE_CASE					:       List[Any]							   =							1000






def 						lowercase				(	_snake_case		: float	)	->float:
	"""simple docstring"""





	return x * x






def 						lowercase				(	_snake_case		: Union[str, Any]	,  _snake_case		: float	,  _snake_case		: float	,  _snake_case		: int = 4	)	->float:
	"""simple docstring"""





	assert callable(
	    _snake_case	), f"""the function(object) passed should be callable your input : {function}"""
	assert isinstance(_snake_case	,  (float, int)	), f"""a should be float or integer your input : {a}"""
	assert isinstance(function(_snake_case	)	,  (float, int)	), (
	    "the function should return integer or float return type of your function, "
	    f"""{type(_snake_case	)}"""
	)
	assert isinstance(_snake_case	,  (float, int)	), f"""b should be float or integer your input : {b}"""
	assert (
	    isinstance(_snake_case	,  _snake_case	) and precision > 0
	), f"""precision should be positive integer your input : {precision}"""

	# just applying the formula of simpson for approximate integration written in
	# mentioned article in first comment of this file and above this function

	__snake_case      :		Tuple         =							(b - a) / N_STEPS
	__snake_case      :		Union[str, Any]         =							function(_snake_case	) + function(_snake_case	)

	for i in range(1	,  _snake_case	):
		__snake_case      :		List[str]         =							a + h * i
		result += function(_snake_case	) * (4 if i % 2 else 2)

	result *= h / 3
	return round(_snake_case	,  _snake_case	)


if __name__ == "__main__":
			import doctest

			doctest.testmod()





