I got the following assignment:
Returns true if the given appointment can be added to the list of appointments without overlapping
any other appointments.
name="appointments">The list of current appointments
name="appointment">The new appointment for which to check if it fits within the other appointments
True if the new appointment fits between the current appointments: "9-10", "11-12", "15-16"
My current code is:
public bool IsAvailable(Appointment[] appointments, Appointment appointment)
{
bool overlap = true;
foreach (var afspraak in appointments)
{
overlap = (afspraak.Start >= appointment.End || appointment.Start <= afspraak.End);
}
return overlap;
}
This code passes 10 out of the 18 unit tests:
Should return True:
[TestCase("8-9")] passed
[TestCase("8-8:30")] passed
[TestCase("10-11")] passed
[TestCase("10:45-11")] passed
[TestCase("12-15")] passed
[TestCase("12-13")] passed
[TestCase("13-14")] passed
[TestCase("14-15")] passed
[TestCase("16-17")] passed
[TestCase("16:30-17")] failed
Should return False:
[TestCase("7-8")] failed
[TestCase("8-9:30")] failed
[TestCase("9:30-9:45")] failed
[TestCase("9:30-11")] failed
[TestCase("8-10:30")] failed
[TestCase("17-18")] passed
[TestCase("12-18")] failed
[TestCase("11:30-12:30")] failed
I just can't really figure out what I'm doing wrong, anyone seeing what I'm doing wrong?
UPDATE 2: The problem is that only now the "should return false unit tests" pass :(
------