import unittest

from cer import CER


snake_case__						      =			CER()



class 			UpperCamelCase					(			unittest.TestCase			):

     '''simple docstring'''

     def 		UpperCamelCase_    (       self    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					['''White House''']
           _lowerCamelCase           =					['''white house''']
           # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.1818181818    ) < 1E-6    )



     def 		UpperCamelCase_    (       self    )			->					List[Any]:






           """simple docstring"""
           _lowerCamelCase           =					['''were wolf''']
           _lowerCamelCase           =					['''werewolf''']
           # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.1111111    ) < 1E-6    )

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

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

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



     def 		UpperCamelCase_    (       self    )			->					Tuple:






           """simple docstring"""
           _lowerCamelCase           =					['''werewolf''']
           _lowerCamelCase           =					['''weaewolf''']
           # S = 1, D = 0, I = 0, N = 8, CER = 0.125
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.125    ) < 1E-6    )



     def 		UpperCamelCase_    (       self    )			->					Any:






           """simple docstring"""
           _lowerCamelCase           =					['''werewolf''']
           _lowerCamelCase           =					['''wereawolf''']
           # S = 0, D = 1, I = 0, N = 8, CER = 0.125
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.125    ) < 1E-6    )



     def 		UpperCamelCase_    (       self    )			->					Any:






           """simple docstring"""
           _lowerCamelCase           =					['''werewolf''']
           _lowerCamelCase           =					['''wereolf''']
           # S = 0, D = 0, I = 1, N = 8, CER = 0.125
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.125    ) < 1E-6    )



     def 		UpperCamelCase_    (       self    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					['''werewolf''']
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertEqual(A_					,					0.0    )



     def 		UpperCamelCase_    (       self    )			->					str:






           """simple docstring"""
           _lowerCamelCase           =					['''werewolf''', '''I am your father''']
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertEqual(A_					,					0.0    )

           _lowerCamelCase           =					['''werewolf''', '''I am your father''', '''doge''']
           _lowerCamelCase           =					['''werxwolf''', '''I       am your father''', '''doge''']
           # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.03571428    ) < 1E-6    )



     def 		UpperCamelCase_    (       self    )			->					Optional[Any]:






           """simple docstring"""
           _lowerCamelCase           =					['''My hovercraft''', '''is full of eels''']
           _lowerCamelCase           =					['''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           =					cer.compute(predictions=A_					,					references=A_					,					concatenate_texts=A_    )
           self.assertTrue(abs(char_error_rate - 0.071428    ) < 1E-6    )



     def 		UpperCamelCase_    (       self    )			->					Optional[int]:






           """simple docstring"""
           _lowerCamelCase           =					['''我能吞下玻璃而不伤身体''']
           _lowerCamelCase           =					[''' 能吞虾玻璃而 不霜身体啦''']
           # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.4545454545    ) < 1E-6    )

           _lowerCamelCase           =					['''我能吞下玻璃''', '''而不伤身体''']
           _lowerCamelCase           =					['''我    能 吞 下 玻 璃''', '''而不伤身体''']
           # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
           _lowerCamelCase           =					cer.compute(predictions=A_					,					references=A_    )
           self.assertTrue(abs(char_error_rate - 0.454545454545    ) < 1E-6    )

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





     def 		UpperCamelCase_    (       self    )			->					Optional[Any]:






           """simple docstring"""
           _lowerCamelCase           =					['''''']
           _lowerCamelCase           =					['''Hypothesis''']
           with self.assertRaises(A_    ):
                 cer.compute(predictions=A_					,					references=A_    )


if __name__ == "__main__":
     unittest.main()
# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import sys
import warnings
from os.path import abspath, dirname, join


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
snake_case__						      =			abspath(join(dirname(dirname(dirname(__file__))), 'src'))
sys.path.insert(1, git_repo_path)


# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='ignore', category=FutureWarning)
def    __magic_name__(	__UpperCAmelCase		)    ->     int:



      '''simple docstring'''

      from transformers.testing_utils import pytest_addoption_shared

      pytest_addoption_shared(__UpperCAmelCase		)




def    __magic_name__(	__UpperCAmelCase		)    ->     List[str]:



      '''simple docstring'''

      from transformers.testing_utils import pytest_terminal_summary_main

      _lowerCamelCase           =					terminalreporter.config.getoption('''--make-reports'''		)
      if make_reports:
            pytest_terminal_summary_main(__UpperCAmelCase			,    id=__UpperCAmelCase		)