





import unittest

from cer import CER


_a									=				CER()






class  __A   (   unittest.TestCase			):

			'''simple docstring'''







			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["White House"]
				lowerCamelCase__        =		["white house"]
				# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.18_1818_1818							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["were wolf"]
				lowerCamelCase__        =		["werewolf"]
				# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.111_1111							) < 1E-6							)

				lowerCamelCase__        =		["werewolf"]
				lowerCamelCase__        =		["weae     wolf"]
				# S = 1, D = 1, I = 0, N = 8, CER = 0.25
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.25							) < 1E-6							)

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

				# consecutive whitespaces case 2
				lowerCamelCase__        =		["were   wolf"]
				lowerCamelCase__        =		["were               wolf"]
				# S = 0, D = 0, I = 0, N = 9, CER = 0
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.0							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["werewolf"]
				lowerCamelCase__        =		["weaewolf"]
				# S = 1, D = 0, I = 0, N = 8, CER = 0.125
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.125							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["werewolf"]
				lowerCamelCase__        =		["wereawolf"]
				# S = 0, D = 1, I = 0, N = 8, CER = 0.125
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.125							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["werewolf"]
				lowerCamelCase__        =		["wereolf"]
				# S = 0, D = 0, I = 1, N = 8, CER = 0.125
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.125							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["werewolf"]
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertEqual(__lowerCAmelCase	,  0.0							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["werewolf", "I am your father"]
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertEqual(__lowerCAmelCase	,  0.0							)

				lowerCamelCase__        =		["werewolf", "I am your father", "doge"]
				lowerCamelCase__        =		["werxwolf", "I       am your father", "doge"]
				# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.0357_1428							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		["My hovercraft", "is full of eels"]
				lowerCamelCase__        =		["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__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase	,  concatenate_texts=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.07_1428							) < 1E-6							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







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

				lowerCamelCase__        =		["我能吞下玻璃", "而不伤身体"]
				lowerCamelCase__        =		["我    能 吞 下 玻 璃", "而不伤身体"]
				# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertTrue(abs(char_error_rate - 0.4545_4545_4545							) < 1E-6							)

				lowerCamelCase__        =		["我能吞下玻璃而不伤身体"]
				lowerCamelCase__        =		cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)
				self.assertFalse(__lowerCAmelCase	,  0.0							)





			def 		__lowerCamelCase    (   self							):



				'''simple docstring'''







				lowerCamelCase__        =		[""]
				lowerCamelCase__        =		["Hypothesis"]
				with self.assertRaises(__lowerCAmelCase							):
					cer.compute(predictions=__lowerCAmelCase	,  references=__lowerCAmelCase							)


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













import warnings

from .generation import FlaxGenerationMixin






class  __A   (   lowerCAmelCase			):

			'''simple docstring'''







			warnings.warn(
			    """Importing `FlaxGenerationMixin` from `src/transformers/generation_flax_utils.py` is deprecated and will """
			    """be removed in Transformers v5. Import as `from transformers import FlaxGenerationMixin` instead."""      ,    lowerCAmelCase      ,    )



