155 lines
No EOL
4.4 KiB
C#
155 lines
No EOL
4.4 KiB
C#
namespace WaitingRoom.Test;
|
|
|
|
public sealed class WaitingRoomTests
|
|
{
|
|
private const string Name = "Susi";
|
|
private readonly DateTime _arrivalTime = DateTime.Now;
|
|
private readonly WaitingRoom _waitingRoom = new();
|
|
|
|
[Fact]
|
|
public void Empty()
|
|
{
|
|
CheckCounts(0, 0);
|
|
_waitingRoom.ToString().Should().Be("0 Emergency 0 Normal");
|
|
}
|
|
|
|
[Fact]
|
|
public void Add_Single_Normal()
|
|
{
|
|
var p = new Patient(Name, _arrivalTime);
|
|
|
|
_waitingRoom.AddPatient(p);
|
|
|
|
CheckCounts(1, 0);
|
|
_waitingRoom.ToString().Should().Be("0 Emergency 1 Normal");
|
|
}
|
|
|
|
[Fact]
|
|
public void NextPatient()
|
|
{
|
|
var p = new Patient(Name, _arrivalTime);
|
|
_waitingRoom.AddPatient(p);
|
|
|
|
CheckCounts(1, 0);
|
|
var next = _waitingRoom.Next();
|
|
|
|
next.Should()
|
|
.NotBeNull("patient was waiting");
|
|
next?.Name.Should().Be(Name);
|
|
next?.Arrival.Should().Be(_arrivalTime);
|
|
next?.IsEmergency.Should().BeFalse();
|
|
CheckCounts(0, 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void Add_Multiple_Normal()
|
|
{
|
|
var p1 = new Patient(Name, _arrivalTime);
|
|
_waitingRoom.AddPatient(p1);
|
|
|
|
var p2 = new Patient("BeforeFirst", _arrivalTime.AddMinutes(-5));
|
|
_waitingRoom.AddPatient(p2);
|
|
|
|
var p3 = new Patient("AfterFirst", _arrivalTime.AddMinutes(15));
|
|
_waitingRoom.AddPatient(p3);
|
|
|
|
CheckCounts(3, 0);
|
|
|
|
var next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p2, "patients are ordered by arrival time");
|
|
CheckCounts(2, 0);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p1);
|
|
CheckCounts(1, 0);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p3);
|
|
CheckCounts(0, 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void Add_Multiple_Emergency()
|
|
{
|
|
var p1 = new Patient("FirstEmergency", _arrivalTime, true);
|
|
_waitingRoom.AddPatient(p1);
|
|
|
|
var p2 = new Patient("BeforeFirst", _arrivalTime.AddMinutes(-5));
|
|
_waitingRoom.AddPatient(p2);
|
|
|
|
var p3 = new Patient("AfterFirst", _arrivalTime.AddMinutes(15));
|
|
_waitingRoom.AddPatient(p3);
|
|
|
|
var p4 = new Patient("AnotherEmergency", _arrivalTime.AddMinutes(20), true);
|
|
_waitingRoom.AddPatient(p4);
|
|
|
|
CheckCounts(2, 2);
|
|
|
|
var next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p1, "first arrived emergency");
|
|
CheckCounts(2, 1);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p4, "second emergency - treated before normal patients");
|
|
CheckCounts(2, 0);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p2, "first arrived normal patient");
|
|
CheckCounts(1, 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void ChangeToEmergency()
|
|
{
|
|
var p1 = new Patient("FirstEmergency", _arrivalTime, true);
|
|
_waitingRoom.AddPatient(p1);
|
|
|
|
var p2 = new Patient("BeforeFirst", _arrivalTime.AddMinutes(-5));
|
|
_waitingRoom.AddPatient(p2);
|
|
|
|
var p3 = new Patient("AfterFirst", _arrivalTime.AddMinutes(15));
|
|
_waitingRoom.AddPatient(p3);
|
|
|
|
var p4 = new Patient("VeryLatePatient", _arrivalTime.AddMinutes(20));
|
|
_waitingRoom.AddPatient(p4);
|
|
|
|
CheckCounts(3, 1);
|
|
|
|
var next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p1, "first emergency");
|
|
CheckCounts(3, 0);
|
|
|
|
_waitingRoom.SetPatientToEmergency(p4);
|
|
p4.IsEmergency.Should().BeTrue("changed");
|
|
CheckCounts(2, 1);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p4, "promoted to emergency");
|
|
CheckCounts(2, 0);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p2, "regular next normal patient");
|
|
CheckCounts(1, 0);
|
|
|
|
next = _waitingRoom.Next();
|
|
next.Should().NotBeNull()
|
|
.And.BeSameAs(p3, "final patient");
|
|
CheckCounts(0, 0);
|
|
}
|
|
|
|
private void CheckCounts(int normal, int emergency)
|
|
{
|
|
_waitingRoom.CountNormal.Should().Be(normal);
|
|
_waitingRoom.CountEmergency.Should().Be(emergency);
|
|
_waitingRoom.CountAll.Should().Be(normal + emergency);
|
|
}
|
|
} |