


'''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 LevitImageProcessor
class 	UpperCamelCase__					( unittest.TestCase	):



     """simple docstring"""






     def __init__( self      ,	snake_case__      ,	snake_case__=7      ,	snake_case__=3      ,	snake_case__=18      ,	snake_case__=30      ,	snake_case__=400      ,	snake_case__=True      ,	snake_case__=None      ,	snake_case__=True      ,	snake_case__=None      ,	snake_case__=True      ,	snake_case__=[0.5, 0.5, 0.5]      ,	snake_case__=[0.5, 0.5, 0.5]      ,	):

            '''simple docstring'''

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







     def a	( self   ):

            '''simple docstring'''

            return {
                "image_mean": self.image_mean,
                "image_std": self.image_std,
                "do_normalize": self.do_normalize,
                "do_resize": self.do_resize,
                "do_center_crop": self.do_center_crop,
                "size": self.size,
                "crop_size": self.crop_size,
            }
@require_torch
@require_vision
class 	UpperCamelCase__					( SCREAMING_SNAKE_CASE_    ,					unittest.TestCase	):



     """simple docstring"""






     __magic_name__    			=    LevitImageProcessor if is_vision_available() else None







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Optional[Any]   			=       LevitImageProcessingTester(self   )







     @property
     def a	( self   ):

            '''simple docstring'''

            return self.image_processor_tester.prepare_image_processor_dict()







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       self.image_processing_class(**self.image_processor_dict   )
            self.assertTrue(hasattr(snake_case__      ,	'image_mean'   )   )
            self.assertTrue(hasattr(snake_case__      ,	'image_std'   )   )
            self.assertTrue(hasattr(snake_case__      ,	'do_normalize'   )   )
            self.assertTrue(hasattr(snake_case__      ,	'do_resize'   )   )
            self.assertTrue(hasattr(snake_case__      ,	'do_center_crop'   )   )
            self.assertTrue(hasattr(snake_case__      ,	'size'   )   )







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							List[Any]   			=       self.image_processing_class.from_dict(self.image_processor_dict   )
            self.assertEqual(image_processor.size      ,	{'shortest_edge': 18}   )
            self.assertEqual(image_processor.crop_size      ,	{'height': 18, 'width': 18}   )

            _lowerCAmelCase    :							Dict   			=       self.image_processing_class.from_dict(self.image_processor_dict      ,	size=42      ,	crop_size=84   )
            self.assertEqual(image_processor.size      ,	{'shortest_edge': 42}   )
            self.assertEqual(image_processor.crop_size      ,	{'height': 84, 'width': 84}   )







     def a	( self   ):

            '''simple docstring'''

            pass







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Union[str, Any]   			=       self.image_processing_class(**self.image_processor_dict   )
            # create random PIL images
            _lowerCAmelCase    :							Tuple   			=       prepare_image_inputs(self.image_processor_tester      ,	equal_resolution=snake_case__   )
            for image in image_inputs:
                   self.assertIsInstance(snake_case__      ,	Image.Image   )

            # Test not batched input
            _lowerCAmelCase    :							Any   			=       image_processing(image_inputs[0]      ,	return_tensors='pt'   ).pixel_values
            self.assertEqual(
                encoded_images.shape      ,	(
                    1,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )      ,	)

            # Test batched
            _lowerCAmelCase    :							Tuple   			=       image_processing(snake_case__      ,	return_tensors='pt'   ).pixel_values
            self.assertEqual(
                encoded_images.shape      ,	(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )      ,	)







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Tuple   			=       self.image_processing_class(**self.image_processor_dict   )
            # create random numpy tensors
            _lowerCAmelCase    :							Optional[Any]   			=       prepare_image_inputs(self.image_processor_tester      ,	equal_resolution=snake_case__      ,	numpify=snake_case__   )
            for image in image_inputs:
                   self.assertIsInstance(snake_case__      ,	np.ndarray   )

            # Test not batched input
            _lowerCAmelCase    :							str   			=       image_processing(image_inputs[0]      ,	return_tensors='pt'   ).pixel_values
            self.assertEqual(
                encoded_images.shape      ,	(
                    1,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )      ,	)

            # Test batched
            _lowerCAmelCase    :							Tuple   			=       image_processing(snake_case__      ,	return_tensors='pt'   ).pixel_values
            self.assertEqual(
                encoded_images.shape      ,	(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )      ,	)







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Any   			=       self.image_processing_class(**self.image_processor_dict   )
            # create random PyTorch tensors
            _lowerCAmelCase    :							Tuple   			=       prepare_image_inputs(self.image_processor_tester      ,	equal_resolution=snake_case__      ,	torchify=snake_case__   )
            for image in image_inputs:
                   self.assertIsInstance(snake_case__      ,	torch.Tensor   )

            # Test not batched input
            _lowerCAmelCase    :							Tuple   			=       image_processing(image_inputs[0]      ,	return_tensors='pt'   ).pixel_values
            self.assertEqual(
                encoded_images.shape      ,	(
                    1,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )      ,	)

            # Test batched
            _lowerCAmelCase    :							Any   			=       image_processing(snake_case__      ,	return_tensors='pt'   ).pixel_values
            self.assertEqual(
                encoded_images.shape      ,	(
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['height'],
                    self.image_processor_tester.crop_size['width'],
                )      ,	)





'''simple docstring'''







import unittest

from knapsack import greedy_knapsack as kp
class 	UpperCamelCase__					( unittest.TestCase	):



     """simple docstring"""






     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Union[str, Any]   			=       [10, 20, 30, 40, 50, 60]
            _lowerCAmelCase    :							Union[str, Any]   			=       [2, 4, 6, 8, 10, 12]
            _lowerCAmelCase    :							Dict   			=       100
            self.assertEqual(kp.calc_profit(snake_case__      ,	snake_case__      ,	snake_case__   )      ,	210   )







     def a	( self   ):

            '''simple docstring'''

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







     def a	( self   ):

            '''simple docstring'''

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







     def a	( self   ):

            '''simple docstring'''

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







     def a	( self   ):

            '''simple docstring'''

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







     def a	( self   ):

            '''simple docstring'''

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


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

