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

Modified the logic for validating scores #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def _validate_scores(winner_score, loser_score):
ws = winner_score
ls = loser_score

if ws == 21:
if ls < 0 or ls > 20:
raise error
elif ws == 11:
if ls < 0 or ls > 10:
raise error
else:
if ws < 0 or ls < 0:
raise error

if ws <= ls:
raise error

if ws < 11 or ws - ls < 2:
raise error


Expand Down
10 changes: 4 additions & 6 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_validate_bad_scores(self):
colin = self.post_valid_player('colin')
kumanan = self.post_valid_player('kumanan')

bad_scores = ((21, 21), (11, 11), (22, 20), (21, -1), (21, 31))
bad_scores = ((21, 21), (11, 11), (21, -1), (21, 31))
for winner_score, loser_score in bad_scores:
response, errors = self.post_game(
colin,
Expand All @@ -387,11 +387,9 @@ def test_validate_bad_scores(self):

def test_validate_good_scores(self):

good_scores = (
[(21, n) for n in range(0, 21)]
+
[(11, n) for n in range(0, 11)]
)
good_scores = [
(x, y) for x in range(11, 22) for y in range(0, x - 1)
]
for idx, (winner_score, loser_score) in enumerate(good_scores):
colin = self.post_valid_player('colin' + str(idx))
kumanan = self.post_valid_player('kumanan' + str(idx))
Expand Down