
'''simple docstring'''







import unittest

from cer import CER


_lowercase					:    List[Any]       				=			CER()






class 					lowerCAmelCase__  (    unittest.TestCase	):






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	Optional[Any]						=			['''White House''']
											lowercase_      :	List[str]						=			['''white house''']
											# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
											lowercase_      :	str						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.1_818_181_818						) < 1E-6						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	int						=			['''were wolf''']
											lowercase_      :	Dict						=			['''werewolf''']
											# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
											lowercase_      :	Optional[Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.1_111_111						) < 1E-6						)

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

											# consecutive whitespaces case 1
											lowercase_      :	str						=			['''were wolf''']
											lowercase_      :	Union[str, Any]						=			['''were               wolf''']
											# S = 0, D = 0, I = 0, N = 9, CER = 0
											lowercase_      :	Tuple						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.0						) < 1E-6						)

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






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	List[Any]						=			['''werewolf''']
											lowercase_      :	Dict						=			['''weaewolf''']
											# S = 1, D = 0, I = 0, N = 8, CER = 0.125
											lowercase_      :	Any						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.125						) < 1E-6						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	Optional[Any]						=			['''werewolf''']
											lowercase_      :	str						=			['''wereawolf''']
											# S = 0, D = 1, I = 0, N = 8, CER = 0.125
											lowercase_      :	Optional[Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.125						) < 1E-6						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	Optional[Any]						=			['''werewolf''']
											lowercase_      :	Union[str, Any]						=			['''wereolf''']
											# S = 0, D = 0, I = 1, N = 8, CER = 0.125
											lowercase_      :	List[Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.125						) < 1E-6						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	str						=			['''werewolf''']
											lowercase_      :	List[Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertEqual(__SCREAMING_SNAKE_CASE							,				0.0						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	Tuple						=			['''werewolf''', '''I am your father''']
											lowercase_      :	Optional[Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertEqual(__SCREAMING_SNAKE_CASE							,				0.0						)

											lowercase_      :	Tuple						=			['''werewolf''', '''I am your father''', '''doge''']
											lowercase_      :	Union[str, Any]						=			['''werxwolf''', '''I       am your father''', '''doge''']
											# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
											lowercase_      :	Optional[Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.03_571_428						) < 1E-6						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	Optional[int]						=			['''My hovercraft''', '''is full of eels''']
											lowercase_      :	List[str]						=			['''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
											lowercase_      :	Union[str, Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE							,				concatenate_texts=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.071_428						) < 1E-6						)






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	str						=			['''我能吞下玻璃而不伤身体''']
											lowercase_      :	List[Any]						=			[''' 能吞虾玻璃而 不霜身体啦''']
											# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
											lowercase_      :	List[str]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.4_545_454_545						) < 1E-6						)

											lowercase_      :	Union[str, Any]						=			['''我能吞下玻璃''', '''而不伤身体''']
											lowercase_      :	str						=			['''我    能 吞 下 玻 璃''', '''而不伤身体''']
											# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
											lowercase_      :	Union[str, Any]						=			cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)
											self.assertTrue(abs(char_error_rate - 0.454_545_454_545						) < 1E-6						)

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






					def       _snake_case       (  self						):


											"""simple docstring"""





											lowercase_      :	Any						=			['''''']
											lowercase_      :	Optional[int]						=			['''Hypothesis''']
											with self.assertRaises(__SCREAMING_SNAKE_CASE						):
																	cer.compute(predictions=__SCREAMING_SNAKE_CASE							,				references=__SCREAMING_SNAKE_CASE						)


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





'''simple docstring'''







import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry






class 					lowerCAmelCase__  (    lowerCamelCase_	):
					lowerCAmelCase_	  =	'''mock'''






					def __init__(  self							,				*__SCREAMING_SNAKE_CASE							,				__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											super().__init__()
											lowercase_      :	int						=			LocalFileSystem(*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)
											lowercase_      :	Tuple						=			Path(__SCREAMING_SNAKE_CASE						).resolve().as_posix() + '''/'''






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	List[str]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.mkdir(__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Optional[int]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.makedirs(__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Any						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.rmdir(__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				__SCREAMING_SNAKE_CASE=True							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	str						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											lowercase_      :	Union[str, Any]						=			self._fs.ls(__SCREAMING_SNAKE_CASE							,				detail=__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)
											if detail:
																	return [{**info, "name": info["name"][len(self.local_root_dir						) :]} for info in out]
											else:
																	return [name[len(self.local_root_dir						) :] for name in out]






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Optional[int]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											lowercase_      :	Optional[Any]						=			dict(self._fs.info(__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)						)
											lowercase_      :	Dict						=			out['''name'''][len(self.local_root_dir						) :]
											return out






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	List[str]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											lowercase_      :	str						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.cp_file(__SCREAMING_SNAKE_CASE							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	List[Any]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.rm_file(__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Union[str, Any]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.rm(__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Union[str, Any]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs._open(__SCREAMING_SNAKE_CASE							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Dict						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.created(__SCREAMING_SNAKE_CASE						)






					def       _snake_case       (  self							,				__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Optional[Any]						=			posixpath.join(self.local_root_dir							,				self._strip_protocol(__SCREAMING_SNAKE_CASE						)						)
											return self._fs.modified(__SCREAMING_SNAKE_CASE						)






					@classmethod
					def       _snake_case       (  cls							,				__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	Optional[Any]						=			stringify_path(__SCREAMING_SNAKE_CASE						)
											if path.startswith('''mock://'''						):
																	lowercase_      :	int						=			path[7:]
											return path







class 					lowerCAmelCase__  (    lowerCamelCase_	):
					lowerCAmelCase_	  =	'''tmp'''
					lowerCAmelCase_	  =	None






					def __init__(  self							,				*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
											super().__init__(*__SCREAMING_SNAKE_CASE							,				**__SCREAMING_SNAKE_CASE							,				local_root_dir=self.tmp_dir							,				auto_mkdir=__SCREAMING_SNAKE_CASE						)






					@classmethod
					def       _snake_case       (  cls							,				__SCREAMING_SNAKE_CASE						):


											"""simple docstring"""





											lowercase_      :	str						=			stringify_path(__SCREAMING_SNAKE_CASE						)
											if path.startswith('''tmp://'''						):
																	lowercase_      :	Union[str, Any]						=			path[6:]
											return path







@pytest.fixture
def    snake_case_						(							):



						"""simple docstring"""





						lowercase_      :	List[Any]						=			MockFileSystem
						lowercase_      :	Tuple						=			TmpDirFileSystem
						yield
						del _fsspec_registry["mock"]
						del _fsspec_registry["tmp"]
@pytest.fixture
def    snake_case_						(							__SCREAMING_SNAKE_CASE   :					List[Any] , __SCREAMING_SNAKE_CASE   :					List[Any]				):



						"""simple docstring"""





						lowercase_      :	List[str]						=			tmp_path_factory.mktemp('''mockfs'''				)
						return MockFileSystem(local_root_dir=__SCREAMING_SNAKE_CASE , auto_mkdir=__SCREAMING_SNAKE_CASE				)




@pytest.fixture
def    snake_case_						(							__SCREAMING_SNAKE_CASE   :					Union[str, Any] , __SCREAMING_SNAKE_CASE   :					Any				):



						"""simple docstring"""





						lowercase_      :	Union[str, Any]						=			tmp_path_factory.mktemp('''tmpfs'''				)
						with patch.object(__SCREAMING_SNAKE_CASE , '''tmp_dir''' , __SCREAMING_SNAKE_CASE				):
												yield TmpDirFileSystem()



