


'''simple docstring'''

import os
import tempfile
import unittest

import numpy as np
import torch

from diffusers.models import ModelMixin, UNetaDConditionModel
from diffusers.models.attention_processor import AttnProcessor, LoRAAttnProcessor
from diffusers.utils import (
    floats_tensor,
    logging,
    skip_mps,
    torch_device,
)
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()

_UpperCAmelCase					:			Dict				     =					logging.get_logger(__name__)

def 				__magic_name__(    lowerCamelCase,					lowerCamelCase = True):
						__lowerCAmelCase											=					{}
						for name in model.attn_processors.keys():
												__lowerCAmelCase											=					name.endswith('''attn2.processor''') and not (
												    name.startswith('''transformer_in''') or 'temp_attentions' in name.split('''.''')
												)
												__lowerCAmelCase											=					model.config.cross_attention_dim if has_cross_attention else None
												if name.startswith('''mid_block'''):
																		__lowerCAmelCase											=					model.config.block_out_channels[-1]
												elif name.startswith('''up_blocks'''):
																		__lowerCAmelCase											=					int(name[len('''up_blocks.''')])
																		__lowerCAmelCase											=					list(reversed(model.config.block_out_channels))[block_id]
												elif name.startswith('''down_blocks'''):
																		__lowerCAmelCase											=					int(name[len('''down_blocks.''')])
																		__lowerCAmelCase											=					model.config.block_out_channels[block_id]
												elif name.startswith('''transformer_in'''):
																		# Note that the `8 * ...` comes from: https://github.com/huggingface/diffusers/blob/7139f0e874f10b2463caa8cbd585762a309d12d6/src/diffusers/models/unet_3d_condition.py#L148
																		__lowerCAmelCase											=					8 * model.config.attention_head_dim

												__lowerCAmelCase											=					LoRAAttnProcessor(hidden_size=SCREAMING_SNAKE_CASE_,					cross_attention_dim=SCREAMING_SNAKE_CASE_)
												__lowerCAmelCase											=					lora_attn_procs[name].to(model.device)

												if mock_weights:
																		# add 1 to weights to mock trained weights
																		with torch.no_grad():
																								lora_attn_procs[name].to_q_lora.up.weight += 1
																								lora_attn_procs[name].to_k_lora.up.weight += 1
																								lora_attn_procs[name].to_v_lora.up.weight += 1
																								lora_attn_procs[name].to_out_lora.up.weight += 1

						return lora_attn_procs




