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

[#768] New practice exercise go-counting #776

Merged
merged 5 commits into from
Jun 26, 2021

Conversation

jiegillet
Copy link
Contributor

Another one. Again, please take your time for the review, I'm just enjoying a week off.

It took me a while to solve, so I put a high difficulty, but maybe I overdid it?

@github-actions
Copy link
Contributor

Thank you for contributing to exercism/elixir 💜 🎉. This is an automated PR comment 🤖 for the maintainers of this repository that helps with the PR review process. You can safely ignore it and wait for a maintainer to review your changes.

Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:

  • General steps

    • 🏆 Does this PR need to receive a label with a reputation modifier (reputation/contributed_code/{minor,major})? (A medium reputation amount is awarded by default, see docs)
  • Any exercise changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <exercise>/.meta/config.json (see docs)?
    • 🔬 Do the analyzer and the analyzer comments exist for this exercise? Do they need to be changed?
    • 📜 Does the design file (<exercise>/.meta/design.md) need to be updated to document new implementation decisions?
  • Practice exercise changed

    • 🌲 Do prerequisites, practices, and difficulty in config.json need to be updated?
    • 🧑‍🏫 Are the changes in accordance with the community-wide problem specifiations?
  • Practice exercise tests changed

    • ⚪️ Are all tests except the first one skipped?
    • 📜 Does <exercise>/.meta/tests.toml need updating?

Automated comment created by PR Commenter 🤖.

"practices": [
"list-comprehensions"
],
"difficulty": 9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to solve, so I put a high difficulty, but maybe I overdid it?

Anything go-related probably deserves a 9 😬

exercises/practice/go-counting/lib/go_counting.ex Outdated Show resolved Hide resolved
assert Enum.sort(w1) == Enum.sort(w2)
end

def equal?(_a, _b), do: flunk("Unexpected output")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current error message:

  1) test Black corner territory on 5x5 board (GoCountingTest)
     test/go_counting_test.exs:18
     Unexpected output
     code: equal?(output, expected)
     stacktrace:
       test/go_counting_test.exs:25: (test)

Not great because I have no idea what my function actually returned 🤔

If we fall back to a simple assertion:

Suggested change
def equal?(_a, _b), do: flunk("Unexpected output")
def equal?(a, b), do: assert a == b

The error will be much nicer:

  1) test Black corner territory on 5x5 board (GoCountingTest)
     test/go_counting_test.exs:18
     Assertion with == failed
     code:  assert a == b
     left:  nil
     right: {:ok, %{owner: :black, territory: [{0, 0}, {0, 1}, {1, 0}]}}
     stacktrace:
       test/go_counting_test.exs:25: (test)

This case will be triggered when somebody for example misspells the error string ({:error, "Invalid coordinates"} instead {:error, "Invalid coordinate"}), so it's important that it shows all the details.

Edit: this won't matter if we remove equal? altogether

Comment on lines 10 to 12
assert Enum.sort(b1) == Enum.sort(b2)
assert Enum.sort(n1) == Enum.sort(n2)
assert Enum.sort(w1) == Enum.sort(w2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer if we assumed that the coordinates need to be already sorted (by first coordinate first, then second coordinate) and removed the custom equal? assertions altogether. In the canonical data, they are sorted and I don't see a note anything about allowing not sorting 🤔.

We have that assumption in at least one other exercise already, saddle-points.

Copy link
Contributor Author

@jiegillet jiegillet Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's assume coordinates are sorted, it makes everything cleaner. Although I had to modify my example code :)


# @tag :pending
test "Black corner territory on 5x5 board" do
board = [" B ", " B B ", "B W B", " W W ", " W "]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do multiline strings as input. It will be easier to read and not that much harder to implement a solution. In problem specifications, sometimes there is a comment that a list of strings is supposed to be a multiline string (for example: https://github.com/exercism/problem-specifications/blob/e2779fc84ff07cb5bd8ff89f38e78af6d17b5056/exercises/proverb/canonical-data.json#L4-L6). It's weird that it's missing for this exercise.

We will need this hack to keep trailing whitespace in a multiline string:

assert shape == """
\s A \s
\s B B \s
\s C C \s
\s D D \s
\s E E \s
\s F F \s
\s G G \s
\s H H \s
\s I I \s
\s J J \s
\s K K \s
\s L L \s
\s M M \s
\s N N \s
\s O O \s
\s P P \s
\s Q Q \s
\s R R \s
\s S S \s
\s T T \s
\s U U \s
\s V V \s
\s W W \s
\s X X \s
\sY Y\s
Z Z
\sY Y\s
\s X X \s
\s W W \s
\s V V \s
\s U U \s
\s T T \s
\s S S \s
\s R R \s
\s Q Q \s
\s P P \s
\s O O \s
\s N N \s
\s M M \s
\s L L \s
\s K K \s
\s J J \s
\s I I \s
\s H H \s
\s G G \s
\s F F \s
\s E E \s
\s D D \s
\s C C \s
\s B B \s
\s A \s
"""
end

Or maybe it won't be that much easier to read, in that case we should at least split the list items each in a new line, so that it kinda reads like a multiline string while still being a list 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good suggestion, thank you.
It was a bit awkward to deal with the leading/trailing white spaces, so instead I used "_" for empty spaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks great with "_", good idea!

Comment on lines +2 to +4
@type position :: {integer, integer}
@type owner :: %{owner: atom, territory: [position]}
@type territories :: %{white: [position], black: [position], none: [position]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:size/large Large amount of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants