

import unittest

from cer import CER


_a:			Optional[Any]       							=	CER()

class   __UpperCamelCase			(    unittest.TestCase  ):




	def 					__A    (						self		:  str							):


		'''simple docstring'''







		UpperCAmelCase_				 =	["White House"]
		UpperCAmelCase_				 =	["white house"]
		# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
		UpperCAmelCase_				 =	cer.compute(predictions=_A						,		references=_A							)
		self.assertTrue(abs(char_error_rate - 0.1_818_181_818							) < 1e-6							)




	def 					__A    (						self		:  Any							):


		'''simple docstring'''







		UpperCAmelCase_				 =	["were wolf"]
		UpperCAmelCase_				 =	["werewolf"]
		# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
		UpperCAmelCase_				 =	cer.compute(predictions=_A						,		references=_A							)
		self.assertTrue(abs(char_error_rate - 0.1_111_111							) < 1e-6							)

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

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

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




	def 					__A    (						self		:  List[Any]							):


		'''simple docstring'''







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




	def 					__A    (						self		:  Any							):


		'''simple docstring'''







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




	def 					__A    (						self		:  str							):


		'''simple docstring'''







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




	def 					__A    (						self		:  int							):


		'''simple docstring'''







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




	def 					__A    (						self		:  int							):


		'''simple docstring'''







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

		UpperCAmelCase_				 =	["werewolf", "I am your father", "doge"]
		UpperCAmelCase_				 =	["werxwolf", "I       am your father", "doge"]
		# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
		UpperCAmelCase_				 =	cer.compute(predictions=_A						,		references=_A							)
		self.assertTrue(abs(char_error_rate - 0.03_571_428							) < 1e-6							)




	def 					__A    (						self		:  Any							):


		'''simple docstring'''







		UpperCAmelCase_				 =	["My hovercraft", "is full of eels"]
		UpperCAmelCase_				 =	["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_				 =	cer.compute(predictions=_A						,		references=_A						,		concatenate_texts=_A							)
		self.assertTrue(abs(char_error_rate - 0.071_428							) < 1e-6							)




	def 					__A    (						self		:  Tuple							):


		'''simple docstring'''







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

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

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




	def 					__A    (						self		:  List[Any]							):


		'''simple docstring'''







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


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


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCamelCase__     :					int								=			{
    "configuration_camembert": ["CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "CamembertConfig", "CamembertOnnxConfig"],
}

try:
       if not is_sentencepiece_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCamelCase__     :					str								=			["CamembertTokenizer"]

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCamelCase__     :					Any								=			["CamembertTokenizerFast"]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCamelCase__     :					Union[str, Any]								=			[
           "CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
           "CamembertForCausalLM",
           "CamembertForMaskedLM",
           "CamembertForMultipleChoice",
           "CamembertForQuestionAnswering",
           "CamembertForSequenceClassification",
           "CamembertForTokenClassification",
           "CamembertModel",
           "CamembertPreTrainedModel",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       UpperCamelCase__     :					Optional[Any]								=			[
           "TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
           "TFCamembertForCausalLM",
           "TFCamembertForMaskedLM",
           "TFCamembertForMultipleChoice",
           "TFCamembertForQuestionAnswering",
           "TFCamembertForSequenceClassification",
           "TFCamembertForTokenClassification",
           "TFCamembertModel",
           "TFCamembertPreTrainedModel",
       ]


if TYPE_CHECKING:
       from .configuration_camembert import CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, CamembertConfig, CamembertOnnxConfig

       try:
              if not is_sentencepiece_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_camembert import CamembertTokenizer

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_camembert_fast import CamembertTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_camembert import (
                  CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  CamembertForCausalLM,
                  CamembertForMaskedLM,
                  CamembertForMultipleChoice,
                  CamembertForQuestionAnswering,
                  CamembertForSequenceClassification,
                  CamembertForTokenClassification,
                  CamembertModel,
                  CamembertPreTrainedModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_camembert import (
                  TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFCamembertForCausalLM,
                  TFCamembertForMaskedLM,
                  TFCamembertForMultipleChoice,
                  TFCamembertForQuestionAnswering,
                  TFCamembertForSequenceClassification,
                  TFCamembertForTokenClassification,
                  TFCamembertModel,
                  TFCamembertPreTrainedModel,
              )

else:
       import sys

       UpperCamelCase__     :					List[str]								=			_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


