import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin




class    a__				(       __lowercase							,       unittest.TestCase			):
     lowerCamelCase  :					Dict							=CTRLTokenizer
     lowerCamelCase  :					List[str]							=False
     lowerCamelCase  :					Any							=False






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[Any]   ):





         """simple docstring"""



         super().setUp()

         # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
         __lowerCamelCase          =  ['''adapt''', '''re@@''', '''a@@''', '''apt''', '''c@@''', '''t''', '''<unk>''']
         __lowerCamelCase          =  dict(zip(_a  ,    range(len(_a   )   )   )   )
         __lowerCamelCase          =  ['''#version: 0.2''', '''a p''', '''ap t</w>''', '''r e''', '''a d''', '''ad apt</w>''', '''''']
         __lowerCamelCase          =  {'''unk_token''': '''<unk>'''}

         __lowerCamelCase          =  os.path.join(self.tmpdirname  ,    VOCAB_FILES_NAMES['''vocab_file''']   )
         __lowerCamelCase          =  os.path.join(self.tmpdirname  ,    VOCAB_FILES_NAMES['''merges_file''']   )
         with open(self.vocab_file  ,    '''w'''  ,    encoding='''utf-8'''   ) as fp:
             fp.write(json.dumps(_a   ) + '''\n'''   )
         with open(self.merges_file  ,    '''w'''  ,    encoding='''utf-8'''   ) as fp:
             fp.write('''\n'''.join(_a   )   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[Any]  ,    **a		:		Union[str, Any]   ):





         """simple docstring"""



         kwargs.update(self.special_tokens_map   )
         return CTRLTokenizer.from_pretrained(self.tmpdirname  ,    **_a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Optional[Any]  ,    a		:		Any   ):





         """simple docstring"""



         __lowerCamelCase          =  '''adapt react readapt apt'''
         __lowerCamelCase          =  '''adapt react readapt apt'''
         return input_text, output_text






     def        SCREAMING_SNAKE_CASE__       (			self		:		Union[str, Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  CTRLTokenizer(self.vocab_file  ,    self.merges_file  ,    **self.special_tokens_map   )
         __lowerCamelCase          =  '''adapt react readapt apt'''
         __lowerCamelCase          =  '''adapt re@@ a@@ c@@ t re@@ adapt apt'''.split()
         __lowerCamelCase          =  tokenizer.tokenize(_a   )
         self.assertListEqual(_a  ,    _a   )

         __lowerCamelCase          =  tokens + [tokenizer.unk_token]

         __lowerCamelCase          =  [0, 1, 2, 4, 5, 1, 0, 3, 6]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(_a   )  ,    _a   )

'''simple docstring'''




def __lowerCAmelCase			(							UpperCamelCase__    ,  UpperCamelCase__    ,  UpperCamelCase__    )     ->   float:
    if principal <= 0:
        raise Exception('''Principal borrowed must be > 0'''    )
    if rate_per_annum < 0:
        raise Exception('''Rate of interest must be >= 0'''    )
    if years_to_repay <= 0 or not isinstance(UpperCamelCase__    ,  UpperCamelCase__    ):
        raise Exception('''Years to repay must be an integer > 0'''    )

    # Yearly rate is divided by 12 to get monthly rate
    __lowerCamelCase          =  rate_per_annum / 12

    # Years to repay is multiplied by 12 to get number of payments as payment is monthly
    __lowerCamelCase          =  years_to_repay * 12

    return (
        principal
        * rate_per_month
        * (1 + rate_per_month) ** number_of_payments
        / ((1 + rate_per_month) ** number_of_payments - 1)
    )


if __name__ == "__main__":
  import doctest

  doctest.testmod()
