
"""simple docstring"""




import numpy as np

from transformers import BatchFeature
from transformers.testing_utils import require_tf, require_torch

from .test_feature_extraction_common import FeatureExtractionSavingTestMixin







class     lowercase(_lowercase       ):
     # to overwrite at feature extractactor specific tests
     __snake_case:	List[Any]						=     None
     __snake_case:	Any						=     None



     @property
     def 			lowercase__  (							self   )		->     Dict:







         """simple docstring"""



         return self.feat_extract_tester.prepare_feat_extract_dict()



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







         """simple docstring"""



         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE     ,				'feature_size'   )   )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE     ,				'sampling_rate'   )   )
         self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE     ,				'padding_value'   )   )



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







         """simple docstring"""



         a__		=			self.feat_extract_tester.prepare_inputs_for_common()
         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )

         self.assertTrue(all(len(__SCREAMING_SNAKE_CASE   ) == len(__SCREAMING_SNAKE_CASE   ) for x, y in zip(__SCREAMING_SNAKE_CASE     ,				processed_features[input_name]   )   )   )

         a__		=			self.feat_extract_tester.prepare_inputs_for_common(equal_length=__SCREAMING_SNAKE_CASE   )
         a__		=			BatchFeature({input_name: speech_inputs}     ,				tensor_type='np'   )

         a__		=			processed_features[input_name]

         if len(batch_features_input.shape   ) < 3:
             a__		=			batch_features_input[:, :, None]

         self.assertTrue(
             batch_features_input.shape
             == (self.feat_extract_tester.batch_size, len(speech_inputs[0]   ), self.feat_extract_tester.feature_size)   )



     @require_torch
     def 			lowercase__  (							self   )		->     Union[str, Any]:







         """simple docstring"""



         a__		=			self.feat_extract_tester.prepare_inputs_for_common(equal_length=__SCREAMING_SNAKE_CASE   )
         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}     ,				tensor_type='pt'   )

         a__		=			processed_features[input_name]

         if len(batch_features_input.shape   ) < 3:
             a__		=			batch_features_input[:, :, None]

         self.assertTrue(
             batch_features_input.shape
             == (self.feat_extract_tester.batch_size, len(speech_inputs[0]   ), self.feat_extract_tester.feature_size)   )



     @require_tf
     def 			lowercase__  (							self   )		->     Dict:







         """simple docstring"""



         a__		=			self.feat_extract_tester.prepare_inputs_for_common(equal_length=__SCREAMING_SNAKE_CASE   )
         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}     ,				tensor_type='tf'   )

         a__		=			processed_features[input_name]

         if len(batch_features_input.shape   ) < 3:
             a__		=			batch_features_input[:, :, None]

         self.assertTrue(
             batch_features_input.shape
             == (self.feat_extract_tester.batch_size, len(speech_inputs[0]   ), self.feat_extract_tester.feature_size)   )



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE=False   )		->     Tuple:







         """simple docstring"""



         def _inputs_have_equal_length(__SCREAMING_SNAKE_CASE   ):
             a__		=			len(input[0]   )
             for input_slice in input[1:]:
                 if len(__SCREAMING_SNAKE_CASE   ) != length:
                     return False
             return True

         def _inputs_are_equal(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
             if len(__SCREAMING_SNAKE_CASE   ) != len(__SCREAMING_SNAKE_CASE   ):
                 return False

             for input_slice_a, input_slice_a in zip(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
                 if not np.allclose(np.asarray(__SCREAMING_SNAKE_CASE   )     ,				np.asarray(__SCREAMING_SNAKE_CASE   )     ,				atol=1e-3   ):
                     return False
             return True

         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			self.feat_extract_tester.prepare_inputs_for_common(numpify=__SCREAMING_SNAKE_CASE   )
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )

         a__		=			self.feat_extract_tester.seq_length_diff
         a__		=			self.feat_extract_tester.max_seq_length + pad_diff
         a__		=			self.feat_extract_tester.min_seq_length
         a__		=			self.feat_extract_tester.batch_size
         a__		=			self.feat_extract_tester.feature_size

         # test padding for List[int] + numpy
         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding=__SCREAMING_SNAKE_CASE   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[-1]   )   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				return_tensors='np'   )
         a__		=			input_a[input_name]

         # max_length parameter has to be provided when setting `padding="max_length"`
         with self.assertRaises(__SCREAMING_SNAKE_CASE   ):
             feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='max_length'   )[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=__SCREAMING_SNAKE_CASE     ,				return_tensors='np'   )
         a__		=			input_a[input_name]

         self.assertFalse(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(_inputs_are_equal(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(len(input_a[0]   ) == pad_min_length   )
         self.assertTrue(len(input_a[1]   ) == pad_min_length + pad_diff   )
         self.assertTrue(input_a.shape[:2] == (batch_size, len(input_a[0]   ))   )
         self.assertTrue(input_a.shape[:2] == (batch_size, pad_max_length)   )

         if feature_size > 1:
             self.assertTrue(input_a.shape[2] == input_a.shape[2] == feature_size   )

         # test padding for `pad_to_multiple_of` for List[int] + numpy
         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				pad_to_multiple_of=1_0   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				pad_to_multiple_of=1_0   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				pad_to_multiple_of=1_0     ,				max_length=__SCREAMING_SNAKE_CASE   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				pad_to_multiple_of=1_0     ,				max_length=__SCREAMING_SNAKE_CASE     ,				return_tensors='np'     ,				)
         a__		=			input_a[input_name]

         self.assertTrue(all(len(__SCREAMING_SNAKE_CASE   ) % 1_0 == 0 for x in input_a   )   )
         self.assertTrue(_inputs_are_equal(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )   )

         a__		=			pad_max_length if pad_max_length % 1_0 == 0 else (pad_max_length // 1_0 + 1) * 1_0
         self.assertTrue(all(len(__SCREAMING_SNAKE_CASE   ) == expected_mult_pad_length for x in input_a   )   )
         self.assertEqual(input_a.shape[:2]     ,				(batch_size, expected_mult_pad_length)   )

         if feature_size > 1:
             self.assertTrue(input_a.shape[2] == feature_size   )

         # Check padding value is correct
         a__		=			(np.ones(self.feat_extract_tester.feature_size   ) * feat_extract.padding_value).sum()
         self.assertTrue(
             abs(np.asarray(input_a[0]   )[pad_min_length:].sum() - padding_vector_sum * (pad_max_length - pad_min_length)   )
             < 1e-3   )
         self.assertTrue(
             abs(
                 np.asarray(input_a[1]   )[pad_min_length + pad_diff :].sum()
                 - padding_vector_sum * (pad_max_length - pad_min_length - pad_diff)   )
             < 1e-3   )
         self.assertTrue(
             abs(
                 np.asarray(input_a[2]   )[pad_min_length + 2 * pad_diff :].sum()
                 - padding_vector_sum * (pad_max_length - pad_min_length - 2 * pad_diff)   )
             < 1e-3   )
         self.assertTrue(
             abs(input_a[0, pad_min_length:].sum() - padding_vector_sum * (pad_max_length - pad_min_length)   ) < 1e-3   )
         self.assertTrue(
             abs(input_a[0, pad_min_length:].sum() - padding_vector_sum * (expected_mult_pad_length - pad_min_length)   )
             < 1e-3   )



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE=False   )		->     List[str]:







         """simple docstring"""



         def _inputs_have_equal_length(__SCREAMING_SNAKE_CASE   ):
             a__		=			len(input[0]   )
             for input_slice in input[1:]:
                 if len(__SCREAMING_SNAKE_CASE   ) != length:
                     return False
             return True

         def _inputs_are_equal(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
             if len(__SCREAMING_SNAKE_CASE   ) != len(__SCREAMING_SNAKE_CASE   ):
                 return False

             for input_slice_a, input_slice_a in zip(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   ):
                 if not np.allclose(np.asarray(__SCREAMING_SNAKE_CASE   )     ,				np.asarray(__SCREAMING_SNAKE_CASE   )     ,				atol=1e-3   ):
                     return False
             return True

         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			self.feat_extract_tester.prepare_inputs_for_common(numpify=__SCREAMING_SNAKE_CASE   )
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )

         # truncate to smallest
         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[0]   )     ,				truncation=__SCREAMING_SNAKE_CASE   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[0]   )   )
         a__		=			input_a[input_name]

         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertFalse(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )

         # truncate to smallest with np
         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[0]   )     ,				return_tensors='np'     ,				truncation=__SCREAMING_SNAKE_CASE     ,				)
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[0]   )     ,				return_tensors='np'   )
         a__		=			input_a[input_name]

         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(input_a.shape[1] == len(speech_inputs[0]   )   )

         # since truncation forces padding to be smaller than longest input
         # function can't return `np.ndarray`, but has to return list
         self.assertFalse(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )

         # truncate to middle
         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[1]   )     ,				truncation=__SCREAMING_SNAKE_CASE     ,				return_tensors='np'     ,				)
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[1]   )     ,				truncation=__SCREAMING_SNAKE_CASE   )
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[1]   )     ,				return_tensors='np'   )
         a__		=			input_a[input_name]

         self.assertTrue(input_a.shape[1] == len(speech_inputs[1]   )   )
         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(_inputs_are_equal(__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )   )

         # since truncation forces padding to be smaller than longest input
         # function can't return `np.ndarray`, but has to return list
         self.assertFalse(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertTrue(len(input_a[-1]   ) == len(speech_inputs[-1]   )   )

         # padding has to be max_length when setting `truncation=True`
         with self.assertRaises(__SCREAMING_SNAKE_CASE   ):
             feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				truncation=__SCREAMING_SNAKE_CASE   )[input_name]

         # padding has to be max_length when setting `truncation=True`
         with self.assertRaises(__SCREAMING_SNAKE_CASE   ):
             feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				truncation=__SCREAMING_SNAKE_CASE   )[input_name]

         # padding has to be max_length when setting `truncation=True`
         with self.assertRaises(__SCREAMING_SNAKE_CASE   ):
             feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				truncation=__SCREAMING_SNAKE_CASE   )[input_name]

         # max_length parameter has to be provided when setting `truncation=True` and padding="max_length"
         with self.assertRaises(__SCREAMING_SNAKE_CASE   ):
             feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				truncation=__SCREAMING_SNAKE_CASE   )[input_name]

         # test truncation for `pad_to_multiple_of` for List[int] + numpy
         a__		=			1_2
         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[0]   )     ,				pad_to_multiple_of=__SCREAMING_SNAKE_CASE     ,				truncation=__SCREAMING_SNAKE_CASE     ,				)
         a__		=			input_a[input_name]

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=len(speech_inputs[0]   )     ,				pad_to_multiple_of=__SCREAMING_SNAKE_CASE     ,				)
         a__		=			input_a[input_name]

         # retrieve expected_length as multiple of pad_to_multiple_of
         a__		=			len(speech_inputs[0]   )
         if expected_length % pad_to_multiple_of != 0:
             a__		=			((len(speech_inputs[0]   ) // pad_to_multiple_of) + 1) * pad_to_multiple_of

         self.assertTrue(len(input_a[0]   ) == expected_length   )
         self.assertTrue(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )
         self.assertFalse(_inputs_have_equal_length(__SCREAMING_SNAKE_CASE   )   )



     def 			lowercase__  (							self   )		->     Any:







         """simple docstring"""



         self._check_padding(numpify=__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     Any:







         """simple docstring"""



         self._check_padding(numpify=__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     List[Any]:







         """simple docstring"""



         self._check_truncation(numpify=__SCREAMING_SNAKE_CASE   )



     def 			lowercase__  (							self   )		->     str:







         """simple docstring"""



         self._check_truncation(numpify=__SCREAMING_SNAKE_CASE   )



     @require_torch
     def 			lowercase__  (							self   )		->     Optional[int]:







         """simple docstring"""



         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			self.feat_extract_tester.prepare_inputs_for_common()
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				return_tensors='np'   )[input_name]
         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				return_tensors='pt'   )[input_name]

         self.assertTrue(abs(input_np.astype(np.floataa   ).sum() - input_pt.numpy().astype(np.floataa   ).sum()   ) < 1e-2   )



     @require_tf
     def 			lowercase__  (							self   )		->     str:







         """simple docstring"""



         a__		=			self.feature_extraction_class(**self.feat_extract_dict   )
         a__		=			self.feat_extract_tester.prepare_inputs_for_common()
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				return_tensors='np'   )[input_name]
         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				return_tensors='tf'   )[input_name]

         self.assertTrue(abs(input_np.astype(np.floataa   ).sum() - input_tf.numpy().astype(np.floataa   ).sum()   ) < 1e-2   )



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







         """simple docstring"""



         a__		=			self.feat_extract_dict
         a__		=			True
         a__		=			self.feature_extraction_class(**__SCREAMING_SNAKE_CASE   )
         a__		=			self.feat_extract_tester.prepare_inputs_for_common()
         a__		=			[len(__SCREAMING_SNAKE_CASE   ) for x in speech_inputs]
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )

         a__		=			feat_extract.pad(__SCREAMING_SNAKE_CASE     ,				padding='longest'     ,				return_tensors='np'   )
         self.assertIn('attention_mask'     ,				__SCREAMING_SNAKE_CASE   )
         self.assertListEqual(list(processed.attention_mask.shape   )     ,				list(processed[input_name].shape[:2]   )   )
         self.assertListEqual(processed.attention_mask.sum(-1   ).tolist()     ,				__SCREAMING_SNAKE_CASE   )




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







         """simple docstring"""



         a__		=			self.feat_extract_dict
         a__		=			True
         a__		=			self.feature_extraction_class(**__SCREAMING_SNAKE_CASE   )
         a__		=			self.feat_extract_tester.prepare_inputs_for_common()
         a__		=			[len(__SCREAMING_SNAKE_CASE   ) for x in speech_inputs]
         a__		=			feat_extract.model_input_names[0]

         a__		=			BatchFeature({input_name: speech_inputs}   )
         a__		=			min(__SCREAMING_SNAKE_CASE   )

         a__		=			feat_extract.pad(
             __SCREAMING_SNAKE_CASE     ,				padding='max_length'     ,				max_length=__SCREAMING_SNAKE_CASE     ,				truncation=__SCREAMING_SNAKE_CASE     ,				return_tensors='np'   )
         self.assertIn('attention_mask'     ,				__SCREAMING_SNAKE_CASE   )
         self.assertListEqual(
             list(processed_pad.attention_mask.shape   )     ,				[processed_pad[input_name].shape[0], max_length]   )
         self.assertListEqual(
             processed_pad.attention_mask[:, :max_length].sum(-1   ).tolist()     ,				[max_length for x in speech_inputs]   )




"""simple docstring"""




from collections import deque







class     lowercase:



     def __init__(							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     None:







         """simple docstring"""



         a__		=			process_name  # process name
         a__		=			arrival_time  # arrival time of the process
         # completion time of finished process or last interrupted time
         a__		=			arrival_time
         a__		=			burst_time  # remaining burst time
         a__		=			0  # total time of the process wait in ready queue
         a__		=			0  # time from arrival time to completion time







class     lowercase:



     def __init__(							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE     ,				)		->     None:







         """simple docstring"""



         a__		=			number_of_queues
         # time slice of queues that round robin algorithm applied
         a__		=			time_slices
         # unfinished process is in this ready_queue
         a__		=			queue
         # current time
         a__		=			current_time
         # finished process is in this sequence queue
         a__		=			deque()



     def 			lowercase__  (							self   )		->     list[str]:







         """simple docstring"""



         a__		=			[]
         for i in range(len(self.finish_queue   )   ):
             sequence.append(self.finish_queue[i].process_name   )
         return sequence



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     list[int]:







         """simple docstring"""



         a__		=			[]
         for i in range(len(__SCREAMING_SNAKE_CASE   )   ):
             waiting_times.append(queue[i].waiting_time   )
         return waiting_times



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     list[int]:







         """simple docstring"""



         a__		=			[]
         for i in range(len(__SCREAMING_SNAKE_CASE   )   ):
             turnaround_times.append(queue[i].turnaround_time   )
         return turnaround_times



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     list[int]:







         """simple docstring"""



         a__		=			[]
         for i in range(len(__SCREAMING_SNAKE_CASE   )   ):
             completion_times.append(queue[i].stop_time   )
         return completion_times



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     list[int]:







         """simple docstring"""



         return [q.burst_time for q in queue]



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     int:







         """simple docstring"""



         process.waiting_time += self.current_time - process.stop_time
         return process.waiting_time



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE   )		->     deque[Process]:







         """simple docstring"""



         a__		=			deque()  # sequence deque of finished process
         while len(__SCREAMING_SNAKE_CASE   ) != 0:
             a__		=			ready_queue.popleft()  # current process

             # if process's arrival time is later than current time, update current time
             if self.current_time < cp.arrival_time:
                 self.current_time += cp.arrival_time

             # update waiting time of current process
             self.update_waiting_time(__SCREAMING_SNAKE_CASE   )
             # update current time
             self.current_time += cp.burst_time
             # finish the process and set the process's burst-time 0
             a__		=			0
             # set the process's turnaround time because it is finished
             a__		=			self.current_time - cp.arrival_time
             # set the completion time
             a__		=			self.current_time
             # add the process to queue that has finished queue
             finished.append(__SCREAMING_SNAKE_CASE   )

         self.finish_queue.extend(__SCREAMING_SNAKE_CASE   )  # add finished process to finish queue
         # FCFS will finish all remaining processes
         return finished



     def 			lowercase__  (							self     ,				__SCREAMING_SNAKE_CASE     ,				__SCREAMING_SNAKE_CASE   )		->     tuple[deque[Process], deque[Process]]:







         """simple docstring"""



         a__		=			deque()  # sequence deque of terminated process
         # just for 1 cycle and unfinished processes will go back to queue
         for _ in range(len(__SCREAMING_SNAKE_CASE   )   ):
             a__		=			ready_queue.popleft()  # current process

             # if process's arrival time is later than current time, update current time
             if self.current_time < cp.arrival_time:
                 self.current_time += cp.arrival_time

             # update waiting time of unfinished processes
             self.update_waiting_time(__SCREAMING_SNAKE_CASE   )
             # if the burst time of process is bigger than time-slice
             if cp.burst_time > time_slice:
                 # use CPU for only time-slice
                 self.current_time += time_slice
                 # update remaining burst time
                 cp.burst_time -= time_slice
                 # update end point time
                 a__		=			self.current_time
                 # locate the process behind the queue because it is not finished
                 ready_queue.append(__SCREAMING_SNAKE_CASE   )
             else:
                 # use CPU for remaining burst time
                 self.current_time += cp.burst_time
                 # set burst time 0 because the process is finished
                 a__		=			0
                 # set the finish time
                 a__		=			self.current_time
                 # update the process' turnaround time because it is finished
                 a__		=			self.current_time - cp.arrival_time
                 # add the process to queue that has finished queue
                 finished.append(__SCREAMING_SNAKE_CASE   )

         self.finish_queue.extend(__SCREAMING_SNAKE_CASE   )  # add finished process to finish queue
         # return finished processes queue and remaining processes queue
         return finished, ready_queue




     def 			lowercase__  (							self   )		->     deque[Process]:







         """simple docstring"""



         for i in range(self.number_of_queues - 1   ):
             a__	,     a__		=			self.round_robin(
                 self.ready_queue     ,				self.time_slices[i]   )
         #  the last queue has first_come_first_served algorithm
         self.first_come_first_served(self.ready_queue   )

         return self.finish_queue


