


'''simple docstring'''
import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_MAPPING,
     SegformerForImageClassification,
     SegformerForSemanticSegmentation,
     SegformerModel,
 )
 from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import SegformerImageProcessor

class 						_lowerCamelCase					(    snake_case_				):




 '''simple docstring'''


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Optional[int]       =			self.config_class(**self.inputs_dict						)
       self.parent.assertTrue(hasattr(__lowercase      ,      'hidden_sizes'						)						)
       self.parent.assertTrue(hasattr(__lowercase      ,      'num_attention_heads'						)						)
       self.parent.assertTrue(hasattr(__lowercase      ,      'num_encoder_blocks'						)						)


class 						_lowerCamelCase					:




 '''simple docstring'''


 def __init__(      self      ,      __lowercase      ,      __lowercase=13      ,      __lowercase=64      ,      __lowercase=3      ,      __lowercase=4      ,      __lowercase=[2, 2, 2, 2]      ,      __lowercase=[8, 4, 2, 1]      ,      __lowercase=[16, 32, 64, 128]      ,      __lowercase=[1, 4, 8, 16]      ,      __lowercase=[1, 2, 4, 8]      ,      __lowercase=True      ,      __lowercase=True      ,      __lowercase="gelu"      ,      __lowercase=0.1      ,      __lowercase=0.1      ,      __lowercase=0.0_2      ,      __lowercase=3      ,      __lowercase=None      ,      ):

       """simple docstring"""







       __A  :		Any       =			parent
       __A  :		Tuple       =			batch_size
       __A  :		Any       =			image_size
       __A  :		str       =			num_channels
       __A  :		Optional[int]       =			num_encoder_blocks
       __A  :		int       =			sr_ratios
       __A  :		int       =			depths
       __A  :		Optional[Any]       =			hidden_sizes
       __A  :		int       =			downsampling_rates
       __A  :		str       =			num_attention_heads
       __A  :		List[str]       =			is_training
       __A  :		Any       =			use_labels
       __A  :		Dict       =			hidden_act
       __A  :		Union[str, Any]       =			hidden_dropout_prob
       __A  :		List[str]       =			attention_probs_dropout_prob
       __A  :		Optional[Any]       =			initializer_range
       __A  :		Optional[Any]       =			num_labels
       __A  :		int       =			scope


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Union[str, Any]       =			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

       __A  :		int       =			None
       if self.use_labels:
             __A  :		str       =			ids_tensor([self.batch_size, self.image_size, self.image_size]      ,      self.num_labels						)

       __A  :		List[Any]       =			self.get_config()
       return config, pixel_values, labels


 def  snake_case__   (      self						):

       """simple docstring"""







       return SegformerConfig(
           image_size=self.image_size      ,      num_channels=self.num_channels      ,      num_encoder_blocks=self.num_encoder_blocks      ,      depths=self.depths      ,      hidden_sizes=self.hidden_sizes      ,      num_attention_heads=self.num_attention_heads      ,      hidden_act=self.hidden_act      ,      hidden_dropout_prob=self.hidden_dropout_prob      ,      attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,      initializer_range=self.initializer_range      ,      )


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase						):

       """simple docstring"""







       __A  :		Optional[int]       =			SegformerModel(config=__lowercase						)
       model.to(__lowercase						)
       model.eval()
       __A  :		str       =			model(__lowercase						)
       __A  :		Optional[int]       =			self.image_size // (self.downsampling_rates[-1] * 2)
       self.parent.assertEqual(
           result.last_hidden_state.shape      ,      (self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)						)


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase						):

       """simple docstring"""







       __A  :		Optional[Any]       =			self.num_labels
       __A  :		List[str]       =			SegformerForSemanticSegmentation(__lowercase						)
       model.to(__lowercase						)
       model.eval()
       __A  :		Dict       =			model(__lowercase						)
       self.parent.assertEqual(
           result.logits.shape      ,      (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)						)
       __A  :		int       =			model(__lowercase      ,      labels=__lowercase						)
       self.parent.assertEqual(
           result.logits.shape      ,      (self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)						)
       self.parent.assertGreater(result.loss      ,      0.0						)


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase						):

       """simple docstring"""







       __A  :		int       =			1
       __A  :		Any       =			SegformerForSemanticSegmentation(config=__lowercase						)
       model.to(__lowercase						)
       model.eval()
       __A  :		List[Any]       =			torch.randint(0      ,      1      ,      (self.batch_size, self.image_size, self.image_size)						).to(__lowercase						)
       __A  :		Optional[Any]       =			model(__lowercase      ,      labels=__lowercase						)
       self.parent.assertGreater(result.loss      ,      0.0						)







 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		int       =			self.prepare_config_and_inputs()
       __A  :		int       =			config_and_inputs
       __A  :		List[str]       =			{'pixel_values': pixel_values}
       return config, inputs_dict