@skip_mps
class    a__					(			_snake_case				,    _snake_case				,    unittest.TestCase   ):







				"""simple docstring"""



				__UpperCamelCase     :		Optional[Any]						=						UNetaDConditionModel
				__UpperCamelCase     :		List[str]						=						'''sample'''




				@property
				def        _snake_case	(self		):
										__lowerCAmelCase											=					4
										__lowerCAmelCase											=					4
										__lowerCAmelCase											=					4
										__lowerCAmelCase											=					(32, 32)

										__lowerCAmelCase											=					floats_tensor((batch_size, num_channels, num_frames) + sizes		).to(_a		)
										__lowerCAmelCase											=					torch.tensor([10]		).to(_a		)
										__lowerCAmelCase											=					floats_tensor((batch_size, 4, 32)		).to(_a		)

										return {"sample": noise, "timestep": time_step, "encoder_hidden_states": encoder_hidden_states}




				@property
				def        _snake_case	(self		):
										return (4, 4, 32, 32)




				@property
				def        _snake_case	(self		):
										return (4, 4, 32, 32)




				def        _snake_case	(self		):
										__lowerCAmelCase											=					{
										    'block_out_channels': (32, 64),
										    'down_block_types': (
										        'CrossAttnDownBlock3D',
										        'DownBlock3D',
										    ),
										    'up_block_types': ('UpBlock3D', 'CrossAttnUpBlock3D'),
										    'cross_attention_dim': 32,
										    'attention_head_dim': 8,
										    'out_channels': 4,
										    'in_channels': 4,
										    'layers_per_block': 1,
										    'sample_size': 32,
										}
										__lowerCAmelCase											=					self.dummy_input
										return init_dict, inputs_dict




				@unittest.skipIf(
				    torch_device != '''cuda''' or not is_xformers_available()							,      reason='''XFormers attention is only available with CUDA and `xformers` installed'''							,      )
				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()
										__lowerCAmelCase											=					self.model_class(**_a		)

										model.enable_xformers_memory_efficient_attention()

										assert (
										    model.mid_block.attentions[0].transformer_blocks[0].attna.processor.__class__.__name__
										    == "XFormersAttnProcessor"
										), "xformers is not enabled"




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					32

										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)
										model.eval()

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		)

																if isinstance(_a							,      _a		):
																						__lowerCAmelCase											=					output.sample

										self.assertIsNotNone(_a		)
										__lowerCAmelCase											=					inputs_dict['sample'].shape
										self.assertEqual(output.shape							,      _a							,      '''Input and output shapes do not match'''		)




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)
										model.eval()

										with torch.no_grad():
																# Warmup pass when using mps (see #372)
																if torch_device == "mps" and isinstance(_a							,      _a		):
																						model(**self.dummy_input		)

																__lowerCAmelCase											=					model(**_a		)
																if isinstance(_a							,      _a		):
																						__lowerCAmelCase											=					first.sample

																__lowerCAmelCase											=					model(**_a		)
																if isinstance(_a							,      _a		):
																						__lowerCAmelCase											=					second.sample

										__lowerCAmelCase											=					first.cpu().numpy()
										__lowerCAmelCase											=					second.cpu().numpy()
										__lowerCAmelCase											=					out_a[~np.isnan(_a		)]
										__lowerCAmelCase											=					out_a[~np.isnan(_a		)]
										__lowerCAmelCase											=					np.amax(np.abs(out_a - out_a		)		)
										self.assertLessEqual(_a							,      1e-5		)




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)
										model.eval()

										model.set_attention_slice('''auto'''		)
										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		)
										assert output is not None

										model.set_attention_slice('''max'''		)
										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		)
										assert output is not None

										model.set_attention_slice(2		)
										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		)
										assert output is not None




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		).sample

										__lowerCAmelCase											=					create_lora_layers(_a		)

										# make sure we can set a list of attention processors
										model.set_attn_processor(_a		)
										model.to(_a		)

										# test that attn processors can be set to itself
										model.set_attn_processor(model.attn_processors		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a							,      cross_attention_kwargs={'''scale''': 0.0}		).sample
																__lowerCAmelCase											=					model(**_a							,      cross_attention_kwargs={'''scale''': 0.5}		).sample
																__lowerCAmelCase											=					model(**_a							,      cross_attention_kwargs={'''scale''': 0.5}		).sample

										assert (samplea - samplea).abs().max() < 3e-3
										assert (samplea - samplea).abs().max() < 3e-3

										# sample 2 and sample 3 should be different
										assert (samplea - samplea).abs().max() > 3e-3




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										torch.manual_seed(0		)
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		).sample

										__lowerCAmelCase											=					create_lora_layers(_a		)
										model.set_attn_processor(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a							,      cross_attention_kwargs={'''scale''': 0.5}		).sample

										with tempfile.TemporaryDirectory() as tmpdirname:
																model.save_attn_procs(_a		)
																self.assertTrue(os.path.isfile(os.path.join(_a							,      '''pytorch_lora_weights.bin'''		)		)		)
																torch.manual_seed(0		)
																__lowerCAmelCase											=					self.model_class(**_a		)
																new_model.to(_a		)
																new_model.load_attn_procs(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					new_model(**_a							,      cross_attention_kwargs={'''scale''': 0.5}		).sample

										assert (sample - new_sample).abs().max() < 1e-3

										# LoRA and no LoRA should NOT be the same
										assert (sample - old_sample).abs().max() > 1e-4




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										torch.manual_seed(0		)
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		).sample

										__lowerCAmelCase											=					create_lora_layers(_a		)
										model.set_attn_processor(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a							,      cross_attention_kwargs={'''scale''': 0.5}		).sample

										with tempfile.TemporaryDirectory() as tmpdirname:
																model.save_attn_procs(_a							,      safe_serialization=_a		)
																self.assertTrue(os.path.isfile(os.path.join(_a							,      '''pytorch_lora_weights.safetensors'''		)		)		)
																torch.manual_seed(0		)
																__lowerCAmelCase											=					self.model_class(**_a		)
																new_model.to(_a		)
																new_model.load_attn_procs(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					new_model(**_a							,      cross_attention_kwargs={'''scale''': 0.5}		).sample

										assert (sample - new_sample).abs().max() < 3e-3

										# LoRA and no LoRA should NOT be the same
										assert (sample - old_sample).abs().max() > 1e-4




				def        _snake_case	(self		):
										# enable deterministic behavior for gradient checkpointing
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										torch.manual_seed(0		)
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)

										__lowerCAmelCase											=					create_lora_layers(_a							,      mock_weights=_a		)
										model.set_attn_processor(_a		)
										# Saving as torch, properly reloads with directly filename
										with tempfile.TemporaryDirectory() as tmpdirname:
																model.save_attn_procs(_a		)
																self.assertTrue(os.path.isfile(os.path.join(_a							,      '''pytorch_lora_weights.bin'''		)		)		)
																torch.manual_seed(0		)
																__lowerCAmelCase											=					self.model_class(**_a		)
																new_model.to(_a		)
																new_model.load_attn_procs(_a							,      weight_name='''pytorch_lora_weights.bin'''		)




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										torch.manual_seed(0		)
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)

										__lowerCAmelCase											=					create_lora_layers(_a							,      mock_weights=_a		)
										model.set_attn_processor(_a		)
										# Saving as torch, properly reloads with directly filename
										with tempfile.TemporaryDirectory() as tmpdirname:
																model.save_attn_procs(_a		)
																self.assertTrue(os.path.isfile(os.path.join(_a							,      '''pytorch_lora_weights.bin'''		)		)		)
																torch.manual_seed(0		)
																__lowerCAmelCase											=					self.model_class(**_a		)
																new_model.to(_a		)
																with self.assertRaises(_a		) as e:
																						new_model.load_attn_procs(_a							,      use_safetensors=_a		)
																self.assertIn('''Error no file named pytorch_lora_weights.safetensors'''							,      str(e.exception		)		)




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					8

										torch.manual_seed(0		)
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		).sample

										__lowerCAmelCase											=					create_lora_layers(_a		)
										model.set_attn_processor(_a		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a							,      cross_attention_kwargs={'''scale''': 0.0}		).sample

										model.set_attn_processor(AttnProcessor()		)

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		).sample

										assert (sample - new_sample).abs().max() < 1e-4
										assert (sample - old_sample).abs().max() < 3e-3




				@unittest.skipIf(
				    torch_device != '''cuda''' or not is_xformers_available()							,      reason='''XFormers attention is only available with CUDA and `xformers` installed'''							,      )
				def        _snake_case	(self		):
										# enable deterministic behavior for gradient checkpointing
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()

										__lowerCAmelCase											=					4

										torch.manual_seed(0		)
										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)
										__lowerCAmelCase											=					create_lora_layers(_a		)
										model.set_attn_processor(_a		)

										# default
										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		).sample

																model.enable_xformers_memory_efficient_attention()
																__lowerCAmelCase											=					model(**_a		).sample

																model.disable_xformers_memory_efficient_attention()
																__lowerCAmelCase											=					model(**_a		).sample

										assert (sample - on_sample).abs().max() < 1e-4
										assert (sample - off_sample).abs().max() < 1e-4




				def        _snake_case	(self		):
										__lowerCAmelCase											=					self.prepare_init_args_and_inputs_for_common()
										__lowerCAmelCase											=					32

										__lowerCAmelCase											=					self.model_class(**_a		)
										model.to(_a		)
										model.eval()

										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		)[0]

										model.enable_forward_chunking()
										with torch.no_grad():
																__lowerCAmelCase											=					model(**_a		)[0]

										self.assertEqual(output.shape							,      output_a.shape							,      '''Shape doesn\'t match'''		)
										assert np.abs(output.cpu() - output_a.cpu()		).max() < 1e-2


