


import unittest

from knapsack import knapsack as k
class 						lowerCamelCase_							(					unittest.TestCase					):



					'''simple docstring'''







					def A   (					self    ) ->      Any:







								'''simple docstring'''

								__lowercase			       = 0
								__lowercase			       = [0]
								__lowercase			       = [0]
								__lowercase			       = len(snake_case_    )
								self.assertEqual(k.knapsack(snake_case_			,							snake_case_			,							snake_case_			,							snake_case_    )			,							0    )

								__lowercase			       = [6_0]
								__lowercase			       = [1_0]
								__lowercase			       = len(snake_case_    )
								self.assertEqual(k.knapsack(snake_case_			,							snake_case_			,							snake_case_			,							snake_case_    )			,							0    )






					def A   (					self    ) ->      Tuple:







								'''simple docstring'''

								__lowercase			       = 3
								__lowercase			       = [1, 2, 3]
								__lowercase			       = [3, 2, 1]
								__lowercase			       = len(snake_case_    )
								self.assertEqual(k.knapsack(snake_case_			,							snake_case_			,							snake_case_			,							snake_case_    )			,							5    )






					def A   (					self    ) ->      Union[str, Any]:







								'''simple docstring'''

								__lowercase			       = 5_0
								__lowercase			       = [6_0, 1_0_0, 1_2_0]
								__lowercase			       = [1_0, 2_0, 3_0]
								__lowercase			       = len(snake_case_    )
								self.assertEqual(k.knapsack(snake_case_			,							snake_case_			,							snake_case_			,							snake_case_    )			,							2_2_0    )


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






import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor
class 						lowerCamelCase_							(					unittest.TestCase					):



					'''simple docstring'''







					def __init__(					self			,							snake_case_			,							snake_case_=7			,							snake_case_=3			,							snake_case_=1_8			,							snake_case_=3_0			,							snake_case_=4_0_0			,							snake_case_=True			,							snake_case_=None			,							snake_case_=True			,							snake_case_=False			,							snake_case_=True			,							snake_case_=True			,							snake_case_=[0.5, 0.5, 0.5]			,							snake_case_=[0.5, 0.5, 0.5]			,							) ->      Optional[Any]:







								'''simple docstring'''

								__lowercase			       = parent
								__lowercase			       = batch_size
								__lowercase			       = num_channels
								__lowercase			       = image_size
								__lowercase			       = min_resolution
								__lowercase			       = max_resolution
								__lowercase			       = do_resize
								__lowercase			       = size if size is not None else {'''height''': 1_8, '''width''': 2_0}
								__lowercase			       = do_thumbnail
								__lowercase			       = do_align_axis
								__lowercase			       = do_pad
								__lowercase			       = do_normalize
								__lowercase			       = image_mean
								__lowercase			       = image_std






					def A   (					self    ) ->      Dict:







								'''simple docstring'''

								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_thumbnail": self.do_thumbnail,
								    "do_align_long_axis": self.do_align_axis,
								    "do_pad": self.do_pad,
								    "do_normalize": self.do_normalize,
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								}




@require_torch
@require_vision
class 						lowerCamelCase_							(					lowerCAmelCase__  ,  unittest.TestCase					):



					'''simple docstring'''







					__UpperCAmelCase							  =					DonutImageProcessor if is_vision_available() else None






					def A   (					self    ) ->      Optional[Any]:







								'''simple docstring'''

								__lowercase			       = DonutImageProcessingTester(self    )






					@property
					def A   (					self    ) ->      str:







								'''simple docstring'''

								return self.image_processor_tester.prepare_image_processor_dict()






					def A   (					self    ) ->      Optional[int]:







								'''simple docstring'''

								__lowercase			       = self.image_processing_class(**self.image_processor_dict    )
								self.assertTrue(hasattr(snake_case_			,							'''do_resize'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''size'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''do_thumbnail'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''do_align_long_axis'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''do_pad'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''do_normalize'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''image_mean'''    )    )
								self.assertTrue(hasattr(snake_case_			,							'''image_std'''    )    )






					def A   (					self    ) ->      List[str]:







								'''simple docstring'''

								__lowercase			       = self.image_processing_class.from_dict(self.image_processor_dict    )
								self.assertEqual(image_processor.size			,							{'''height''': 1_8, '''width''': 2_0}    )

								__lowercase			       = self.image_processing_class.from_dict(self.image_processor_dict			,							size=4_2    )
								self.assertEqual(image_processor.size			,							{'''height''': 4_2, '''width''': 4_2}    )

								# Previous config had dimensions in (width, height) order
								__lowercase			       = self.image_processing_class.from_dict(self.image_processor_dict			,							size=(4_2, 8_4)    )
								self.assertEqual(image_processor.size			,							{'''height''': 8_4, '''width''': 4_2}    )






					def A   (					self    ) ->      Optional[Any]:







								'''simple docstring'''

								pass






					@is_flaky()
					def A   (					self    ) ->      Optional[Any]:







								'''simple docstring'''

								__lowercase			       = self.image_processing_class(**self.image_processor_dict    )
								# create random PIL images
								__lowercase			       = 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
								__lowercase			       = 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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )			,							)

								# Test batched
								__lowercase			       = 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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )			,							)






					@is_flaky()
					def A   (					self    ) ->      Dict:







								'''simple docstring'''

								__lowercase			       = self.image_processing_class(**self.image_processor_dict    )
								# create random numpy tensors
								__lowercase			       = 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
								__lowercase			       = 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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )			,							)

								# Test batched
								__lowercase			       = 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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )			,							)






					@is_flaky()
					def A   (					self    ) ->      Dict:







								'''simple docstring'''

								__lowercase			       = self.image_processing_class(**self.image_processor_dict    )
								# create random PyTorch tensors
								__lowercase			       = 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
								__lowercase			       = 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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )			,							)

								# Test batched
								__lowercase			       = 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.size['''height'''],
								        self.image_processor_tester.size['''width'''],
								    )			,							)


