



"""simple docstring"""







import json
import os
import unittest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin
@require_tokenizers
class        __A       (	A_     ,unittest.TestCase    ):







		'''simple docstring'''





		lowerCAmelCase			:					Any   	=				CLIPTokenizer
		lowerCAmelCase			:					Union[str, Any]   	=				CLIPTokenizerFast
		lowerCAmelCase			:					List[Any]   	=				True
		lowerCAmelCase			:					Optional[int]   	=				{}
		lowerCAmelCase			:					str   	=				False







		def 					UpperCAmelCase    (	self						:  List[Any]						)					->		str:






				"""simple docstring"""



				super().setUp()

				# fmt: off
				lowercase__   :    Dict				=			['''l''', '''o''', '''w''', '''e''', '''r''', '''s''', '''t''', '''i''', '''d''', '''n''', '''lo''', '''l</w>''', '''w</w>''', '''r</w>''', '''t</w>''', '''low</w>''', '''er</w>''', '''lowest</w>''', '''newer</w>''', '''wider''', '''<unk>''', '''<|startoftext|>''', '''<|endoftext|>''']
				# fmt: on
				lowercase__   :    Union[str, Any]				=			dict(zip(_snake_case			,range(len(_snake_case						)						)						)						)
				lowercase__   :    Union[str, Any]				=			['''#version: 0.2''', '''l o''', '''lo w</w>''', '''e r</w>''']
				lowercase__   :    List[str]				=			{'''unk_token''': '''<unk>'''}

				lowercase__   :    List[Any]				=			os.path.join(self.tmpdirname			,VOCAB_FILES_NAMES['''vocab_file''']						)
				lowercase__   :    List[str]				=			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(_snake_case						) + '''\n'''						)
				with open(self.merges_file			,'''w'''			,encoding='''utf-8'''						) as fp:
						fp.write('''\n'''.join(_snake_case						)						)







		def 					UpperCAmelCase    (	self						:  Any			,**_snake_case						:  Any						)					->		str:






				"""simple docstring"""



				kwargs.update(self.special_tokens_map						)
				return CLIPTokenizer.from_pretrained(self.tmpdirname			,**_snake_case						)







		def 					UpperCAmelCase    (	self						:  Optional[Any]			,**_snake_case						:  List[str]						)					->		int:






				"""simple docstring"""



				kwargs.update(self.special_tokens_map						)
				return CLIPTokenizerFast.from_pretrained(self.tmpdirname			,**_snake_case						)







		def 					UpperCAmelCase    (	self						:  Optional[int]			,_snake_case						:  List[str]						)					->		Optional[int]:






				"""simple docstring"""



				lowercase__   :    Dict				=			'''lower newer'''
				lowercase__   :    Optional[Any]				=			'''lower newer'''
				return input_text, output_text







		def 					UpperCAmelCase    (	self						:  List[Any]						)					->		Optional[Any]:






				"""simple docstring"""



				lowercase__   :    Union[str, Any]				=			CLIPTokenizer(self.vocab_file			,self.merges_file			,**self.special_tokens_map						)
				lowercase__   :    Dict				=			'''lower newer'''
				lowercase__   :    Union[str, Any]				=			['''lo''', '''w''', '''er</w>''', '''n''', '''e''', '''w''', '''er</w>''']
				lowercase__   :    Tuple				=			tokenizer.tokenize(_snake_case						)
				self.assertListEqual(_snake_case			,_snake_case						)

				lowercase__   :    List[str]				=			tokens + [tokenizer.unk_token]
				lowercase__   :    Optional[Any]				=			[10, 2, 16, 9, 3, 2, 16, 20]
				self.assertListEqual(tokenizer.convert_tokens_to_ids(_snake_case						)			,_snake_case						)







		@require_ftfy
		def 					UpperCAmelCase    (	self						:  Tuple						)					->		List[Any]:






				"""simple docstring"""



				for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
						with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""						):
								lowercase__   :    List[str]				=			self.tokenizer_class.from_pretrained(_snake_case			,**_snake_case						)
								lowercase__   :    Dict				=			self.rust_tokenizer_class.from_pretrained(_snake_case			,**_snake_case						)

								lowercase__   :    Union[str, Any]				=			'''A\n\'ll 11p223RF☆ho!!to?\'d\'d\'\'d of a cat to-$\'\'d.'''
								lowercase__   :    str				=			tokenizer_s.tokenize(_snake_case						)
								lowercase__   :    Optional[Any]				=			tokenizer_r.tokenize(_snake_case						)

								self.assertListEqual(_snake_case			,_snake_case						)

								# Test that the tokenization is identical on an example containing a character (Latin Small Letter A
								# with Tilde) encoded in 2 different ways
								lowercase__   :    Optional[Any]				=			'''xa\u0303y''' + ''' ''' + '''x\xe3y'''
								lowercase__   :    int				=			tokenizer_s.tokenize(_snake_case						)
								lowercase__   :    Union[str, Any]				=			tokenizer_r.tokenize(_snake_case						)

								self.assertListEqual(_snake_case			,_snake_case						)

								# Test that the tokenization is identical on unicode of space type
								lowercase__   :    Optional[int]				=			[
								    '''\u0009''',  # (horizontal tab, '\t')
								    '''\u000B''',  # (vertical tab)
								    '''\u000C''',  # (form feed)
								    '''\u0020''',  # (space, ' ')
								    '''\u200E''',  # (left-to-right mark):w
								    '''\u200F''',  # (right-to-left mark)
								]
								for unicode_seq in spaces_unicodes:
										lowercase__   :    Tuple				=			tokenizer_s.tokenize(_snake_case						)
										lowercase__   :    Optional[int]				=			tokenizer_r.tokenize(_snake_case						)

										self.assertListEqual(_snake_case			,_snake_case						)

								# Test that the tokenization is identical on unicode of line break type
								lowercase__   :    Tuple				=			[
								    '''\u000A''',  # (line feed, '\n')
								    '''\r\n''',  # (carriage return and line feed, '\r\n')
								    '''\u000D''',  # (carriage return, '\r')
								    '''\r''',  # (carriage return, '\r')
								    '''\u000D''',  # (carriage return, '\r')
								    '''\u2028''',  # (line separator)
								    '''\u2029''',  # (paragraph separator)
								    # "\u0085", # (next line)
								]

								# The tokenization is not identical for the character "\u0085" (next line). The slow version using ftfy transforms
								# it into the Horizontal Ellipsis character "…" ("\u2026") while the fast version transforms it into a
								# space (and thus into an empty list).

								for unicode_seq in line_break_unicodes:
										lowercase__   :    Dict				=			tokenizer_s.tokenize(_snake_case						)
										lowercase__   :    Tuple				=			tokenizer_r.tokenize(_snake_case						)

										self.assertListEqual(_snake_case			,_snake_case						)







		def 					UpperCAmelCase    (	self						:  Union[str, Any]						)					->		Optional[int]:






				"""simple docstring"""



				for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
						with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""						):
								lowercase__   :    Union[str, Any]				=			'''hello'''  # `hello` is a token in the vocabulary of `pretrained_name`
								lowercase__   :    List[Any]				=			f"""{text_of_1_token} {text_of_1_token}"""

								lowercase__   :    Dict				=			self.rust_tokenizer_class.from_pretrained(
								    _snake_case			,use_fast=_snake_case			,)
								lowercase__   :    Optional[int]				=			tokenizer_r(_snake_case			,return_offsets_mapping=_snake_case			,add_special_tokens=_snake_case						)
								self.assertEqual(encoding.offset_mapping[0]			,(0, len(_snake_case						))						)
								self.assertEqual(
								    encoding.offset_mapping[1]			,(len(_snake_case						) + 1, len(_snake_case						) + 1 + len(_snake_case						))			,)

								lowercase__   :    Tuple				=			f""" {text}"""

								lowercase__   :    Any				=			self.rust_tokenizer_class.from_pretrained(
								    _snake_case			,use_fast=_snake_case			,)
								lowercase__   :    Dict				=			tokenizer_r(_snake_case			,return_offsets_mapping=_snake_case			,add_special_tokens=_snake_case						)
								self.assertEqual(encoding.offset_mapping[0]			,(1, 1 + len(_snake_case						))						)
								self.assertEqual(
								    encoding.offset_mapping[1]			,(1 + len(_snake_case						) + 1, 1 + len(_snake_case						) + 1 + len(_snake_case						))			,)







		def 					UpperCAmelCase    (	self						:  Any						)					->		Tuple:






				"""simple docstring"""



				with self.assertRaises(_snake_case						) as context:
						self.rust_tokenizer_class.from_pretrained('''robot-test/old-clip-tokenizer'''						)

				self.assertTrue(
				    context.exception.args[0].startswith(
				        '''The `backend_tokenizer` provided does not match the expected format.'''						)						)







		@require_ftfy
		def 					UpperCAmelCase    (	self						:  Any						)					->		Union[str, Any]:






				"""simple docstring"""



				super().test_tokenization_python_rust_equals()







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






				"""simple docstring"""



				pass






