I just did this exercise on PHP and noticed that the README talks about the dog not being present while all are asleep (except the prisoner) but this is not enforced in the tests, either.
public function canLiberate(
$is_knight_awake,
$is_archer_awake,
$is_prisoner_awake,
$is_dog_present
) {
return
$is_prisoner_awake &&
!$is_dog_present && /* This is not necessary but the README indicates it */
!$is_knight_awake &&
!$is_archer_awake or
$is_dog_present &&
!$is_archer_awake;
}
You can delete the line with the comment and the tests still pass.
I think Iāll take this as a vacation entertainment. Changing tests would invalidate to many community solutions. So Iād better change the instructions to meet the tests.
A PR is currently prepared to add a logic table (or is it called truth table?) to the exercise. While digging into it, there were no mismatches found in instructions nor tests.
I was wrong in this thread regarding āprisoner asleep == no rescueā: That is not always, but if ādog not presentā. And @kotp wrongly requested a test for ādog is presentā in case the whole watch is asleep. The logic table hopefully makes such statements more easily approvable.
This, to me, reads like: āPlease add a test, because it needs a testā. Iām sorry, if it wasnāt meant like this. Iām not here to poke on you.
The PR āis currently preparedā, which should mean: It is in the making. We have no PR yet. But it will exist soon. You may want to read the issue about it instead:
Ah, yeah, that was definitely a question, not a statement to add it as a test, it was purely explorative. If you see later, the opposite of that is there, and so by inference, we have the test in there.
Thanks for the issue link. And the PR is being prepared as you say, I thought it was prepared, which is what caused me to go searching.
You can see there is a test already for whether the prisoner is asleep and the dog is present (the test should pass):
/**
* @testdox can liberate the prisoner when no one is awake but dog present
* @task_id 4
*/
public function testCanLiberateWhenAllAsleepAndDogPresent()
{
$infiltration = new AnnalynsInfiltration();
$actual = $infiltration->canLiberate(
is_knight_awake: false,
is_archer_awake: false,
is_prisoner_awake: false,
is_dog_present: true
);
$expected = true;
$this->assertEquals($expected, $actual);
}
The corresponding line from the logic table is:
Test
Knight Awake
Archer Awake
Prisoner Awake
Dog Present
Can Liberate
Everyone Asleep - Dog Present
FALSE
FALSE
FALSE
TRUE
TRUE
This seems to match the instructions to me, but if it isnāt clear then I suppose the question is how to update the instructions to make them clearer - and avoid making them too convoluted.