-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Yelp/fix-type-error
Extract format_loves and fix type error
- Loading branch information
Showing
4 changed files
with
27 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.10.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def format_loves(loves): | ||
# organise loves into two roughly equal lists for displaying | ||
if len(loves) < 20: | ||
loves_list_one = loves | ||
loves_list_two = [] | ||
else: | ||
loves_list_one = loves[:len(loves)//2] | ||
loves_list_two = loves[len(loves)//2:] | ||
|
||
if len(loves_list_one) < len(loves_list_two): | ||
loves_list_one.append(loves_list_two.pop()) | ||
return loves_list_one, loves_list_two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- coding: utf-8 -*- | ||
import pytest | ||
|
||
from loveapp.util.formatting import format_loves | ||
|
||
|
||
@pytest.mark.parametrize('loves, expected', [ | ||
([], ([], [])), | ||
(list(range(5)), (list(range(5)), [])), | ||
(list(range(31)), (list(range(15)) + [30], list(range(15, 30)))), | ||
]) | ||
def test_format_loves(loves, expected): | ||
assert format_loves(loves) == expected |