Bug in Annalyns Infiltration Test

This test is incorrect:

    public function testCanSpyWhenEveryoneAwake()
    {
        $infiltration = new AnnalynsInfiltration();
        $actual = $infiltration->canSpy(
            is_knight_awake: true,
            is_archer_awake: false,
            is_prisoner_awake: false
        );
        $expected = true;
        $this->assertEquals($expected, $actual);
    }

Both is_archer_awake and is_prisoner_awake should be true.

The test name and values don’t align. The test contents are valid/correct, though. The test ought to pass when the code is correct.

Spy: the group can be spied upon if at least one of them is awake. Otherwise, spying is a waste of time.

In fact, the complaint is correct. This test suffers from copy&paste weirdness. The name was changed, but the flags were not changed to all true.

Also, some other tests had that same problem.

@rzuckerm I a few minutes you should be able to update the exercise to the latest version and find the issue fixed.

Thanks, @mk-mxp .

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.

Is that this one:

    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.

@kotp Which line in the instructions asks for no dog present when knight and archer are asleep? The dog does not matter then.

I only worry about the last conditions after or, as the prisoner must be awake for a successful rescue always:

but if the prisoner is sleeping they can’t be rescued

but your conditions don’t care for that.

If Annalyn has her pet dog with her she can rescue the prisoner if the archer is asleep.

From the README.md/Instructions Tab.

And right, so are the tests flawed? If the prisoner is not awake, there should be some test for this, right? Where this solution should be failing?

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.

1 Like