


'''simple docstring'''



import operator


def    lowerCamelCase__   ( A     :    list   ,     A     :    bool = False   ,     A     :    list | None = None  ):
						UpperCAmelCase         =			operator.lt if reverse else operator.gt
						UpperCAmelCase         =			solution or []

						if not arr:
												return solution

						UpperCAmelCase         =			[arr.pop(0  )]
						for i, item in enumerate(A  ):
												if _operator(A   ,     sublist[-1]  ):
																		sublist.append(A  )
																		arr.pop(A  )

    #  merging sublist into solution list
						if not solution:
												solution.extend(A  )
						else:
												while sublist:
																		UpperCAmelCase         =			sublist.pop(0  )
																		for i, xx in enumerate(A  ):
																								if not _operator(A   ,     A  ):
																														solution.insert(A   ,     A  )
																														break
																		else:
																								solution.append(A  )

						strand_sort(A   ,     A   ,     A  )
						return solution


if __name__ == "__main__":
	assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
	assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]









'''simple docstring'''



import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
	import torch

	from transformers.generation import DisjunctiveConstraint






@require_torch
class  UpperCamelCase__(     unittest.TestCase ):




				def   a__(	self    :				Optional[int]   )->  str:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2, 4], [1, 2, 3, 4]]
										UpperCAmelCase         =			DisjunctiveConstraint(lowerCAmelCase   )
										self.assertTrue(isinstance(dc.token_ids   ,					lowerCAmelCase   )   )

										with self.assertRaises(lowerCAmelCase   ):
																DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]   )   )

										with self.assertRaises(lowerCAmelCase   ):
																DisjunctiveConstraint([torch.LongTensor([1, 2, 4]   ), torch.LongTensor([1, 2, 3, 4, 5]   )]   )




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

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2], [1, 2, 3, 4]]

										with self.assertRaises(lowerCAmelCase   ):
																DisjunctiveConstraint(lowerCAmelCase   )  # fails here




				def   a__(	self    :				Any   )->  Optional[int]:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2, 3], [1, 2, 4]]

										UpperCAmelCase         =			DisjunctiveConstraint(lowerCAmelCase   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(1   )
										UpperCAmelCase         =			stepped is True and completed is False and reset is False
										self.assertTrue(lowerCAmelCase   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(2   )
										UpperCAmelCase         =			stepped is True and completed is False and reset is False
										self.assertTrue(lowerCAmelCase   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1, 2]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(3   )
										UpperCAmelCase         =			stepped is True and completed is True and reset is False
										self.assertTrue(lowerCAmelCase   )
										self.assertTrue(dc.completed   )  # Completed!
										self.assertTrue(dc.current_seq == [1, 2, 3]   )





				def   a__(	self    :				int   )->  Dict:

										"""simple docstring"""




										UpperCAmelCase         =			[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

										UpperCAmelCase         =			DisjunctiveConstraint(lowerCAmelCase   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(1   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(2   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1, 2]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(4   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.current_seq == [1, 2, 4]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(5   )
										self.assertTrue(dc.completed   )  # Completed!
										self.assertTrue(dc.current_seq == [1, 2, 4, 5]   )

										dc.reset()

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(1   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.remaining() == 3   )
										self.assertTrue(dc.current_seq == [1]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(2   )
										self.assertTrue(not dc.completed   )
										self.assertTrue(dc.remaining() == 2   )
										self.assertTrue(dc.current_seq == [1, 2]   )

										UpperCAmelCase       ,       UpperCAmelCase       ,       UpperCAmelCase         =			dc.update(5   )
										self.assertTrue(dc.completed   )  # Completed!
										self.assertTrue(dc.remaining() == 0   )
										self.assertTrue(dc.current_seq == [1, 2, 5]   )





