
'''simple docstring'''

import unittest

from cer import CER


__UpperCAmelCase												=   CER()


class 		_a     (							unittest.TestCase  ):







   """simple docstring"""




   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  str								=		['White House']
    SCREAMING_SNAKE_CASE  :  Any								=		['white house']
    # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
    SCREAMING_SNAKE_CASE  :  List[Any]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.18_1818_1818      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  str								=		['were wolf']
    SCREAMING_SNAKE_CASE  :  Tuple								=		['werewolf']
    # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
    SCREAMING_SNAKE_CASE  :  Tuple								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.111_1111      ) < 1e-6      )

    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		['werewolf']
    SCREAMING_SNAKE_CASE  :  Any								=		['weae     wolf']
    # S = 1, D = 1, I = 0, N = 8, CER = 0.25
    SCREAMING_SNAKE_CASE  :  Any								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.25      ) < 1e-6      )

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

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






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Dict								=		['werewolf']
    SCREAMING_SNAKE_CASE  :  List[Any]								=		['weaewolf']
    # S = 1, D = 0, I = 0, N = 8, CER = 0.125
    SCREAMING_SNAKE_CASE  :  List[str]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.125      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		['werewolf']
    SCREAMING_SNAKE_CASE  :  Union[str, Any]								=		['wereawolf']
    # S = 0, D = 1, I = 0, N = 8, CER = 0.125
    SCREAMING_SNAKE_CASE  :  Tuple								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.125      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[Any]								=		['werewolf']
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		['wereolf']
    # S = 0, D = 0, I = 1, N = 8, CER = 0.125
    SCREAMING_SNAKE_CASE  :  List[Any]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.125      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[str]								=		['werewolf']
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertEqual(A_    ,0.0      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Any								=		['werewolf', 'I am your father']
    SCREAMING_SNAKE_CASE  :  int								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertEqual(A_    ,0.0      )

    SCREAMING_SNAKE_CASE  :  Tuple								=		['werewolf', 'I am your father', 'doge']
    SCREAMING_SNAKE_CASE  :  str								=		['werxwolf', 'I       am your father', 'doge']
    # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
    SCREAMING_SNAKE_CASE  :  str								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.0357_1428      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[Any]								=		['My hovercraft', 'is full of eels']
    SCREAMING_SNAKE_CASE  :  int								=		['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
    SCREAMING_SNAKE_CASE  :  Dict								=		cer.compute(predictions=A_    ,references=A_    ,concatenate_texts=A_      )
    self.assertTrue(abs(char_error_rate - 0.07_1428      ) < 1e-6      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		['我能吞下玻璃而不伤身体']
    SCREAMING_SNAKE_CASE  :  List[str]								=		[' 能吞虾玻璃而 不霜身体啦']
    # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.45_4545_4545      ) < 1e-6      )

    SCREAMING_SNAKE_CASE  :  Tuple								=		['我能吞下玻璃', '而不伤身体']
    SCREAMING_SNAKE_CASE  :  List[str]								=		['我    能 吞 下 玻 璃', '而不伤身体']
    # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
    SCREAMING_SNAKE_CASE  :  Optional[int]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertTrue(abs(char_error_rate - 0.4545_4545_4545      ) < 1e-6      )

    SCREAMING_SNAKE_CASE  :  Dict								=		['我能吞下玻璃而不伤身体']
    SCREAMING_SNAKE_CASE  :  Optional[Any]								=		cer.compute(predictions=A_    ,references=A_      )
    self.assertFalse(A_    ,0.0      )






   def 					__a			(       self      ):
    SCREAMING_SNAKE_CASE  :  List[str]								=		['']
    SCREAMING_SNAKE_CASE  :  Any								=		['Hypothesis']
    with self.assertRaises(A_      ):
     cer.compute(predictions=A_    ,references=A_      )


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



from hashlib import mda, shaaaa

snake_case__						      =			(shaaaa, mda)



class 			UpperCamelCase					:

     '''simple docstring'''

     def __init__(       self					,					A_ = 8    )			->					None:






           """simple docstring"""
           _lowerCamelCase           =					0b0
           _lowerCamelCase           =					size



     def 		UpperCamelCase_    (       self					,					A_    )			->					None:






           """simple docstring"""
           _lowerCamelCase           =					self.hash_(A_    )
           self.bitarray |= h



     def 		UpperCamelCase_    (       self					,					A_    )			->					bool:






           """simple docstring"""
           _lowerCamelCase           =					self.hash_(A_    )
           return (h & self.bitarray) == h



     def __contains__(       self					,					A_    )			->					bool:






           """simple docstring"""
           return self.exists(A_    )



     def 		UpperCamelCase_    (       self					,					A_    )			->					str:






           """simple docstring"""
           _lowerCamelCase           =					bin(A_    )[2:]
           return res.zfill(self.size    )



     @property
     def 		UpperCamelCase_    (       self    )			->					str:






           """simple docstring"""
           return self.format_bin(self.bitarray    )



     def 		UpperCamelCase_    (       self					,					A_    )			->					int:






           """simple docstring"""
           _lowerCamelCase           =					0b0
           for func in HASH_FUNCTIONS:
                 _lowerCamelCase           =					(
                     int.from_bytes(func(value.encode()    ).digest()					,					'''little'''    ) % self.size
                 )
                 res |= 2**position
           return res



     def 		UpperCamelCase_    (       self					,					A_    )			->					str:






           """simple docstring"""
           return self.format_bin(self.hash_(A_    )    )





     @property
     def 		UpperCamelCase_    (       self    )			->					float:






           """simple docstring"""
           _lowerCamelCase           =					bin(self.bitarray    ).count('''1'''    )
           return (n_ones / self.size) ** len(A_    )