@require_torch
class 						_lowerCamelCase					(    snake_case_    ,		snake_case_    ,		unittest.TestCase				):




 '''simple docstring'''
 __lowercase				:		str    							=						(
     (
         SegformerModel,
         SegformerForSemanticSegmentation,
         SegformerForImageClassification,
     )
     if is_torch_available()
     else ()
 )
 __lowercase				:		int    							=						(
     {
         '''feature-extraction''': SegformerModel,
         '''image-classification''': SegformerForImageClassification,
         '''image-segmentation''': SegformerForSemanticSegmentation,
     }
     if is_torch_available()
     else {}
 )

 __lowercase				:		List[str]    							=						True
 __lowercase				:		List[str]    							=						False
 __lowercase				:		List[str]    							=						False
 __lowercase				:		Dict    							=						False


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		int       =			SegformerModelTester(self						)
       __A  :		Dict       =			SegformerConfigTester(self      ,      config_class=__lowercase						)


 def  snake_case__   (      self						):

       """simple docstring"""







       self.config_tester.run_common_tests()


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Any       =			self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__lowercase						)


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		str       =			self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_binary_image_segmentation(*__lowercase						)


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		List[Any]       =			self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_segmentation(*__lowercase						)


 @unittest.skip('SegFormer does not use inputs_embeds'						)
 def  snake_case__   (      self						):

       """simple docstring"""







       pass


 @unittest.skip('SegFormer does not have get_input_embeddings method and get_output_embeddings methods'						)
 def  snake_case__   (      self						):

       """simple docstring"""







       pass


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Dict       =			self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
             __A  :		int       =			model_class(__lowercase						)
             __A  :		Any       =			inspect.signature(model.forward						)
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             __A  :		List[Any]       =			[*signature.parameters.keys()]

             __A  :		str       =			['pixel_values']
             self.assertListEqual(arg_names[:1]      ,      __lowercase						)


 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Optional[Any]       =			self.model_tester.prepare_config_and_inputs_for_common()
       __A  :		int       =			True

       for model_class in self.all_model_classes:
             __A  :		Optional[int]       =			True
             __A  :		Any       =			False
             __A  :		List[Any]       =			True
             __A  :		int       =			model_class(__lowercase						)
             model.to(__lowercase						)
             model.eval()
             with torch.no_grad():
                   __A  :		int       =			model(**self._prepare_for_class(__lowercase      ,      __lowercase						)						)
             __A  :		int       =			outputs.attentions

             __A  :		int       =			sum(self.model_tester.depths						)
             self.assertEqual(len(__lowercase						)      ,      __lowercase						)

             # check that output_attentions also work using config
             del inputs_dict["output_attentions"]
             __A  :		int       =			True
             __A  :		List[Any]       =			model_class(__lowercase						)
             model.to(__lowercase						)
             model.eval()
             with torch.no_grad():
                   __A  :		List[str]       =			model(**self._prepare_for_class(__lowercase      ,      __lowercase						)						)
             __A  :		Tuple       =			outputs.attentions

             self.assertEqual(len(__lowercase						)      ,      __lowercase						)

             # verify the first attentions (first block, first layer)
             __A  :		Optional[int]       =			(self.model_tester.image_size // 4) ** 2
             __A  :		Tuple       =			(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
             self.assertListEqual(
                 list(attentions[0].shape[-3:]						)      ,      [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]      ,      )

             # verify the last attentions (last block, last layer)
             __A  :		List[Any]       =			(self.model_tester.image_size // 32) ** 2
             __A  :		int       =			(self.model_tester.image_size // (32 * self.model_tester.sr_ratios[-1])) ** 2
             self.assertListEqual(
                 list(attentions[-1].shape[-3:]						)      ,      [self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]      ,      )
             __A  :		Tuple       =			len(__lowercase						)

             # Check attention is always last and order is fine
             __A  :		Tuple       =			True
             __A  :		Dict       =			True
             __A  :		int       =			model_class(__lowercase						)
             model.to(__lowercase						)
             model.eval()
             with torch.no_grad():
                   __A  :		Tuple       =			model(**self._prepare_for_class(__lowercase      ,      __lowercase						)						)

             self.assertEqual(out_len + 1      ,      len(__lowercase						)						)

             __A  :		Optional[Any]       =			outputs.attentions

             self.assertEqual(len(__lowercase						)      ,      __lowercase						)
             # verify the first attentions (first block, first layer)
             __A  :		Union[str, Any]       =			(self.model_tester.image_size // 4) ** 2
             __A  :		Union[str, Any]       =			(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
             self.assertListEqual(
                 list(self_attentions[0].shape[-3:]						)      ,      [self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]      ,      )


 def  snake_case__   (      self						):

       """simple docstring"""







       def check_hidden_states_output(__lowercase      ,      __lowercase      ,      __lowercase						):
             __A  :		Tuple       =			model_class(__lowercase						)
             model.to(__lowercase						)
             model.eval()

             with torch.no_grad():
                   __A  :		Any       =			model(**self._prepare_for_class(__lowercase      ,      __lowercase						)						)

             __A  :		int       =			outputs.hidden_states

             __A  :		Optional[int]       =			self.model_tester.num_encoder_blocks
             self.assertEqual(len(__lowercase						)      ,      __lowercase						)

             # verify the first hidden states (first block)
             self.assertListEqual(
                 list(hidden_states[0].shape[-3:]						)      ,      [
                     self.model_tester.hidden_sizes[0],
                     self.model_tester.image_size // 4,
                     self.model_tester.image_size // 4,
                 ]      ,      )

       __A  :		Tuple       =			self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
             __A  :		List[Any]       =			True
             check_hidden_states_output(__lowercase      ,      __lowercase      ,      __lowercase						)

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             __A  :		List[Any]       =			True

             check_hidden_states_output(__lowercase      ,      __lowercase      ,      __lowercase						)


 def  snake_case__   (      self						):

       """simple docstring"""







       if not self.model_tester.is_training:
             return

       __A  :		int       =			self.model_tester.prepare_config_and_inputs_for_common()
       __A  :		List[str]       =			True

       for model_class in self.all_model_classes:
             if model_class in get_values(__lowercase						):
                   continue

             __A  :		List[str]       =			model_class(__lowercase						)
             model.to(__lowercase						)
             model.train()
             __A  :		str       =			self._prepare_for_class(__lowercase      ,      __lowercase      ,      return_labels=__lowercase						)
             __A  :		Optional[Any]       =			model(**__lowercase						).loss
             loss.backward()


 @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'						)
 def  snake_case__   (      self						):

       """simple docstring"""







       pass







 @slow
 def  snake_case__   (      self						):

       """simple docstring"""







       for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             __A  :		Optional[int]       =			SegformerModel.from_pretrained(__lowercase						)
             self.assertIsNotNone(__lowercase						)


def 			_lowercase       (				):
      __A  :		List[str]       =			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
      return image


@require_torch
class 						_lowerCamelCase					(    unittest.TestCase				):




 '''simple docstring'''


 @slow
 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		List[str]       =			SegformerImageProcessor(
           image_scale=(512, 512)      ,      keep_ratio=__lowercase      ,      align=__lowercase      ,      do_random_crop=__lowercase						)
       __A  :		Union[str, Any]       =			SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512'						).to(
           __lowercase						)

       __A  :		Any       =			prepare_img()
       __A  :		int       =			image_processor(images=__lowercase      ,      return_tensors='pt'						)
       __A  :		int       =			encoded_inputs.pixel_values.to(__lowercase						)

       with torch.no_grad():
             __A  :		List[str]       =			model(__lowercase						)

       __A  :		int       =			torch.Size((1, model.config.num_labels, 128, 128)						)
       self.assertEqual(outputs.logits.shape      ,      __lowercase						)

       __A  :		Any       =			torch.tensor(
           [
               [[-4.6_3_1_0, -5.5_2_3_2, -6.2_3_5_6], [-5.1_9_2_1, -6.1_4_4_4, -6.5_9_9_6], [-5.4_4_2_4, -6.2_7_9_0, -6.7_5_7_4]],
               [[-12.1_391, -13.3_122, -13.9_554], [-12.8_732, -13.9_352, -14.3_563], [-12.9_438, -13.8_226, -14.2_513]],
               [[-12.5_134, -13.4_686, -14.4_915], [-12.8_669, -14.4_343, -14.7_758], [-13.2_523, -14.5_819, -15.0_694]],
           ]						).to(__lowercase						)
       self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]      ,      __lowercase      ,      atol=1E-4						)						)


 @slow
 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Optional[Any]       =			SegformerImageProcessor(
           image_scale=(512, 512)      ,      keep_ratio=__lowercase      ,      align=__lowercase      ,      do_random_crop=__lowercase						)
       __A  :		List[str]       =			SegformerForSemanticSegmentation.from_pretrained(
           'nvidia/segformer-b1-finetuned-cityscapes-1024-1024'						).to(__lowercase						)

       __A  :		Dict       =			prepare_img()
       __A  :		Any       =			image_processor(images=__lowercase      ,      return_tensors='pt'						)
       __A  :		List[str]       =			encoded_inputs.pixel_values.to(__lowercase						)

       with torch.no_grad():
             __A  :		Optional[Any]       =			model(__lowercase						)

       __A  :		Union[str, Any]       =			torch.Size((1, model.config.num_labels, 128, 128)						)
       self.assertEqual(outputs.logits.shape      ,      __lowercase						)

       __A  :		int       =			torch.tensor(
           [
               [[-13.5_748, -13.9_111, -12.6_500], [-14.3_500, -15.3_683, -14.2_328], [-14.7_532, -16.0_424, -15.6_087]],
               [[-17.1_651, -15.8_725, -12.9_653], [-17.2_580, -17.3_718, -14.8_223], [-16.6_058, -16.8_783, -16.7_452]],
               [[-3.6_4_5_6, -3.0_2_0_9, -1.4_2_0_3], [-3.0_7_9_7, -3.1_9_5_9, -2.0_0_0_0], [-1.8_7_5_7, -1.9_2_1_7, -1.6_9_9_7]],
           ]						).to(__lowercase						)
       self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]      ,      __lowercase      ,      atol=1E-1						)						)







 @slow
 def  snake_case__   (      self						):

       """simple docstring"""







       __A  :		Union[str, Any]       =			SegformerImageProcessor(
           image_scale=(512, 512)      ,      keep_ratio=__lowercase      ,      align=__lowercase      ,      do_random_crop=__lowercase						)
       __A  :		str       =			SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512'						).to(
           __lowercase						)

       __A  :		str       =			prepare_img()
       __A  :		Dict       =			image_processor(images=__lowercase      ,      return_tensors='pt'						)
       __A  :		str       =			encoded_inputs.pixel_values.to(__lowercase						)

       with torch.no_grad():
             __A  :		Optional[int]       =			model(__lowercase						)

       __A  :		Union[str, Any]       =			outputs.logits.detach().cpu()

       __A  :		Tuple       =			image_processor.post_process_semantic_segmentation(outputs=__lowercase      ,      target_sizes=[(500, 300)]						)
       __A  :		int       =			torch.Size((500, 300)						)
       self.assertEqual(segmentation[0].shape      ,      __lowercase						)

       __A  :		List[str]       =			image_processor.post_process_semantic_segmentation(outputs=__lowercase						)
       __A  :		Tuple       =			torch.Size((128, 128)						)
       self.assertEqual(segmentation[0].shape      ,      __lowercase						)










