

'''simple docstring'''
import unittest

from cer import CER


_lowerCamelCase	 =			CER()
class  _snake_case						(unittest.TestCase):






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Dict      =   ["White House"]
				UpperCAmelCase_			:	Union[str, Any]      =   ["white house"]
				# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
				UpperCAmelCase_			:	Optional[Any]      =   cer.compute(predictions=_snake_case       ,references=_snake_case			)
				self.assertTrue(abs(char_error_rate - 0.1818181818			) < 1E-6			)






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

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

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

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






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






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Any      =   ["werewolf"]
				UpperCAmelCase_			:	Dict      =   ["wereawolf"]
				# S = 0, D = 1, I = 0, N = 8, CER = 0.125
				UpperCAmelCase_			:	List[Any]      =   cer.compute(predictions=_snake_case       ,references=_snake_case			)
				self.assertTrue(abs(char_error_rate - 0.125			) < 1E-6			)






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	str      =   ["werewolf"]
				UpperCAmelCase_			:	int      =   ["wereolf"]
				# S = 0, D = 0, I = 1, N = 8, CER = 0.125
				UpperCAmelCase_			:	str      =   cer.compute(predictions=_snake_case       ,references=_snake_case			)
				self.assertTrue(abs(char_error_rate - 0.125			) < 1E-6			)






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	List[Any]      =   ["werewolf"]
				UpperCAmelCase_			:	int      =   cer.compute(predictions=_snake_case       ,references=_snake_case			)
				self.assertEqual(_snake_case       ,0.0			)






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Optional[int]      =   ["werewolf", "I am your father"]
				UpperCAmelCase_			:	List[Any]      =   cer.compute(predictions=_snake_case       ,references=_snake_case			)
				self.assertEqual(_snake_case       ,0.0			)

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






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Any      =   ["My hovercraft", "is full of eels"]
				UpperCAmelCase_			:	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
				UpperCAmelCase_			:	int      =   cer.compute(predictions=_snake_case       ,references=_snake_case       ,concatenate_texts=_snake_case			)
				self.assertTrue(abs(char_error_rate - 0.071428			) < 1E-6			)






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Tuple      =   ["我能吞下玻璃而不伤身体"]
				UpperCAmelCase_			:	Any      =   [" 能吞虾玻璃而 不霜身体啦"]
				# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
				UpperCAmelCase_			:	int      =   cer.compute(predictions=_snake_case       ,references=_snake_case			)
				self.assertTrue(abs(char_error_rate - 0.4545454545			) < 1E-6			)

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

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






			def 						UpperCamelCase__				(   self			):
				UpperCAmelCase_			:	Union[str, Any]      =   [""]
				UpperCAmelCase_			:	Any      =   ["Hypothesis"]
				with self.assertRaises(_snake_case			):
					cer.compute(predictions=_snake_case       ,references=_snake_case			)


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












"""simple docstring"""
from cva import destroyAllWindows, imread, imshow, waitKey






def        lowerCamelCase_  (						_lowerCamelCase			,   _lowerCamelCase				):
 lowerCamelCase__				,     lowerCamelCase__     :			Optional[Any]     				=						img.shape[0], img.shape[1]

 def to_grayscale(_lowerCamelCase			,   _lowerCamelCase			,   _lowerCamelCase				):
  return 0.2_126 * red + 0.587 * green + 0.114 * blue

 def normalize(_lowerCamelCase				):
  return min(_lowerCamelCase			,   255				)

 for i in range(_lowerCamelCase				):
  for j in range(_lowerCamelCase				):
   lowerCamelCase__     :			List[Any]     				=						int(to_grayscale(*img[i][j]				)				)
   lowerCamelCase__     :			Optional[int]     				=						[
       normalize(_lowerCamelCase				),
       normalize(greyscale + factor				),
       normalize(greyscale + 2 * factor				),
   ]

 return img


if __name__ == "__main__":
      # read original image
      A_			: List[str]				=			{
          percentage: imread("image_data/lena.jpg", 1) for percentage in (10, 20, 30, 40)
      }

      for percentage, img in images.items():
            make_sepia(img, percentage)

      for percentage, img in images.items():
            imshow(f"Original image with sepia (factor: {percentage})", img)

      waitKey(0)
      destroyAllWindows()

