done all unit tests

This commit is contained in:
Jonas Hinterdorfer 2025-03-11 13:53:26 +01:00
parent 8724028270
commit b3daa4a45e
6 changed files with 108 additions and 13 deletions

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,4 +1,44 @@
package at.ionas999.health.model;
public class Patient {
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Patient implements Comparable<Patient> {
private String name;
private LocalDateTime appointment;
private boolean isEmergency;
public Patient(String name, LocalDateTime appointment, boolean isEmergency) {
this.name = name;
this.appointment = appointment;
this.isEmergency = isEmergency;
}
public String getName() {
return name;
}
public LocalDateTime getAppointment() {
return appointment;
}
public boolean isEmergency() {
return isEmergency;
}
@Override
public int compareTo(Patient o) {
if (this.isEmergency && !o.isEmergency) {
return -1;
} else if (!this.isEmergency && o.isEmergency) {
return 1;
} else {
return this.appointment.compareTo(o.appointment);
}
}
@Override
public String toString() {
return (isEmergency ? "EMERGENCY" : appointment.format(DateTimeFormatter.ofPattern("d.M.yy HH:mm"))) + " " + name;
}
}

View File

@ -1,4 +1,52 @@
package at.ionas999.health.model;
import at.ionas999.observer.ChangeObserver;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
public class WaitingRoom {
private final List<ChangeObserver<WaitingRoom>> observers = new ArrayList<>();
private final PriorityQueue<Patient> patients = new PriorityQueue<>();
private Patient patientUndergoingTreatment = null;
public int getPatientCount() {
return patients.size();
}
public Patient getPatientInPreparation(){
return patients.peek();
}
public Patient getPatientUndergoingTreatment(){
return this.patientUndergoingTreatment;
}
public void addObserver(ChangeObserver<WaitingRoom> observer) {
observers.add(observer);
observer.update(this);
}
public void removeObserver(ChangeObserver<WaitingRoom> observer) {
observers.remove(observer);
}
public void addPatient(String name, LocalDateTime appointment, boolean isEmergency) {
Patient patient = new Patient(name, appointment, isEmergency);
patients.add(patient);
notifyObservers();
}
public void treatNextPatient() {
this.patientUndergoingTreatment = patients.poll();
notifyObservers();
}
private void notifyObservers() {
for (ChangeObserver<WaitingRoom> observer : observers) {
observer.update(this);
}
}
}

View File

@ -1,4 +1,4 @@
package at.htlleonding.observer;
package at.ionas999.observer;
@FunctionalInterface
public interface ChangeObserver<T> {

View File

@ -1,6 +1,7 @@
package at.ionas999.health.model;
import at.htlleonding.observer.ChangeObserver;
import at.ionas999.observer.ChangeObserver;
public class UpdateObserver implements ChangeObserver<WaitingRoom> {
private int updateCount;

View File

@ -1,6 +1,6 @@
package at.ionas999.health.model;
import at.htlleonding.observer.ChangeObserver;
import at.ionas999.observer.ChangeObserver;
import org.junit.jupiter.api.Test;
@ -13,16 +13,16 @@ import static org.junit.jupiter.api.Assertions.*;
class WaitingRoomTest {
private List<Patient> createPatients() {
Patient patientOtto = new at.htlleonding.health.model.Patient("Otto Normalverbraucher", LocalDateTime.of(2022, 3, 14, 12, 00), true);
Patient patientTom = new at.htlleonding.health.model.Patient("Tom Taxpayer", LocalDateTime.of(2022, 3, 14, 12, 20), true);
Patient patientRichard = new at.htlleonding.health.model.Patient("Richard Roe", LocalDateTime.of(2022, 3, 14, 13, 00), true);
Patient patientLieschen = new at.htlleonding.health.model.Patient("Lieschen Müller", LocalDateTime.of(2023, 3, 14, 12, 00), true);
Patient patientJan = new at.htlleonding.health.model.Patient("Jan Kowalski", LocalDateTime.of(2022, 3, 14, 12, 15), false);
Patient patientJohn = new at.htlleonding.health.model.Patient("John Doe", LocalDateTime.of(2022, 3, 14, 12, 30), false);
Patient patientMax = new at.htlleonding.health.model.Patient("Max Mustermann", LocalDateTime.of(2022, 3, 14, 13, 00), false);
Patient patientSally = new at.htlleonding.health.model.Patient("Sally Sixpack", LocalDateTime.of(2022, 3, 15, 12, 00), false);
Patient patientOtto = new at.ionas999.health.model.Patient("Otto Normalverbraucher", LocalDateTime.of(2022, 3, 14, 12, 00), true);
Patient patientTom = new at.ionas999.health.model.Patient("Tom Taxpayer", LocalDateTime.of(2022, 3, 14, 12, 20), true);
Patient patientRichard = new at.ionas999.health.model.Patient("Richard Roe", LocalDateTime.of(2022, 3, 14, 13, 00), true);
Patient patientLieschen = new at.ionas999.health.model.Patient("Lieschen Müller", LocalDateTime.of(2023, 3, 14, 12, 00), true);
Patient patientJan = new at.ionas999.health.model.Patient("Jan Kowalski", LocalDateTime.of(2022, 3, 14, 12, 15), false);
Patient patientJohn = new at.ionas999.health.model.Patient("John Doe", LocalDateTime.of(2022, 3, 14, 12, 30), false);
Patient patientMax = new at.ionas999.health.model.Patient("Max Mustermann", LocalDateTime.of(2022, 3, 14, 13, 00), false);
Patient patientSally = new at.ionas999.health.model.Patient("Sally Sixpack", LocalDateTime.of(2022, 3, 15, 12, 00), false);
List<at.htlleonding.health.model.Patient> result = new LinkedList<>();
List<at.ionas999.health.model.Patient> result = new LinkedList<>();
result.add(patientOtto);
result.add(patientTom);
result.add(patientRichard);