-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
Conversation
Thank you for contributing to Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:
Automated comment created by PR Commenter 🤖. |
"practices": [ | ||
"list-comprehensions" | ||
], | ||
"difficulty": 9 |
There was a problem hiding this comment.
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 😬
assert Enum.sort(w1) == Enum.sort(w2) | ||
end | ||
|
||
def equal?(_a, _b), do: flunk("Unexpected output") |
There was a problem hiding this comment.
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:
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
assert Enum.sort(b1) == Enum.sort(b2) | ||
assert Enum.sort(n1) == Enum.sort(n2) | ||
assert Enum.sort(w1) == Enum.sort(w2) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 "] |
There was a problem hiding this comment.
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:
elixir/exercises/practice/diamond/test/diamond_test.exs
Lines 53 to 106 in 9565a2f
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 🙂
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
@type position :: {integer, integer} | ||
@type owner :: %{owner: atom, territory: [position]} | ||
@type territories :: %{white: [position], black: [position], none: [position]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-authored-by: Angelika Tyborska <[email protected]>
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?