


'''simple docstring'''







import unittest

from cer import CER


a__    :   Any								=			CER()
class    lowercase_	(       unittest.TestCase  ):


    def   __a				(	self       ):
          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.18_1818_1818       ) < 1e-6       )


    def   __a				(	self       ):
          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.111_1111       ) < 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       ):
          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       ):
          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       ):
          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       ):
          UpperCamelCase__      =							["werewolf"]
          UpperCamelCase__      =							cer.compute(predictions=a    ,   references=a       )
          self.assertEqual(a    ,   0.0       )


    def   __a				(	self       ):
          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.0357_1428       ) < 1e-6       )


    def   __a				(	self       ):
          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.07_1428       ) < 1e-6       )


    def   __a				(	self       ):
          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.45_4545_4545       ) < 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.4545_4545_4545       ) < 1e-6       )

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


    def   __a				(	self       ):
          UpperCamelCase__      =							[""]
          UpperCamelCase__      =							["Hypothesis"]
          with self.assertRaises(a       ):
                cer.compute(predictions=a    ,   references=a       )


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









'''simple docstring'''







from __future__ import annotations

from enum import Enum, unique
from typing import TypeVar

# Create a generic variable that can be 'Enum', or any subclass.
a__    :   Optional[Any]								=			TypeVar('T', bound='Enum')
@unique
class    lowercase_	(       a__  ):
    __UpperCAmelCase       =      80
    __UpperCAmelCase       =      70
    __UpperCAmelCase       =      60
    __UpperCAmelCase       =      50
    __UpperCAmelCase       =      40
    __UpperCAmelCase       =      30
    __UpperCAmelCase       =      20
    __UpperCAmelCase       =      10

@unique
class    lowercase_	(       a__  ):
    __UpperCAmelCase       =      24
    __UpperCAmelCase       =      21
    __UpperCAmelCase       =      18
    __UpperCAmelCase       =      15
    __UpperCAmelCase       =      12
    __UpperCAmelCase       =      9
    __UpperCAmelCase       =      6
    __UpperCAmelCase       =      3
    __UpperCAmelCase       =      2
    __UpperCAmelCase       =      1
    __UpperCAmelCase       =      -1
    __UpperCAmelCase       =      -2
    __UpperCAmelCase       =      -3
    __UpperCAmelCase       =      -6
    __UpperCAmelCase       =      -9
    __UpperCAmelCase       =      -12
    __UpperCAmelCase       =      -15
    __UpperCAmelCase       =      -18
    __UpperCAmelCase       =      -21
    __UpperCAmelCase       =      -24


    @classmethod
    def   __a				(	cls       ):
          return {unit.name: unit.value for unit in cls if unit.value > 0}


    @classmethod
    def   __a				(	cls       ):
          return {unit.name: unit.value for unit in cls if unit.value < 0}







def _UpperCamelCase			(	__A       )				->						str:


      '''simple docstring'''



      UpperCamelCase__      =							SIUnit.get_positive() if value > 0 else SIUnit.get_negative()
      for name_prefix, value_prefix in prefixes.items():
            UpperCamelCase__      =							value / (10**value_prefix)
            if numerical_part > 1:
                  return F'''{numerical_part!s} {name_prefix}'''
      return str(__A       )







def _UpperCamelCase			(	__A       )				->						str:


      '''simple docstring'''



      for prefix in BinaryUnit:
            UpperCamelCase__      =							value / (2**prefix.value)
            if numerical_part > 1:
                  return F'''{numerical_part!s} {prefix.name}'''
      return str(__A       )


if __name__ == "__main__":
  import doctest

  doctest.testmod()





