


"""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'''

import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput





@dataclass
class 				lowercase    (    __lowerCamelCase			):
   lowerCamelCase_            =42
   lowerCamelCase_            =None
   lowerCamelCase_            =None





class 				lowercase    (    unittest.TestCase			):


   def __UpperCAmelCase							( self					:						Tuple)   ->       Dict:
         lowercase_     			=   ModelOutputTest(a=30)
         self.assertEqual(x.a ,		30)
         self.assertIsNone(x.b)
         self.assertIsNone(x.c)
         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   x.d


   def __UpperCAmelCase							( self					:						List[str])   ->       Union[str, Any]:
         lowercase_     			=   ModelOutputTest(a=30 ,		b=10)
         self.assertEqual(x[0] ,		30)
         self.assertEqual(x[1] ,		10)
         self.assertEqual(x[:2] ,		(30, 10))
         self.assertEqual(x[:] ,		(30, 10))

         lowercase_     			=   ModelOutputTest(a=30 ,		c=10)
         self.assertEqual(x[0] ,		30)
         self.assertEqual(x[1] ,		10)
         self.assertEqual(x[:2] ,		(30, 10))
         self.assertEqual(x[:] ,		(30, 10))


   def __UpperCAmelCase							( self					:						Union[str, Any])   ->       List[str]:
         lowercase_     			=   ModelOutputTest(a=30 ,		b=10)
         self.assertEqual(x["a"] ,		30)
         self.assertEqual(x["b"] ,		10)
         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   x["c"]

         lowercase_     			=   ModelOutputTest(a=30 ,		c=10)
         self.assertEqual(x["a"] ,		30)
         self.assertEqual(x["c"] ,		10)
         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   x["b"]


   def __UpperCAmelCase							( self					:						List[str])   ->       List[str]:
         lowercase_     			=   ModelOutputTest(a=30)
         self.assertEqual(list(x.keys()) ,		["a"])
         self.assertEqual(list(x.values()) ,		[30])
         self.assertEqual(list(x.items()) ,		[("a", 30)])
         self.assertEqual(list(__lowerCAmelCase) ,		["a"])

         lowercase_     			=   ModelOutputTest(a=30 ,		b=10)
         self.assertEqual(list(x.keys()) ,		["a", "b"])
         self.assertEqual(list(x.values()) ,		[30, 10])
         self.assertEqual(list(x.items()) ,		[("a", 30), ("b", 10)])
         self.assertEqual(list(__lowerCAmelCase) ,		["a", "b"])

         lowercase_     			=   ModelOutputTest(a=30 ,		c=10)
         self.assertEqual(list(x.keys()) ,		["a", "c"])
         self.assertEqual(list(x.values()) ,		[30, 10])
         self.assertEqual(list(x.items()) ,		[("a", 30), ("c", 10)])
         self.assertEqual(list(__lowerCAmelCase) ,		["a", "c"])

         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   x.update({"d": 20})
         with self.assertRaises(__lowerCAmelCase):
               del x["a"]
         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   x.pop("a")
         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   x.setdefault("d" ,		32)


   def __UpperCAmelCase							( self					:						List[Any])   ->       Optional[int]:
         lowercase_     			=   ModelOutputTest(a=30)
         lowercase_     			=   10
         self.assertEqual(x.a ,		10)
         self.assertEqual(x["a"] ,		10)


   def __UpperCAmelCase							( self					:						List[Any])   ->       Any:
         lowercase_     			=   ModelOutputTest(a=30)
         lowercase_     			=   10
         self.assertEqual(x.a ,		10)
         self.assertEqual(x["a"] ,		10)


   def __UpperCAmelCase							( self					:						Union[str, Any])   ->       List[Any]:
         lowercase_     			=   ModelOutputTest({"a": 30, "b": 10})
         self.assertEqual(list(x.keys()) ,		["a", "b"])
         self.assertEqual(x.a ,		30)
         self.assertEqual(x.b ,		10)


   def __UpperCAmelCase							( self					:						List[str])   ->       str:
         lowercase_     			=   ModelOutputTest([("a", 30), ("b", 10)])
         self.assertEqual(list(x.keys()) ,		["a", "b"])
         self.assertEqual(x.a ,		30)
         self.assertEqual(x.b ,		10)

         with self.assertRaises(__lowerCAmelCase):
               lowercase_     			=   ModelOutputTest([("a", 30), (10, 10)])

         lowercase_     			=   ModelOutputTest(a=(30, 30))
         self.assertEqual(list(x.keys()) ,		["a"])
         self.assertEqual(x.a ,		(30, 30))






