Esempio n. 1
0
class PatientsLine:
    def __init__(self, patience_rate=0):
        self.corona_plus_patients = Fifo(patience_rate, "plus patients")
        self.corona_minus_patients = Fifo(patience_rate, "minus patients")

    def elapse_time(self):
        self.corona_minus_patients.elapse_time()
        self.corona_plus_patients.elapse_time()

    def add_to_line(self, patient):
        if patient.corona_test_result == "+":
            self.corona_plus_patients.add_to_line(patient)
        else:
            self.corona_minus_patients.add_to_line(patient)

    def get_next_patient(self):
        next_patient = self.corona_plus_patients.get_next_patient()
        if next_patient == None:
            next_patient = self.corona_minus_patients.get_next_patient()
        return next_patient

    def get_plus_patients_length(self):
        return len(self.corona_plus_patients.line)

    def get_minus_patients_length(self):
        return len(self.corona_minus_patients.line)

    def get_line_length(self):
        return self.get_plus_patients_length(
        ) + self.get_minus_patients_length()
Esempio n. 2
0
    def test_patience_time(self):
        fifo = Fifo()

        fifo.add_to_line(Patient("+", 2))
        fifo.add_to_line(Patient("+", 3))
        fifo.add_to_line(Patient("+", 5))

        fifo.elapse_time()

        self.assertEqual(1, fifo.get_next_patient().patience_in_minutes)

        fifo.elapse_time()
        fifo.elapse_time()

        self.assertEqual(2, fifo.get_next_patient().patience_in_minutes)

        self.assertEqual(0, len(fifo.line))
        self.assertIsNone(fifo.get_next_patient())
Esempio n. 3
0
 def test_empty_fifo(self):
     fifo = Fifo()
     self.assertEqual(1, fifo.elapse_time())
     self.assertIsNone(fifo.get_next_patient())