from math import pi, sqrt, tan







def 			lowerCamelCase_		(       UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if side_length < 0:
								raise ValueError('surface_area_cube() only accepts non-negative values'      )
				return 6 * side_length**2







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if length < 0 or breadth < 0 or height < 0:
								raise ValueError('surface_area_cuboid() only accepts non-negative values'      )
				return 2 * ((length * breadth) + (breadth * height) + (length * height))







def 			lowerCamelCase_		(       UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius < 0:
								raise ValueError('surface_area_sphere() only accepts non-negative values'      )
				return 4 * pi * radius**2







def 			lowerCamelCase_		(       UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius < 0:
								raise ValueError('surface_area_hemisphere() only accepts non-negative values'      )
				return 3 * pi * radius**2







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius < 0 or height < 0:
								raise ValueError('surface_area_cone() only accepts non-negative values'      )
				return pi * radius * (radius + (height**2 + radius**2) ** 0.5)







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius_a < 0 or radius_a < 0 or height < 0:
								raise ValueError(
								    'surface_area_conical_frustum() only accepts non-negative values'      )
				__lowerCamelCase		       =    (height**2 + (radius_a - radius_a) ** 2) ** 0.5
				return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius < 0 or height < 0:
								raise ValueError('surface_area_cylinder() only accepts non-negative values'      )
				return 2 * pi * radius * (height + radius)







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if torus_radius < 0 or tube_radius < 0:
								raise ValueError('surface_area_torus() only accepts non-negative values'      )
				if torus_radius < tube_radius:
								raise ValueError(
								    'surface_area_torus() does not support spindle or self intersecting tori'      )
				return 4 * pow(UpperCamelCase__ ,     2      ) * torus_radius * tube_radius







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if length < 0 or width < 0:
								raise ValueError('area_rectangle() only accepts non-negative values'      )
				return length * width







def 			lowerCamelCase_		(       UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if side_length < 0:
								raise ValueError('area_square() only accepts non-negative values'      )
				return side_length**2







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if base < 0 or height < 0:
								raise ValueError('area_triangle() only accepts non-negative values'      )
				return (base * height) / 2







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if sidea < 0 or sidea < 0 or sidea < 0:
								raise ValueError('area_triangle_three_sides() only accepts non-negative values'      )
				elif sidea + sidea < sidea or sidea + sidea < sidea or sidea + sidea < sidea:
								raise ValueError('Given three sides do not form a triangle'      )
				__lowerCamelCase		       =    (sidea + sidea + sidea) / 2
				__lowerCamelCase		       =    sqrt(
				    semi_perimeter
				    * (semi_perimeter - sidea)
				    * (semi_perimeter - sidea)
				    * (semi_perimeter - sidea)      )
				return area







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if base < 0 or height < 0:
								raise ValueError('area_parallelogram() only accepts non-negative values'      )
				return base * height







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if basea < 0 or basea < 0 or height < 0:
								raise ValueError('area_trapezium() only accepts non-negative values'      )
				return 1 / 2 * (basea + basea) * height







def 			lowerCamelCase_		(       UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius < 0:
								raise ValueError('area_circle() only accepts non-negative values'      )
				return pi * radius**2







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if radius_x < 0 or radius_y < 0:
								raise ValueError('area_ellipse() only accepts non-negative values'      )
				return pi * radius_x * radius_y







def 			lowerCamelCase_		(       UpperCamelCase__				:      float ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if diagonal_a < 0 or diagonal_a < 0:
								raise ValueError('area_rhombus() only accepts non-negative values'      )
				return 1 / 2 * diagonal_a * diagonal_a







def 			lowerCamelCase_		(       UpperCamelCase__				:      int ,     UpperCamelCase__				:      float      )     ->       float:





				"""simple docstring"""


				if not isinstance(UpperCamelCase__ ,     UpperCamelCase__      ) or sides < 3:
								raise ValueError(
								    'area_reg_polygon() only accepts integers greater than or \
equal to three as number of sides'      )
				elif length < 0:
								raise ValueError(
								    'area_reg_polygon() only accepts non-negative values as \
length of a side'      )
				return (sides * length**2) / (4 * tan(pi / sides      ))
				return (sides * length**2) / (4 * tan(pi / sides      ))


if __name__ == "__main__":
					import doctest

					doctest.testmod(verbose=True)  # verbose so we can see methods missing tests

					print("[DEMO] Areas of various geometric shapes: \n")
					print(f'''Rectangle: {area_rectangle(10, 20) = }''')
					print(f'''Square: {area_square(10) = }''')
					print(f'''Triangle: {area_triangle(10, 10) = }''')
					print(f'''Triangle: {area_triangle_three_sides(5, 12, 13) = }''')
					print(f'''Parallelogram: {area_parallelogram(10, 20) = }''')
					print(f'''Rhombus: {area_rhombus(10, 20) = }''')
					print(f'''Trapezium: {area_trapezium(10, 20, 30) = }''')
					print(f'''Circle: {area_circle(20) = }''')
					print(f'''Ellipse: {area_ellipse(10, 20) = }''')
					print("\nSurface Areas of various geometric shapes: \n")
					print(f'''Cube: {surface_area_cube(20) = }''')
					print(f'''Cuboid: {surface_area_cuboid(10, 20, 30) = }''')
					print(f'''Sphere: {surface_area_sphere(20) = }''')
					print(f'''Hemisphere: {surface_area_hemisphere(20) = }''')
					print(f'''Cone: {surface_area_cone(10, 20) = }''')
					print(f'''Conical Frustum: {surface_area_conical_frustum(10, 20, 30) = }''')
					print(f'''Cylinder: {surface_area_cylinder(10, 20) = }''')
					print(f'''Torus: {surface_area_torus(20, 10) = }''')
					print(f'''Equilateral Triangle: {area_reg_polygon(3, 10) = }''')
					print(f'''Square: {area_reg_polygon(4, 10) = }''')
					print(f'''Reqular Pentagon: {area_reg_polygon(5, 10) = }''')