if __name__ == "__main__":
    import doctest

    a		:       List[str]     						=       Process('P1', 0, 53)
    a		:       Optional[int]     						=       Process('P2', 0, 17)
    a		:       Union[str, Any]     						=       Process('P3', 0, 68)
    a		:       Optional[int]     						=       Process('P4', 0, 24)
    a		:       Optional[int]     						=       3
    a		:       Optional[Any]     						=       [17, 25]
    a		:       Union[str, Any]     						=       deque([Pa, Pa, Pa, Pa])

    if len(time_slices) != number_of_queues - 1:
        raise SystemExit(0)

    doctest.testmod(extraglobs={'queue': deque([Pa, Pa, Pa, Pa])})

    a		:       Union[str, Any]     						=       Process('P1', 0, 53)
    a		:       Optional[int]     						=       Process('P2', 0, 17)
    a		:       Optional[Any]     						=       Process('P3', 0, 68)
    a		:       str     						=       Process('P4', 0, 24)
    a		:       Optional[Any]     						=       3
    a		:       Tuple     						=       [17, 25]
    a		:       int     						=       deque([Pa, Pa, Pa, Pa])
    a		:       Tuple     						=       MLFQ(number_of_queues, time_slices, queue, 0)
    a		:       Optional[int]     						=       mlfq.multi_level_feedback_queue()

    # print total waiting times of processes(P1, P2, P3, P4)
    print(
        F'''waiting time:\
        \t\t\t{MLFQ.calculate_waiting_time(mlfq, [Pa, Pa, Pa, Pa])}'''
    )
    # print completion times of processes(P1, P2, P3, P4)
    print(
        F'''completion time:\
        \t\t{MLFQ.calculate_completion_time(mlfq, [Pa, Pa, Pa, Pa])}'''
    )
    # print total turnaround times of processes(P1, P2, P3, P4)
    print(
        F'''turnaround time:\
        \t\t{MLFQ.calculate_turnaround_time(mlfq, [Pa, Pa, Pa, Pa])}'''
    )
    # print sequence of finished processes
    print(
        F'''sequence of finished processes:\
        {mlfq.calculate_sequence_of_finish_queue()}'''
    )


