





import unittest

from cer import CER


__UpperCAmelCase						=      CER()

class 		__a							(	unittest.TestCase      ):



       def  A							(     self	:   Any			):
           lowerCAmelCase_					:	Optional[int]						=   ["""White House"""]
           lowerCAmelCase_					:	Optional[Any]						=   ["""white house"""]
           # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
           lowerCAmelCase_					:	Dict						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.18_1818_1818			) < 1e-6			)



       def  A							(     self	:   Union[str, Any]			):
           lowerCAmelCase_					:	Union[str, Any]						=   ["""were wolf"""]
           lowerCAmelCase_					:	Optional[Any]						=   ["""werewolf"""]
           # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
           lowerCAmelCase_					:	Tuple						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.111_1111			) < 1e-6			)

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

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

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



       def  A							(     self	:   Tuple			):
           lowerCAmelCase_					:	Optional[int]						=   ["""werewolf"""]
           lowerCAmelCase_					:	List[str]						=   ["""weaewolf"""]
           # S = 1, D = 0, I = 0, N = 8, CER = 0.125
           lowerCAmelCase_					:	List[str]						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.125			) < 1e-6			)



       def  A							(     self	:   Optional[Any]			):
           lowerCAmelCase_					:	Any						=   ["""werewolf"""]
           lowerCAmelCase_					:	Optional[int]						=   ["""wereawolf"""]
           # S = 0, D = 1, I = 0, N = 8, CER = 0.125
           lowerCAmelCase_					:	List[Any]						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.125			) < 1e-6			)



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



       def  A							(     self	:   str			):
           lowerCAmelCase_					:	Tuple						=   ["""werewolf"""]
           lowerCAmelCase_					:	Optional[Any]						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertEqual(UpperCAmelCase					,			0.0			)



       def  A							(     self	:   Any			):
           lowerCAmelCase_					:	List[Any]						=   ["""werewolf""", """I am your father"""]
           lowerCAmelCase_					:	List[Any]						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertEqual(UpperCAmelCase					,			0.0			)

           lowerCAmelCase_					:	List[Any]						=   ["""werewolf""", """I am your father""", """doge"""]
           lowerCAmelCase_					:	List[Any]						=   ["""werxwolf""", """I       am your father""", """doge"""]
           # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
           lowerCAmelCase_					:	Any						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.0357_1428			) < 1e-6			)



       def  A							(     self	:   Union[str, Any]			):
           lowerCAmelCase_					:	Union[str, Any]						=   ["""My hovercraft""", """is full of eels"""]
           lowerCAmelCase_					:	Tuple						=   ["""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_					:	Tuple						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase					,			concatenate_texts=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.07_1428			) < 1e-6			)



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

           lowerCAmelCase_					:	Union[str, Any]						=   ["""我能吞下玻璃""", """而不伤身体"""]
           lowerCAmelCase_					:	Union[str, Any]						=   ["""我    能 吞 下 玻 璃""", """而不伤身体"""]
           # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
           lowerCAmelCase_					:	str						=   cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)
           self.assertTrue(abs(char_error_rate - 0.4545_4545_4545			) < 1e-6			)

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



       def  A							(     self	:   Optional[int]			):
           lowerCAmelCase_					:	int						=   [""""""]
           lowerCAmelCase_					:	List[str]						=   ["""Hypothesis"""]
           with self.assertRaises(UpperCAmelCase			):
               cer.compute(predictions=UpperCAmelCase					,			references=UpperCAmelCase			)


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











import math
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      list:
    '''simple docstring'''





    if n <= 0:
        raise ValueError("""Only positive integers have prime factors"""		)
    lowerCAmelCase_					:	str						=   []
    while n % 2 == 0:
        pf.append(2		)
        lowerCAmelCase_					:	str						=   int(n / 2		)
    for i in range(3		,    int(math.sqrt(lowercase__		)		) + 1		,    2		):
        while n % i == 0:
            pf.append(lowercase__		)
            lowerCAmelCase_					:	List[Any]						=   int(n / i		)
    if n > 2:
        pf.append(lowercase__		)
    return pf
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      int:
    '''simple docstring'''





    if n <= 0:
        raise ValueError("""Only positive numbers are accepted"""		)
    lowerCAmelCase_					:	Union[str, Any]						=   1
    lowerCAmelCase_					:	str						=   1
    while n % 2 == 0:
        temp += 1
        lowerCAmelCase_					:	Optional[Any]						=   int(n / 2		)
    div *= temp
    for i in range(3		,    int(math.sqrt(lowercase__		)		) + 1		,    2		):
        lowerCAmelCase_					:	Tuple						=   1
        while n % i == 0:
            temp += 1
            lowerCAmelCase_					:	Any						=   int(n / i		)
        div *= temp
    if n > 1:
        div *= 2
    return div
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      int:
    '''simple docstring'''





    if n <= 0:
        raise ValueError("""Only positive numbers are accepted"""		)
    lowerCAmelCase_					:	Tuple						=   1
    lowerCAmelCase_					:	str						=   1
    while n % 2 == 0:
        temp += 1
        lowerCAmelCase_					:	Optional[int]						=   int(n / 2		)
    if temp > 1:
        s *= (2**temp - 1) / (2 - 1)
    for i in range(3		,    int(math.sqrt(lowercase__		)		) + 1		,    2		):
        lowerCAmelCase_					:	int						=   1
        while n % i == 0:
            temp += 1
            lowerCAmelCase_					:	Any						=   int(n / i		)
        if temp > 1:
            s *= (i**temp - 1) / (i - 1)
    return int(lowercase__		)
def 			__UpperCamelCase				(			lowercase__	:       int		)	->      int:
    '''simple docstring'''





    lowerCAmelCase_					:	str						=   n
    for x in set(prime_factors(lowercase__		)		):
        s *= (x - 1) / x
    return int(lowercase__		)


if __name__ == "__main__":
  import doctest

  doctest.testmod()


