[WIP] Implement exercise bowling#790
Conversation
|
@aes421 build failed due to some code style issues: |
b9a5449 to
73c311f
Compare
|
@aes421 you forgot to add the exercise to |
|
Hey @m-a-ge I'm actually not done writing the test/implementation of this exercise yet. I left the config stuff until last for me previous PR, but I can go ahead and do it now if you'd like. |
|
Ah, sorry, my bad. Ping me when you're done. Side note: I don't usually leave comments in |
|
@m-a-ge done with this one. Let me know what you'd like to see changed. |
exercises/bowling/.gitignore
Outdated
| @@ -0,0 +1 @@ | |||
| .cache/ | |||
There was a problem hiding this comment.
I would advise not to include this in repo .gitignore. You can use your local one for this purpose
|
|
||
| from example import BowlingGame | ||
|
|
||
|
|
There was a problem hiding this comment.
Could you please also leave a comment stating what version of canonical-data.json the tests were adopted as discussed in #784 if aplicable?
The format is:
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
exercises/bowling/bowling_test.py
Outdated
| def test_should_be_able_to_score_a_game_with_all_zeros(self): | ||
| rolls = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
|
|
||
| self.game = BowlingGame() |
There was a problem hiding this comment.
I would also suggest introduce a setUp method and create an instance of BowlingGame only once
def setUp(self):
self.game= BowlingGame()
exercises/bowling/example.py
Outdated
| self.bonusRollsSeen = 0 | ||
|
|
||
| def roll(self, pins): | ||
| if (self.isBonusRoll()): |
There was a problem hiding this comment.
probably just:
if self.isBonusRoll():
# do stuffThis increases readability
exercises/bowling/example.py
Outdated
| raise ValueError | ||
|
|
||
| # open a new frame if the last one has been closed | ||
| if (self.currentFrame.isOpen() is False): |
There was a problem hiding this comment.
if not self.currentFrame.isOpen():| self.rolls[1] = roll | ||
| self.open = False | ||
|
|
||
| def isOpen(self): |
There was a problem hiding this comment.
this doesn't look right, method name doesn't correspond to its actual function
There was a problem hiding this comment.
I'm not sure what you mean on this one. you call isOpen to find out if the frame is open (true) or not (false)
exercises/bowling/example.py
Outdated
|
|
||
|
|
||
| class Frame(object): | ||
|
|
There was a problem hiding this comment.
It would be great to add docstring
exercises/bowling/example.py
Outdated
|
|
||
| def isBonusRoll(self): | ||
| # if we've already seen all | ||
| if (len(self.rolls) >= NUM_FRAMES): |
There was a problem hiding this comment.
refactor to oneliner
|
|
||
|
|
||
| class BowlingGame(object): | ||
| def __init__(self): |
There was a problem hiding this comment.
docstring here would be nice 📓
exercises/bowling/bowling_test.py
Outdated
|
|
||
| self.game = BowlingGame() | ||
|
|
||
| for roll in rolls: |
There was a problem hiding this comment.
Probably something like:
[self.game.roll(roll) for roll in rolls]And the code is duplicated in every test which is not a good thing, should be refactored
cmccandless
left a comment
There was a problem hiding this comment.
There should be a solution template bowling.py included as well. See solution template for complex-numbers as an example.
exercises/bowling/bowling_test.py
Outdated
| @@ -0,0 +1,261 @@ | |||
| import unittest | |||
|
|
|||
| from example import BowlingGame | |||
There was a problem hiding this comment.
should be from bowling import BowlingGame
|
Thanks for the feedback! I just got back from a holiday, and I'm hoping to have time to work on finishing this one later this week. |
|
This issue has been automatically marked as |
|
I think I've got everything fixed up. Let me know what you think. @m-a-ge @cmccandless |
exercises/bowling/bowling_test.py
Outdated
| @@ -1,258 +1,189 @@ | |||
| # Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 | |||
There was a problem hiding this comment.
For consistency with the other exercises, could you please move this line like so:
from bowling import BowlingGame
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1
class BowlingTests(unittest.TestCase):
...Please note the number of blank lines before and after.
|
This issue has been automatically marked as |
|
@aes421 Merged; thanks for working on this! |
https://github.com/exercism/problem-specifications/tree/master/exercises/bowling