






import unittest

from cer import CER


UpperCamelCase											=      CER()




class 	lowerCamelCase__				(							unittest.TestCase ):






      def      UpperCAmelCase_     (self					:    List[str]		)       ->   int:


       """simple docstring"""






       lowerCamelCase_							:    Any							=     ['White House']
       lowerCamelCase_							:    Optional[Any]							=     ['white house']
       # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
       lowerCamelCase_							:    Any							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertTrue(abs(char_error_rate - 0.18_1818_1818		) < 1e-6		)






      def      UpperCAmelCase_     (self					:    Tuple		)       ->   Dict:


       """simple docstring"""






       lowerCamelCase_							:    List[str]							=     ['were wolf']
       lowerCamelCase_							:    Optional[Any]							=     ['werewolf']
       # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
       lowerCamelCase_							:    int							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertTrue(abs(char_error_rate - 0.111_1111		) < 1e-6		)

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

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

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






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


       """simple docstring"""






       lowerCamelCase_							:    Optional[int]							=     ['werewolf']
       lowerCamelCase_							:    Dict							=     ['weaewolf']
       # S = 1, D = 0, I = 0, N = 8, CER = 0.125
       lowerCamelCase_							:    Any							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertTrue(abs(char_error_rate - 0.125		) < 1e-6		)






      def      UpperCAmelCase_     (self					:    Optional[Any]		)       ->   str:


       """simple docstring"""






       lowerCamelCase_							:    Optional[int]							=     ['werewolf']
       lowerCamelCase_							:    Dict							=     ['wereawolf']
       # S = 0, D = 1, I = 0, N = 8, CER = 0.125
       lowerCamelCase_							:    Any							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertTrue(abs(char_error_rate - 0.125		) < 1e-6		)






      def      UpperCAmelCase_     (self					:    int		)       ->   List[Any]:


       """simple docstring"""






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






      def      UpperCAmelCase_     (self					:    Dict		)       ->   int:


       """simple docstring"""






       lowerCamelCase_							:    Dict							=     ['werewolf']
       lowerCamelCase_							:    Any							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertEqual(_snake_case		,		0.0		)






      def      UpperCAmelCase_     (self					:    List[str]		)       ->   Optional[int]:


       """simple docstring"""






       lowerCamelCase_							:    str							=     ['werewolf', 'I am your father']
       lowerCamelCase_							:    Tuple							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertEqual(_snake_case		,		0.0		)

       lowerCamelCase_							:    Tuple							=     ['werewolf', 'I am your father', 'doge']
       lowerCamelCase_							:    Optional[Any]							=     ['werxwolf', 'I       am your father', 'doge']
       # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
       lowerCamelCase_							:    Dict							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertTrue(abs(char_error_rate - 0.0357_1428		) < 1e-6		)






      def      UpperCAmelCase_     (self					:    int		)       ->   Any:


       """simple docstring"""






       lowerCamelCase_							:    List[Any]							=     ['My hovercraft', 'is full of eels']
       lowerCamelCase_							:    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
       lowerCamelCase_							:    Tuple							=     cer.compute(predictions=_snake_case		,		references=_snake_case		,		concatenate_texts=_snake_case		)
       self.assertTrue(abs(char_error_rate - 0.07_1428		) < 1e-6		)






      def      UpperCAmelCase_     (self					:    str		)       ->   str:


       """simple docstring"""






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

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

       lowerCamelCase_							:    List[str]							=     ['我能吞下玻璃而不伤身体']
       lowerCamelCase_							:    Tuple							=     cer.compute(predictions=_snake_case		,		references=_snake_case		)
       self.assertFalse(_snake_case		,		0.0		)






      def      UpperCAmelCase_     (self					:    Dict		)       ->   List[Any]:


       """simple docstring"""






       lowerCamelCase_							:    List[Any]							=     ['']
       lowerCamelCase_							:    int							=     ['Hypothesis']
       with self.assertRaises(_snake_case		):
        cer.compute(predictions=_snake_case		,		references=_snake_case		)


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








import unittest

from transformers import load_tool
from transformers.tools.agent_types import AGENT_TYPE_MAPPING

from .test_tools_common import ToolTesterMixin, output_types




class 	lowerCamelCase__				(							unittest.TestCase,   UpperCAmelCase ):






      def      UpperCAmelCase_     (self					:    Any		)       ->   Union[str, Any]:


       """simple docstring"""






       lowerCamelCase_							:    str							=     load_tool('translation'		)
       self.tool.setup()
       lowerCamelCase_							:    Optional[int]							=     load_tool('translation'		,		remote=_snake_case		)






      def      UpperCAmelCase_     (self					:    Any		)       ->   Dict:


       """simple docstring"""






       lowerCamelCase_							:    Optional[Any]							=     self.tool('Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    Optional[int]		)       ->   Dict:


       """simple docstring"""






       lowerCamelCase_							:    Optional[int]							=     self.remote_tool('Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    List[str]		)       ->   Optional[int]:


       """simple docstring"""






       lowerCamelCase_							:    Union[str, Any]							=     self.tool(text='Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    Any		)       ->   Tuple:


       """simple docstring"""






       lowerCamelCase_							:    Optional[int]							=     self.remote_tool(text='Hey, what\'s up?'		,		src_lang='English'		,		tgt_lang='French'		)
       self.assertEqual(_snake_case		,		'- Hé, comment ça va?'		)






      def      UpperCAmelCase_     (self					:    Union[str, Any]		)       ->   Any:


       """simple docstring"""






       lowerCamelCase_							:    str							=     ['Hey, what\'s up?', 'English', 'Spanish']
       lowerCamelCase_							:    Any							=     self.tool(*_snake_case		)

       # There is a single output
       if len(self.tool.outputs		) == 1:
        lowerCamelCase_							:    Any							=     [outputs]

       self.assertListEqual(output_types(_snake_case		)		,		self.tool.outputs		)






      def      UpperCAmelCase_     (self					:    Tuple		)       ->   Optional[Any]:


       """simple docstring"""






       lowerCamelCase_							:    List[str]							=     ['Hey, what\'s up?', 'English', 'Spanish']
       lowerCamelCase_							:    Optional[Any]							=     self.tool(*_snake_case		)

       if not isinstance(_snake_case		,		_snake_case		):
        lowerCamelCase_							:    List[str]							=     [outputs]

       self.assertEqual(len(_snake_case		)		,		len(self.tool.outputs		)		)

       for output, output_type in zip(_snake_case		,		self.tool.outputs		):
        lowerCamelCase_							:    Optional[int]							=     AGENT_TYPE_MAPPING[output_type]
        self.assertTrue(isinstance(_snake_case		,		_snake_case		)		)






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


       """simple docstring"""






       lowerCamelCase_							:    Dict							=     ['Hey, what\'s up?', 'English', 'Spanish']

       lowerCamelCase_							:    List[str]							=     []

       for _input, input_type in zip(_snake_case		,		self.tool.inputs		):
        if isinstance(_snake_case		,		_snake_case		):
         _inputs.append([AGENT_TYPE_MAPPING[_input_type](_input		) for _input_type in input_type]		)
        else:
         _inputs.append(AGENT_TYPE_MAPPING[input_type](_input		)		)

        # Should not raise an error
       lowerCamelCase_							:    Any							=     self.tool(*_snake_case		)

       if not isinstance(_snake_case		,		_snake_case		):
        lowerCamelCase_							:    Optional[Any]							=     [outputs]

       self.assertEqual(len(_snake_case		)		,		len(self.tool.outputs		)		)