# (todo: sayakpaul) implement SLOW tests.


'''simple docstring'''




from __future__ import annotations

import unittest
from collections.abc import Iterator


class    UpperCAmelCase__	:






   """simple docstring"""
   def __init__(self							,					_a							,					_a					)     ->  None:
        lowercase_       :							Union[str, Any]  					=       label
        lowercase_       :							List[str]  					=       parent
        lowercase_       :							Node | None  					=       None
        lowercase_       :							Node | None  					=       None



class    UpperCAmelCase__	:






   """simple docstring"""
   def __init__(self					)     ->  None:
        lowercase_       :							Node | None  					=       None
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							int  					=       None
   def 		_lowerCamelCase			(self					)     ->  bool:
        return self.root is None
   def 		_lowerCamelCase			(self							,					_a					)     ->  None:
        lowercase_       :							Any  					=       self._put(self.root							,					_a					)
   def 		_lowerCamelCase			(self							,					_a							,					_a							,					_a = None					)     ->  Node:
        if node is None:
             lowercase_       :							Union[str, Any]  					=       Node(_a							,					_a					)
        else:
             if label < node.label:
                  lowercase_       :							Optional[int]  					=       self._put(node.left							,					_a							,					_a					)
             elif label > node.label:
                  lowercase_       :							List[str]  					=       self._put(node.right							,					_a							,					_a					)
             else:
                  lowercase_       :							Optional[int]  					=       f'''Node with label {label} already exists'''
                  raise Exception(_a					)

        return node
   def 		_lowerCamelCase			(self							,					_a					)     ->  Node:
        return self._search(self.root							,					_a					)
   def 		_lowerCamelCase			(self							,					_a							,					_a					)     ->  Node:
        if node is None:
             lowercase_       :							Optional[int]  					=       f'''Node with label {label} does not exist'''
             raise Exception(_a					)
        else:
             if label < node.label:
                  lowercase_       :							int  					=       self._search(node.left							,					_a					)
             elif label > node.label:
                  lowercase_       :							str  					=       self._search(node.right							,					_a					)

        return node
   def 		_lowerCamelCase			(self							,					_a					)     ->  None:
        lowercase_       :							List[str]  					=       self.search(_a					)
        if node.right and node.left:
             lowercase_       :							int  					=       self._get_lowest_node(node.right					)
             lowercase_       :							Any  					=       node.left
             lowercase_       :							str  					=       node.right
             lowercase_       :							Any  					=       lowest_node
             if node.right:
                  lowercase_       :							Any  					=       lowest_node
             self._reassign_nodes(_a							,					_a					)
        elif not node.right and node.left:
             self._reassign_nodes(_a							,					node.left					)
        elif node.right and not node.left:
             self._reassign_nodes(_a							,					node.right					)
        else:
             self._reassign_nodes(_a							,					_a					)
   def 		_lowerCamelCase			(self							,					_a							,					_a					)     ->  None:
        if new_children:
             lowercase_       :							List[str]  					=       node.parent

        if node.parent:
             if node.parent.right == node:
                  lowercase_       :							str  					=       new_children
             else:
                  lowercase_       :							Tuple  					=       new_children
        else:
             lowercase_       :							Union[str, Any]  					=       new_children
   def 		_lowerCamelCase			(self							,					_a					)     ->  Node:
        if node.left:
             lowercase_       :							Optional[int]  					=       self._get_lowest_node(node.left					)
        else:
             lowercase_       :							str  					=       node
             self._reassign_nodes(_a							,					node.right					)

        return lowest_node
   def 		_lowerCamelCase			(self							,					_a					)     ->  bool:
        try:
             self.search(_a					)
             return True
        except Exception:
             return False
   def 		_lowerCamelCase			(self					)     ->  int:
        if self.root is None:
             raise Exception('Binary search tree is empty'					)

        lowercase_       :							Tuple  					=       self.root
        while node.right is not None:
             lowercase_       :							Union[str, Any]  					=       node.right

        return node.label
   def 		_lowerCamelCase			(self					)     ->  int:
        if self.root is None:
             raise Exception('Binary search tree is empty'					)

        lowercase_       :							Optional[Any]  					=       self.root
        while node.left is not None:
             lowercase_       :							Optional[int]  					=       node.left

        return node.label
   def 		_lowerCamelCase			(self					)     ->  Iterator[Node]:
        return self._inorder_traversal(self.root					)
   def 		_lowerCamelCase			(self							,					_a					)     ->  Iterator[Node]:
        if node is not None:
             yield from self._inorder_traversal(node.left					)
             yield node
             yield from self._inorder_traversal(node.right					)
   def 		_lowerCamelCase			(self					)     ->  Iterator[Node]:
        return self._preorder_traversal(self.root					)





   def 		_lowerCamelCase			(self							,					_a					)     ->  Iterator[Node]:
        if node is not None:
             yield node
             yield from self._preorder_traversal(node.left					)
             yield from self._preorder_traversal(node.right					)



