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.

1 Like

@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

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.

I wrongly requested it? I do not understand the implication. I suggested, as exploration, but was it wrong of me to do so?

I do not think it was requested, only asked about.

The test is specifically not present, not is present. That test comes after and I do not think that is from me. But I am not seeing the patch.

Can you give a link to which PR you are referring to so we do not have to go search for it?

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:

:wave: I wrote part of this exercise (in JS). We have these tests which cover the cases you are both talking about: javascript/exercises/concept/annalyns-infiltration/annalyns-infiltration.spec.js at main Ā· exercism/javascript Ā· GitHub

You may want to copy.

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.

Hi!

PR is here: Annalyn's Infiltration - Task 4 - Instructions don't match tests by sarad1p1ty Ā· Pull Request #786 Ā· exercism/php Ā· GitHub

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.