


import unittest

from cer import CER


lowerCamelCase		      = CER()




class A						(     unittest.TestCase  ):






						def  lowerCamelCase (      self		:  List[str]				)      ->		Dict:
													"""simple docstring"""




													_lowerCamelCase :	Dict						=['White House']
													_lowerCamelCase :	Tuple						=['white house']
													# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
													_lowerCamelCase :	Dict						=cer.compute(predictions=a_    ,     references=a_				)
													self.assertTrue(abs(char_error_rate - 0.1818181818				) < 1E-6				)






						def  lowerCamelCase (      self		:  Union[str, Any]				)      ->		List[Any]:
													"""simple docstring"""




													_lowerCamelCase :	List[str]						=['were wolf']
													_lowerCamelCase :	List[str]						=['werewolf']
													# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
													_lowerCamelCase :	Dict						=cer.compute(predictions=a_    ,     references=a_				)
													self.assertTrue(abs(char_error_rate - 0.1111111				) < 1E-6				)

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

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

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






						def  lowerCamelCase (      self		:  Optional[Any]				)      ->		Optional[int]:
													"""simple docstring"""




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






						def  lowerCamelCase (      self		:  Tuple				)      ->		Optional[int]:
													"""simple docstring"""




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






						def  lowerCamelCase (      self		:  Tuple				)      ->		Tuple:
													"""simple docstring"""




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






						def  lowerCamelCase (      self		:  List[Any]				)      ->		int:
													"""simple docstring"""




													_lowerCamelCase :	Any						=['werewolf']
													_lowerCamelCase :	Union[str, Any]						=cer.compute(predictions=a_    ,     references=a_				)
													self.assertEqual(a_    ,     0.0				)






						def  lowerCamelCase (      self		:  List[str]				)      ->		Dict:
													"""simple docstring"""




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

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






						def  lowerCamelCase (      self		:  Union[str, Any]				)      ->		Dict:
													"""simple docstring"""




													_lowerCamelCase :	int						=['My hovercraft', 'is full of eels']
													_lowerCamelCase :	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
													_lowerCamelCase :	Tuple						=cer.compute(predictions=a_    ,     references=a_    ,     concatenate_texts=a_				)
													self.assertTrue(abs(char_error_rate - 0.071428				) < 1E-6				)






						def  lowerCamelCase (      self		:  Optional[Any]				)      ->		List[Any]:
													"""simple docstring"""




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

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

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






						def  lowerCamelCase (      self		:  Optional[int]				)      ->		int:
													"""simple docstring"""




													_lowerCamelCase :	List[Any]						=['']
													_lowerCamelCase :	List[str]						=['Hypothesis']
													with self.assertRaises(a_				):
																				cer.compute(predictions=a_    ,     references=a_				)


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






from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import is_torch_available, is_transformers_available


if is_transformers_available() and is_torch_available():
 from .image_encoder import PaintByExampleImageEncoder
 from .pipeline_paint_by_example import PaintByExamplePipeline