class    UpperCAmelCase__	(							unittest.TestCase      ):






   """simple docstring"""
   @staticmethod
   def 		_lowerCamelCase			()     ->  BinarySearchTree:
        lowercase_       :							int  					=       BinarySearchTree()
        t.put(8					)
        t.put(3					)
        t.put(6					)
        t.put(1					)
        t.put(10					)
        t.put(14					)
        t.put(13					)
        t.put(4					)
        t.put(7					)
        t.put(5					)

        return t
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							List[Any]  					=       BinarySearchTree()
        assert t.is_empty()

        t.put(8					)
        assert t.root is not None
        assert t.root.parent is None
        assert t.root.label == 8

        t.put(10					)
        assert t.root.right is not None
        assert t.root.right.parent == t.root
        assert t.root.right.label == 10

        t.put(3					)
        assert t.root.left is not None
        assert t.root.left.parent == t.root
        assert t.root.left.label == 3

        t.put(6					)
        assert t.root.left.right is not None
        assert t.root.left.right.parent == t.root.left
        assert t.root.left.right.label == 6

        t.put(1					)
        assert t.root.left.left is not None
        assert t.root.left.left.parent == t.root.left
        assert t.root.left.left.label == 1

        with self.assertRaises(_a					):  # noqa: B017
             t.put(1					)
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							List[Any]  					=       self._get_binary_search_tree()

        lowercase_       :							int  					=       t.search(6					)
        assert node.label == 6

        lowercase_       :							str  					=       t.search(13					)
        assert node.label == 13

        with self.assertRaises(_a					):  # noqa: B017
             t.search(2					)
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Any  					=       self._get_binary_search_tree()

        t.remove(13					)
        assert t.root is not None
        assert t.root.right is not None
        assert t.root.right.right is not None
        assert t.root.right.right.right is None
        assert t.root.right.right.left is None

        t.remove(7					)
        assert t.root.left is not None
        assert t.root.left.right is not None
        assert t.root.left.right.left is not None
        assert t.root.left.right.right is None
        assert t.root.left.right.left.label == 4

        t.remove(6					)
        assert t.root.left.left is not None
        assert t.root.left.right.right is not None
        assert t.root.left.left.label == 1
        assert t.root.left.right.label == 4
        assert t.root.left.right.right.label == 5
        assert t.root.left.right.left is None
        assert t.root.left.left.parent == t.root.left
        assert t.root.left.right.parent == t.root.left

        t.remove(3					)
        assert t.root is not None
        assert t.root.left.label == 4
        assert t.root.left.right.label == 5
        assert t.root.left.left.label == 1
        assert t.root.left.parent == t.root
        assert t.root.left.left.parent == t.root.left
        assert t.root.left.right.parent == t.root.left

        t.remove(4					)
        assert t.root.left is not None
        assert t.root.left.left is not None
        assert t.root.left.label == 5
        assert t.root.left.right is None
        assert t.root.left.left.label == 1
        assert t.root.left.parent == t.root
        assert t.root.left.left.parent == t.root.left
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Union[str, Any]  					=       self._get_binary_search_tree()

        t.remove(3					)
        assert t.root is not None
        assert t.root.left is not None
        assert t.root.left.left is not None
        assert t.root.left.right is not None
        assert t.root.left.right.left is not None
        assert t.root.left.right.right is not None
        assert t.root.left.label == 4
        assert t.root.left.right.label == 6
        assert t.root.left.left.label == 1
        assert t.root.left.right.right.label == 7
        assert t.root.left.right.left.label == 5
        assert t.root.left.parent == t.root
        assert t.root.left.right.parent == t.root.left
        assert t.root.left.left.parent == t.root.left
        assert t.root.left.right.left.parent == t.root.left.right
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Union[str, Any]  					=       self._get_binary_search_tree()
        t.empty()
        assert t.root is None
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							str  					=       self._get_binary_search_tree()
        assert not t.is_empty()

        t.empty()
        assert t.is_empty()
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							List[Any]  					=       self._get_binary_search_tree()

        assert t.exists(6					)
        assert not t.exists(-1					)
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Dict  					=       self._get_binary_search_tree()

        assert t.get_max_label() == 14

        t.empty()
        with self.assertRaises(_a					):  # noqa: B017
             t.get_max_label()
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Tuple  					=       self._get_binary_search_tree()

        assert t.get_min_label() == 1

        t.empty()
        with self.assertRaises(_a					):  # noqa: B017
             t.get_min_label()
   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Tuple  					=       self._get_binary_search_tree()

        lowercase_       :							List[str]  					=       [i.label for i in t.inorder_traversal()]
        assert inorder_traversal_nodes == [1, 3, 4, 5, 6, 7, 8, 10, 13, 14]





   def 		_lowerCamelCase			(self					)     ->  None:
        lowercase_       :							Tuple  					=       self._get_binary_search_tree()

        lowercase_       :							List[Any]  					=       [i.label for i in t.preorder_traversal()]
        assert preorder_traversal_nodes == [8, 3, 1, 6, 4, 5, 7, 10, 14, 13]



