


import unittest

from cer import CER


lowerCAmelCase__   	=				CER()







class   lowerCAmelCase__ (       unittest.TestCase):




     '''simple docstring'''


     def 				_lowerCamelCase				(		self)    ->       str:
            _A   : List[Any]       					=				["White House"]
            _A   : int       					=				["white house"]
            # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
            _A   : List[Any]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8) < 1e-6)


     def 				_lowerCamelCase				(		self)    ->       str:
            _A   : List[str]       					=				["were wolf"]
            _A   : int       					=				["werewolf"]
            # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
            _A   : Optional[int]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1) < 1e-6)

            _A   : Any       					=				["werewolf"]
            _A   : Optional[int]       					=				["weae     wolf"]
            # S = 1, D = 1, I = 0, N = 8, CER = 0.25
            _A   : List[Any]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.2_5) < 1e-6)

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

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


     def 				_lowerCamelCase				(		self)    ->       Optional[Any]:
            _A   : Union[str, Any]       					=				["werewolf"]
            _A   : Optional[int]       					=				["weaewolf"]
            # S = 1, D = 0, I = 0, N = 8, CER = 0.125
            _A   : Any       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.1_2_5) < 1e-6)


     def 				_lowerCamelCase				(		self)    ->       Union[str, Any]:
            _A   : List[Any]       					=				["werewolf"]
            _A   : int       					=				["wereawolf"]
            # S = 0, D = 1, I = 0, N = 8, CER = 0.125
            _A   : List[Any]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.1_2_5) < 1e-6)


     def 				_lowerCamelCase				(		self)    ->       Tuple:
            _A   : Tuple       					=				["werewolf"]
            _A   : Optional[int]       					=				["wereolf"]
            # S = 0, D = 0, I = 1, N = 8, CER = 0.125
            _A   : Union[str, Any]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.1_2_5) < 1e-6)


     def 				_lowerCamelCase				(		self)    ->       List[Any]:
            _A   : Optional[int]       					=				["werewolf"]
            _A   : Tuple       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertEqual(__lowerCamelCase				,		0.0)


     def 				_lowerCamelCase				(		self)    ->       List[str]:
            _A   : Dict       					=				["werewolf", "I am your father"]
            _A   : int       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertEqual(__lowerCamelCase				,		0.0)

            _A   : int       					=				["werewolf", "I am your father", "doge"]
            _A   : Dict       					=				["werxwolf", "I       am your father", "doge"]
            # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
            _A   : str       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8) < 1e-6)


     def 				_lowerCamelCase				(		self)    ->       Tuple:
            _A   : List[Any]       					=				["My hovercraft", "is full of eels"]
            _A   : 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
            _A   : Union[str, Any]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase				,		concatenate_texts=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8) < 1e-6)


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

            _A   : List[str]       					=				["我能吞下玻璃", "而不伤身体"]
            _A   : Tuple       					=				["我    能 吞 下 玻 璃", "而不伤身体"]
            # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
            _A   : Dict       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5_4_5) < 1e-6)

            _A   : Union[str, Any]       					=				["我能吞下玻璃而不伤身体"]
            _A   : Optional[int]       					=				cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)
            self.assertFalse(__lowerCamelCase				,		0.0)


     def 				_lowerCamelCase				(		self)    ->       Tuple:
            _A   : str       					=				[""]
            _A   : Tuple       					=				["Hypothesis"]
            with self.assertRaises(__lowerCamelCase):
                   cer.compute(predictions=__lowerCamelCase				,		references=__lowerCamelCase)


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




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowerCAmelCase__   	=				{
    'configuration_deta': ['DETA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DetaConfig'],
}

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__   	=				['DetaImageProcessor']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCAmelCase__   	=				[
        'DETA_PRETRAINED_MODEL_ARCHIVE_LIST',
        'DetaForObjectDetection',
        'DetaModel',
        'DetaPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_deta import DETA_PRETRAINED_CONFIG_ARCHIVE_MAP, DetaConfig

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .image_processing_deta import DetaImageProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_deta import (
            DETA_PRETRAINED_MODEL_ARCHIVE_LIST,
            DetaForObjectDetection,
            DetaModel,
            DetaPreTrainedModel,
        )

else:
    import sys

    lowerCAmelCase__   	=				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