'''simple docstring'''
from math import pi, sqrt, tan


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


def 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 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 			_lowercase       (				UpperCamelCase__       :					float			):
 if radius < 0:
  raise ValueError('surface_area_sphere() only accepts non-negative values'			)
 return 4 * pi * radius**2


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


def 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 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 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 if radius_a < 0 or radius_a < 0 or height < 0:
  raise ValueError(
      'surface_area_conical_frustum() only accepts non-negative values'			)
 __A  :		Optional[Any]       =			(height**2 + (radius_a - radius_a) ** 2) ** 0.5
 return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)


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


def 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 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 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 if length < 0 or width < 0:
  raise ValueError('area_rectangle() only accepts non-negative values'			)
 return length * width


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


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


def 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 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'			)
 __A  :		int       =			(sidea + sidea + sidea) / 2
 __A  :		List[Any]       =			sqrt(
     semi_perimeter
     * (semi_perimeter - sidea)
     * (semi_perimeter - sidea)
     * (semi_perimeter - sidea)			)
 return area


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


def 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 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 			_lowercase       (				UpperCamelCase__       :					float			):
 if radius < 0:
  raise ValueError('area_circle() only accepts non-negative values'			)
 return pi * radius**2


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


def 			_lowercase       (				UpperCamelCase__       :					float,				UpperCamelCase__       :					float			):
 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 			_lowercase       (				UpperCamelCase__       :					int,				UpperCamelCase__       :					float			):
 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(1_0, 2_0) = }''')
 print(f'''Square: {area_square(1_0) = }''')
 print(f'''Triangle: {area_triangle(1_0, 1_0) = }''')
 print(f'''Triangle: {area_triangle_three_sides(5, 1_2, 1_3) = }''')
 print(f'''Parallelogram: {area_parallelogram(1_0, 2_0) = }''')
 print(f'''Rhombus: {area_rhombus(1_0, 2_0) = }''')
 print(f'''Trapezium: {area_trapezium(1_0, 2_0, 3_0) = }''')
 print(f'''Circle: {area_circle(2_0) = }''')
 print(f'''Ellipse: {area_ellipse(1_0, 2_0) = }''')
 print('\nSurface Areas of various geometric shapes: \n')
 print(f'''Cube: {surface_area_cube(2_0) = }''')
 print(f'''Cuboid: {surface_area_cuboid(1_0, 2_0, 3_0) = }''')
 print(f'''Sphere: {surface_area_sphere(2_0) = }''')
 print(f'''Hemisphere: {surface_area_hemisphere(2_0) = }''')
 print(f'''Cone: {surface_area_cone(1_0, 2_0) = }''')
 print(f'''Conical Frustum: {surface_area_conical_frustum(1_0, 2_0, 3_0) = }''')
 print(f'''Cylinder: {surface_area_cylinder(1_0, 2_0) = }''')
 print(f'''Torus: {surface_area_torus(2_0, 1_0) = }''')
 print(f'''Equilateral Triangle: {area_reg_polygon(3, 1_0) = }''')
 print(f'''Square: {area_reg_polygon(4, 1_0) = }''')
 print(f'''Reqular Pentagon: {area_reg_polygon(5, 1_0) = }''')






