-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[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. |
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.
Good work overall!
I left comments for you to address.
And I suggest you spend some time on refactoring to make your code a bit better
exercises/bowling/.gitignore
Outdated
@@ -0,0 +1 @@ | |||
.cache/ |
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 would advise not to include this in repo .gitignore
. You can use your local one for this purpose
exercises/bowling/bowling_test.py
Outdated
|
||
from example import BowlingGame | ||
|
||
|
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably just:
if self.isBonusRoll():
# do stuff
This 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not self.currentFrame.isOpen():
self.rolls[1] = roll | ||
self.open = False | ||
|
||
def isOpen(self): |
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 doesn't look right, method name doesn't correspond to its actual function
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'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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor to oneliner
exercises/bowling/example.py
Outdated
|
||
|
||
class BowlingGame(object): | ||
def __init__(self): |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
@@ -1,258 +1,189 @@ | |||
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1 |
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.
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.
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.
done!
This issue has been automatically marked as |
@aes421 Merged; thanks for working on this! |
https://github.com/exercism/problem-specifications/tree/master/exercises/bowling