'''simple docstring'''

import os
import unittest

from transformers.models.bartpho.tokenization_bartpho import VOCAB_FILES_NAMES, BartphoTokenizer
from transformers.testing_utils import get_tests_dir

from ...test_tokenization_common import TokenizerTesterMixin


UpperCamelCase__  :						Union[str, Any]					=      get_tests_dir('fixtures/test_sentencepiece_bpe.model')


class 					_lowercase						(   lowerCAmelCase		,unittest.TestCase ):
      '''simple docstring'''


      UpperCAmelCase_   :   Any   				= BartphoTokenizer
      UpperCAmelCase_   :   Optional[int]   				= False
      UpperCAmelCase_   :   Union[str, Any]   				= True




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



         '''simple docstring'''



         super().setUp()

         UpperCAmelCase__				:					Any 					=	['''▁This''', '''▁is''', '''▁a''', '''▁t''', '''est''']
         UpperCAmelCase__				:					Any 					=	dict(zip(lowerCamelCase_       ,range(len(lowerCamelCase_				)				)				)				)
         UpperCAmelCase__				:					List[str] 					=	{'''unk_token''': '''<unk>'''}

         UpperCAmelCase__				:					Optional[int] 					=	os.path.join(self.tmpdirname       ,VOCAB_FILES_NAMES['''monolingual_vocab_file''']				)
         with open(self.monolingual_vocab_file       ,'''w'''       ,encoding='''utf-8'''				) as fp:
            for token in vocab_tokens:
               fp.write(f'''{token} {vocab_tokens[token]}\n'''				)

         UpperCAmelCase__				:					Union[str, Any] 					=	BartphoTokenizer(lowerCamelCase_       ,self.monolingual_vocab_file       ,**self.special_tokens_map				)
         tokenizer.save_pretrained(self.tmpdirname				)




      def 		lowerCAmelCase__       (					self       ,**lowerCamelCase_				)      ->      Union[str, Any]:



         '''simple docstring'''



         kwargs.update(self.special_tokens_map				)
         return BartphoTokenizer.from_pretrained(self.tmpdirname       ,**lowerCamelCase_				)




      def 		lowerCAmelCase__       (					self       ,lowerCamelCase_				)      ->      Optional[Any]:



         '''simple docstring'''



         UpperCAmelCase__				:					Union[str, Any] 					=	'''This is a là test'''
         UpperCAmelCase__				:					str 					=	'''This is a<unk><unk> test'''
         return input_text, output_text




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



         '''simple docstring'''



         UpperCAmelCase__				:					List[str] 					=	BartphoTokenizer(lowerCamelCase_       ,self.monolingual_vocab_file       ,**self.special_tokens_map				)
         UpperCAmelCase__				:					List[str] 					=	'''This is a là test'''
         UpperCAmelCase__				:					Union[str, Any] 					=	'''▁This ▁is ▁a ▁l à ▁t est'''.split()
         UpperCAmelCase__				:					Any 					=	tokenizer.tokenize(lowerCamelCase_				)
         self.assertListEqual(lowerCamelCase_       ,lowerCamelCase_				)

         UpperCAmelCase__				:					List[Any] 					=	tokens + [tokenizer.unk_token]
         UpperCAmelCase__				:					int 					=	[4, 5, 6, 3, 3, 7, 8, 3]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase_				)       ,lowerCamelCase_				)





'''simple docstring'''

def __UpperCamelCase( _A       :					float	,      _A       :					list[float]     ):
   '''simple docstring'''
   if discount_rate < 0:
      raise ValueError('''Discount rate cannot be negative'''     )
   if not cash_flows:
      raise ValueError('''Cash flows list cannot be empty'''     )
   UpperCAmelCase__				:					str 					=	sum(
       cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_A     )     )
   return round(_A	,      ndigits=2     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()