def _UpperCamelCase (							):
     lowercase_       :							int  					=       BinarySearchTree()
     t.put(8				)
     t.put(3				)
     t.put(6				)
     t.put(1				)
     t.put(10				)
     t.put(14				)
     t.put(13				)
     t.put(4				)
     t.put(7				)
     t.put(5				)

     print(
         '\n            8\n           / \\\n          3   10\n         / \\    \\\n        1   6    14\n           / \\   /\n          4   7 13\n           \\\n            5\n        '				)

     print('Label 6 exists:'	,							t.exists(6				)				)
     print('Label 13 exists:'	,							t.exists(13				)				)
     print('Label -1 exists:'	,							t.exists(-1				)				)
     print('Label 12 exists:'	,							t.exists(12				)				)

     # Prints all the elements of the list in inorder traversal
     lowercase_       :							Optional[int]  					=       [i.label for i in t.inorder_traversal()]
     print('Inorder traversal:'	,							SCREAMING_SNAKE_CASE_				)

     # Prints all the elements of the list in preorder traversal
     lowercase_       :							str  					=       [i.label for i in t.preorder_traversal()]
     print('Preorder traversal:'	,							SCREAMING_SNAKE_CASE_				)

     print('Max. label:'	,							t.get_max_label()				)
     print('Min. label:'	,							t.get_min_label()				)

     # Delete elements
     print('\nDeleting elements 13, 10, 8, 3, 6, 14'				)
     print(
         '\n          4\n         / \\\n        1   7\n             \\\n              5\n        '				)
     t.remove(13				)
     t.remove(10				)
     t.remove(8				)
     t.remove(3				)
     t.remove(6				)
     t.remove(14				)

     # Prints all the elements of the list in inorder traversal after delete
     lowercase_       :							Dict  					=       [i.label for i in t.inorder_traversal()]
     print('Inorder traversal after delete:'	,							SCREAMING_SNAKE_CASE_				)

     # Prints all the elements of the list in preorder traversal after delete
     lowercase_       :							Dict  					=       [i.label for i in t.preorder_traversal()]
     print('Preorder traversal after delete:'	,							SCREAMING_SNAKE_CASE_				)

     print('Max. label:'	,							t.get_max_label()				)
     print('Min. label:'	,							t.get_min_label()				)


if __name__ == "__main__":
 binary_search_tree_example()




