


'''simple docstring'''

import unittest

from cer import CER


__lowercase:		Tuple    						=  CER()







class 			UpperCAmelCase			(							unittest.TestCase):

 def 		lowercase_    (			self			:						int       ):





    """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 		lowercase_    (			self			:						List[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 		lowercase_    (			self			:						Optional[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 		lowercase_    (			self			:						Dict       ):





    """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 		lowercase_    (			self			:						List[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 		lowercase_    (			self			:						str       ):





    """simple docstring"""



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

 def 		lowercase_    (			self			:						List[Any]       ):





    """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 		lowercase_    (			self			:						List[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 		lowercase_    (			self			:						Optional[Any]       ):





    """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 		lowercase_    (			self			:						Union[str, Any]       ):





    """simple docstring"""



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


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




'''simple docstring'''



lowerCAmelCase						:		Tuple						      = '''
# Diffusers installation
! pip install diffusers transformers datasets accelerate
# To install from source instead of the last release, comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/diffusers.git
'''

lowerCAmelCase						:		Tuple						      = [{'''type''': '''code''', '''content''': INSTALL_CONTENT}]