
'''simple docstring'''







import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import ViTImageProcessor






class  lowerCAmelCase__   (  unittest.TestCase     ):






					def __init__(   self				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE=13				,							__SCREAMING_SNAKE_CASE=3				,							__SCREAMING_SNAKE_CASE=2_24				,							__SCREAMING_SNAKE_CASE=30				,							__SCREAMING_SNAKE_CASE=4_00				,							__SCREAMING_SNAKE_CASE=True				,							__SCREAMING_SNAKE_CASE=None				,							__SCREAMING_SNAKE_CASE=True				,							__SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]				,							__SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]				,							):


											"""simple docstring"""





											lowercase_	:     str													=       size if size is not None else {'''height''': 18, '''width''': 18}
											lowercase_	:     Dict													=       parent
											lowercase_	:     int													=       batch_size
											lowercase_	:     Dict													=       num_channels
											lowercase_	:     Optional[Any]													=       image_size
											lowercase_	:     Union[str, Any]													=       min_resolution
											lowercase_	:     List[Any]													=       max_resolution
											lowercase_	:     Any													=       do_resize
											lowercase_	:     Any													=       size
											lowercase_	:     Union[str, Any]													=       do_normalize
											lowercase_	:     Optional[int]													=       image_mean
											lowercase_	:     List[str]													=       image_std






					def 	_snake_case    (   self		):


											"""simple docstring"""





											return {
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_normalize": self.do_normalize,
											    "do_resize": self.do_resize,
											    "size": self.size,
											}







@require_torch
@require_vision
class  lowerCAmelCase__   (  lowerCamelCase_    ,						unittest.TestCase     ):
					lowerCAmelCase_        =     ViTImageProcessor if is_vision_available() else None






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     int													=       EfficientFormerImageProcessorTester(self		)






					@property
					def 	_snake_case    (   self		):


											"""simple docstring"""





											return self.image_proc_tester.prepare_image_processor_dict()






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Optional[int]													=       self.image_processing_class(**self.image_processor_dict		)
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,							'''image_mean'''		)		)
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,							'''image_std'''		)		)
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,							'''do_normalize'''		)		)
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,							'''do_resize'''		)		)
											self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE				,							'''size'''		)		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											pass






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     int													=       self.image_processing_class(**self.image_processor_dict		)
											# create random PIL images
											lowercase_	:     Optional[Any]													=       prepare_image_inputs(self.image_proc_tester				,							equal_resolution=__SCREAMING_SNAKE_CASE		)
											for image in image_inputs:
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE				,							Image.Image		)

											# Test not batched input
											lowercase_	:     Dict													=       image_processor(image_inputs[0]				,							return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape				,							(
											        1,
											        self.image_proc_tester.num_channels,
											        self.image_proc_tester.size['''height'''],
											        self.image_proc_tester.size['''width'''],
											    )				,							)

											# Test batched
											lowercase_	:     Tuple													=       image_processor(__SCREAMING_SNAKE_CASE				,							return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape				,							(
											        self.image_proc_tester.batch_size,
											        self.image_proc_tester.num_channels,
											        self.image_proc_tester.size['''height'''],
											        self.image_proc_tester.size['''width'''],
											    )				,							)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Optional[int]													=       self.image_processing_class(**self.image_processor_dict		)
											# create random numpy tensors
											lowercase_	:     Any													=       prepare_image_inputs(self.image_proc_tester				,							equal_resolution=__SCREAMING_SNAKE_CASE				,							numpify=__SCREAMING_SNAKE_CASE		)
											for image in image_inputs:
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE				,							np.ndarray		)

											# Test not batched input
											lowercase_	:     Optional[Any]													=       image_processor(image_inputs[0]				,							return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape				,							(
											        1,
											        self.image_proc_tester.num_channels,
											        self.image_proc_tester.size['''height'''],
											        self.image_proc_tester.size['''width'''],
											    )				,							)

											# Test batched
											lowercase_	:     Optional[int]													=       image_processor(__SCREAMING_SNAKE_CASE				,							return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape				,							(
											        self.image_proc_tester.batch_size,
											        self.image_proc_tester.num_channels,
											        self.image_proc_tester.size['''height'''],
											        self.image_proc_tester.size['''width'''],
											    )				,							)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     Union[str, Any]													=       self.image_processing_class(**self.image_processor_dict		)
											# create random PyTorch tensors
											lowercase_	:     str													=       prepare_image_inputs(self.image_proc_tester				,							equal_resolution=__SCREAMING_SNAKE_CASE				,							torchify=__SCREAMING_SNAKE_CASE		)
											for image in image_inputs:
																	self.assertIsInstance(__SCREAMING_SNAKE_CASE				,							torch.Tensor		)

											# Test not batched input
											lowercase_	:     List[Any]													=       image_processor(image_inputs[0]				,							return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape				,							(
											        1,
											        self.image_proc_tester.num_channels,
											        self.image_proc_tester.size['''height'''],
											        self.image_proc_tester.size['''width'''],
											    )				,							)

											# Test batched
											lowercase_	:     int													=       image_processor(__SCREAMING_SNAKE_CASE				,							return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape				,							(
											        self.image_proc_tester.batch_size,
											        self.image_proc_tester.num_channels,
											        self.image_proc_tester.size['''height'''],
											        self.image_proc_tester.size['''width'''],
											    )				,							)





'''simple docstring'''







import unittest

from knapsack import greedy_knapsack as kp






class  lowerCAmelCase__   (  unittest.TestCase     ):






					def 	_snake_case    (   self		):


											"""simple docstring"""





											lowercase_	:     List[str]													=       [10, 20, 30, 40, 50, 60]
											lowercase_	:     Optional[Any]													=       [2, 4, 6, 8, 10, 12]
											lowercase_	:     Union[str, Any]													=       1_00
											self.assertEqual(kp.calc_profit(__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE				,							__SCREAMING_SNAKE_CASE		)				,							2_10		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											self.assertRaisesRegex(__SCREAMING_SNAKE_CASE				,							'''max_weight must greater than zero.'''		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											self.assertRaisesRegex(__SCREAMING_SNAKE_CASE				,							'''Weight can not be negative.'''		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											self.assertRaisesRegex(__SCREAMING_SNAKE_CASE				,							'''Profit can not be negative.'''		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											self.assertRaisesRegex(__SCREAMING_SNAKE_CASE				,							'''max_weight must greater than zero.'''		)






					def 	_snake_case    (   self		):


											"""simple docstring"""





											self.assertRaisesRegex(
											    __SCREAMING_SNAKE_CASE				,							'''The length of profit and weight must be same.'''		)


if __name__ == "__main__":
							unittest.main()



