Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Queen Attack test values #1504

Merged
merged 3 commits into from
Apr 15, 2019

Conversation

TeaDrivenDev
Copy link
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
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
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
Contributor Author

Makes sense; updated.

@SleeplessByte
Copy link
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