Skip to content

Correct Queen Attack test values#1504

Merged
SleeplessByte merged 3 commits intoexercism:masterfrom
TeaDrivenDev:queenattack
Apr 15, 2019
Merged

Correct Queen Attack test values#1504
SleeplessByte merged 3 commits intoexercism:masterfrom
TeaDrivenDev:queenattack

Conversation

@TeaDrivenDev
Copy link
Copy Markdown
Contributor

There is a flaw in the Queen Attack test suite that causes the most naive implementation that makes the tests green to actually be incomplete.

The tests for "third diagonal" (2, 2 and 1, 1) and "fourth diagonal" (2, 2 and 5, 5) actually test for the same diagonal (A1 to H8) and are fulfilled by the condition row1 = column1 && row2 = column2. This does not cover the parallels of that diagonal, however, so if there was an additional test for (0, 6) and (1, 7) that would still be red.

This is fixed by replacing the redundant "fourth diagonal" test values with said (0, 6) and (1, 7), which will require the condition to be changed to row1 - column1 = row2 - column2, thus covering all diagonals from "top left" to "bottom right".

That said, the tests for "first diagonal" and "second diagonal" are actually also covering the same diagonal (the one from "bottom left" to "top right" that includes 2, 2), but this PR is not addressing that.

@cmccandless
Copy link
Copy Markdown
Contributor

I disagree. A solution that uses the difference of the positions would be testing against "third diagonal" (2,2) - (1,1) = (1,1), versus "fourth diagonal" (2,2) - (5,5) = (-3,-3). For such solutions, each test case verifies against a different edge case.

Not to say that such solutions are quite optimal, but they are completely valid, if implemented correctly. Keeping both cases ensures that solutions like this handle both edge cases.

@cmccandless
Copy link
Copy Markdown
Contributor

cmccandless commented Apr 8, 2019

My apologies; I misread your initial statement (not enough coffee yet).

However, I do stand by my assertion that there needs to be a case where the second queen is closer to the bottom-left corner of the board than the first. What about switching the new suggested values (i.e. white: (1,7), black: (0, 6))?

@TeaDrivenDev
Copy link
Copy Markdown
Contributor Author

Makes sense; updated.

Comment thread exercises/queen-attack/canonical-data.json Outdated
Co-Authored-By: TeaDrivenDev <TeaDrivenDev@users.noreply.github.com>
@SleeplessByte
Copy link
Copy Markdown
Member

🚀 lgtm and with 3 approvals I think this is good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants