
"""simple docstring"""




def        _lowerCamelCase ( __a    ):

		# bit count represents no. of bits in the gray code
		if bit_count < 0:
				raise ValueError('''The given input must be positive'''    )

		# get the generated string sequence
		SCREAMING_SNAKE_CASE_						 = gray_code_sequence_string(__a    )
		#
		# convert them to integers
		for i in range(len(__a    )    ):
				SCREAMING_SNAKE_CASE_						 = int(sequence[i],							2    )

		return sequence



def        _lowerCamelCase ( __a    ):

		# The approach is a recursive one
		# Base case achieved when either n = 0 or n=1
		if bit_count == 0:
				return ["0"]

		if bit_count == 1:
				return ["0", "1"]

		SCREAMING_SNAKE_CASE_						 = 1 << bit_count  # defines the length of the sequence
		# 1<< n is equivalent to 2^n

		# recursive answer will generate answer for n-1 bits
		SCREAMING_SNAKE_CASE_						 = gray_code_sequence_string(bit_count - 1    )

		SCREAMING_SNAKE_CASE_						 = []

		# append 0 to first half of the smaller sequence generated
		for i in range(seq_len // 2    ):
				SCREAMING_SNAKE_CASE_						 = '''0''' + smaller_sequence[i]
				sequence.append(__a    )

		# append 1 to second half ... start from the end of the list
		for i in reversed(range(seq_len // 2    )    ):
				SCREAMING_SNAKE_CASE_						 = '''1''' + smaller_sequence[i]
				sequence.append(__a    )

		return sequence


if __name__ == "__main__":
						import doctest

						doctest.testmod()


"""simple docstring"""




import os
import unittest

from transformers.models.transfo_xl.tokenization_transfo_xl import VOCAB_FILES_NAMES, TransfoXLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin





class  snake_case     (							__lowercase       ,			unittest.TestCase   ):
							UpperCAmelCase__						     =      TransfoXLTokenizer
							UpperCAmelCase__						     =      False
							UpperCAmelCase__						     =      False

							def _lowercase					(self    ):

									"""simple docstring"""







									super().setUp()

									SCREAMING_SNAKE_CASE_						 = [
									    '''<unk>''',
									    '''[CLS]''',
									    '''[SEP]''',
									    '''want''',
									    '''unwanted''',
									    '''wa''',
									    '''un''',
									    '''running''',
									    ''',''',
									    '''low''',
									    '''l''',
									]
									SCREAMING_SNAKE_CASE_						 = os.path.join(self.tmpdirname       ,       VOCAB_FILES_NAMES['''vocab_file''']    )
									with open(self.vocab_file       ,       '''w'''       ,       encoding='''utf-8'''    ) as vocab_writer:
											vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]    )    )

							def _lowercase					(self       ,       **SCREAMING_SNAKE_CASE_    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = True
									return TransfoXLTokenizer.from_pretrained(self.tmpdirname       ,       **SCREAMING_SNAKE_CASE_    )

							def _lowercase					(self       ,       SCREAMING_SNAKE_CASE_    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = '''<unk> UNwanted , running'''
									SCREAMING_SNAKE_CASE_						 = '''<unk> unwanted, running'''
									return input_text, output_text

							def _lowercase					(self    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = TransfoXLTokenizer(vocab_file=self.vocab_file       ,       lower_case=SCREAMING_SNAKE_CASE_    )

									SCREAMING_SNAKE_CASE_						 = tokenizer.tokenize('''<unk> UNwanted , running'''    )
									self.assertListEqual(SCREAMING_SNAKE_CASE_       ,       ['''<unk>''', '''unwanted''', ''',''', '''running''']    )

									self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE_    )       ,       [0, 4, 8, 7]    )

							def _lowercase					(self    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = TransfoXLTokenizer(lower_case=SCREAMING_SNAKE_CASE_    )

									self.assertListEqual(
									    tokenizer.tokenize(''' \tHeLLo ! how  \n Are yoU ?  '''    )       ,       ['''hello''', '''!''', '''how''', '''are''', '''you''', '''?''']    )

							def _lowercase					(self    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = TransfoXLTokenizer(lower_case=SCREAMING_SNAKE_CASE_    )

									self.assertListEqual(
									    tokenizer.tokenize(''' \tHeLLo ! how  \n Are yoU ?  '''    )       ,       ['''HeLLo''', '''!''', '''how''', '''Are''', '''yoU''', '''?''']    )

							def _lowercase					(self    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = TransfoXLTokenizer(lower_case=SCREAMING_SNAKE_CASE_    )
									SCREAMING_SNAKE_CASE_						 = '''Hello (bracket) and side-scrolled [and] Henry\'s $5,000 with 3.34 m. What\'s up!?'''
									SCREAMING_SNAKE_CASE_						 = [
									    '''Hello''',
									    '''(''',
									    '''bracket''',
									    ''')''',
									    '''and''',
									    '''side''',
									    '''@-@''',
									    '''scrolled''',
									    '''[''',
									    '''and''',
									    ''']''',
									    '''Henry''',
									    '''\'s''',
									    '''$''',
									    '''5''',
									    '''@,@''',
									    '''000''',
									    '''with''',
									    '''3''',
									    '''@.@''',
									    '''34''',
									    '''m''',
									    '''.''',
									    '''What''',
									    '''\'s''',
									    '''up''',
									    '''!''',
									    '''?''',
									]

									self.assertListEqual(tokenizer.tokenize(SCREAMING_SNAKE_CASE_    )       ,       SCREAMING_SNAKE_CASE_    )

									self.assertEqual(tokenizer.convert_tokens_to_string(SCREAMING_SNAKE_CASE_    )       ,       SCREAMING_SNAKE_CASE_    )







							def _lowercase					(self    ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = self.get_tokenizer()
									SCREAMING_SNAKE_CASE_						 = len(SCREAMING_SNAKE_CASE_    )

									tokenizer.add_tokens(['''new1''', '''new2''']    )
									tokenizer.move_added_token('''new1'''       ,       1    )

									# Check that moved token is not copied (duplicate)
									self.assertEqual(len(SCREAMING_SNAKE_CASE_    )       ,       original_len + 2    )
									# Check that token is moved to specified id
									self.assertEqual(tokenizer.encode('''new1'''    )       ,       [1]    )
									self.assertEqual(tokenizer.decode([1]    )       ,       '''new1'''    )