



import unittest

from cer import CER


lowerCAmelCase					:				Union[str, Any]   	=CER()






class 	_a			(      unittest.TestCase  ):






			def 							_snake_case   (    self )	->					List[str]:
									lowerCAmelCase	:   str					     =					["""White House"""]
									lowerCAmelCase	:   Union[str, Any]					     =					["""white house"""]
									# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
									lowerCAmelCase	:   List[str]					     =					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 							_snake_case   (    self )	->					int:
									lowerCAmelCase	:   Optional[int]					     =					["""were wolf"""]
									lowerCAmelCase	:   Optional[Any]					     =					["""werewolf"""]
									# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
									lowerCAmelCase	:   Union[str, Any]					     =					cer.compute(predictions=__lowerCamelCase    ,  references=__lowerCamelCase )
									self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1 ) < 1e-6 )

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

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

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






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






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






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






			def 							_snake_case   (    self )	->					Optional[Any]:
									lowerCAmelCase	:   Tuple					     =					["""werewolf"""]
									lowerCAmelCase	:   Dict					     =					cer.compute(predictions=__lowerCamelCase    ,  references=__lowerCamelCase )
									self.assertEqual(__lowerCamelCase    ,  0.0 )






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

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






			def 							_snake_case   (    self )	->					Union[str, Any]:
									lowerCAmelCase	:   Tuple					     =					["""My hovercraft""", """is full of eels"""]
									lowerCAmelCase	:   Union[str, Any]					     =					["""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	:   Dict					     =					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 							_snake_case   (    self )	->					List[str]:
									lowerCAmelCase	:   Optional[Any]					     =					["""我能吞下玻璃而不伤身体"""]
									lowerCAmelCase	:   Union[str, Any]					     =					[""" 能吞虾玻璃而 不霜身体啦"""]
									# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
									lowerCAmelCase	:   Dict					     =					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 )

									lowerCAmelCase	:   str					     =					["""我能吞下玻璃""", """而不伤身体"""]
									lowerCAmelCase	:   Any					     =					["""我    能 吞 下 玻 璃""", """而不伤身体"""]
									# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
									lowerCAmelCase	:   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_4_5 ) < 1e-6 )

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






			def 							_snake_case   (    self )	->					str:
									lowerCAmelCase	:   Tuple					     =					[""""""]
									lowerCAmelCase	:   Optional[Any]					     =					["""Hypothesis"""]
									with self.assertRaises(__lowerCamelCase ):
															cer.compute(predictions=__lowerCamelCase    ,  references=__lowerCamelCase )


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


def   a_					(_lowerCAmelCase  :   int       )->				str:
    if not isinstance(_lowerCAmelCase			,	_lowerCAmelCase       ):
        snake_case:						Optional[Any]         =   (
            """operation can not be conducted on a object of type """
            F"{type(_lowerCAmelCase       ).__name__}"
        )
        raise TypeError(_lowerCAmelCase       )
    snake_case:						List[Any]         =   """"""
    for _ in range(0			,	32       ):
        bit_string += str(number % 2       )
        snake_case:						Any         =   number >> 1
    return bit_string

def   a_					(_lowerCAmelCase  :   int       )->				str:
    if number < 0:
        raise ValueError("""the value of input must be positive"""       )
    elif isinstance(_lowerCAmelCase			,	_lowerCAmelCase       ):
        raise TypeError("""Input value must be a 'int' type"""       )
    elif isinstance(_lowerCAmelCase			,	_lowerCAmelCase       ):
        raise TypeError("""'<' not supported between instances of 'str' and 'int'"""       )
    snake_case:						Optional[Any]         =   0
    # iterator over [1 to 32],since we are dealing with 32 bit integer
    for _ in range(1			,	33       ):
        # left shift the bits by unity
        snake_case:						Dict         =   result << 1
        # get the end bit
        snake_case:						Union[str, Any]         =   number % 2
        # right shift the bits by unity
        snake_case:						Union[str, Any]         =   number >> 1
        # add that bit to our ans
        snake_case:						Tuple         =   result | end_bit
    return get_reverse_bit_string(_lowerCAmelCase       )


if __name__ == "__main__":
    import doctest

    doctest.testmod()


