


"""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()









def   snake_case_    (			__lowercase      ,							__lowercase      ,							__lowercase      ,							__lowercase							):
   UpperCAmelCase_				:   Optional[int]							= int((lower_bound + upper_bound) // 2							)
   if array[r] == value:
      return r
   if lower_bound >= upper_bound:
      return -1
   if array[r] < value:
      return binary_search(__lowercase      ,							r + 1      ,							__lowercase      ,							__lowercase							)
   else:
      return binary_search(__lowercase      ,							__lowercase      ,							r - 1      ,							__lowercase							)
def   snake_case_    (			__lowercase      ,							__lowercase							):
   UpperCAmelCase_				:   Union[str, Any]							= 0
   if matrix[index][0] == value:
      return [index, 0]
   while index < len(__lowercase							) and matrix[index][0] < value:
      UpperCAmelCase_				:   str							= binary_search(matrix[index]      ,							0      ,							len(matrix[index]							) - 1      ,							__lowercase							)
      if r != -1:
         return [index, r]
      index += 1
   return [-1, -1]


if __name__ == "__main__":
       import doctest

       doctest.testmod()