Created
December 26, 2018 21:10
-
-
Save encolpe/3338a067fc71c934e0f96a5fd3e9af98 to your computer and use it in GitHub Desktop.
Pagination tests
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
import math | |
TEST_DATA = [ | |
{ | |
'total': 7, | |
'range': 3, | |
'orphan': 1, | |
'have_orphan': True, | |
'nb_pages': 2, | |
}, | |
{ | |
'total': 7, | |
'range': 4, | |
'orphan': 2, | |
'have_orphan': False, | |
'nb_pages': 2, | |
}, | |
{ | |
'total': 7, | |
'range': 5, | |
'orphan': 2, | |
'have_orphan': True, | |
'nb_pages': 1, | |
}, | |
{ | |
'total': 7, | |
'range': 7, | |
'orphan': 6, | |
'have_orphan': False, | |
'nb_pages': 1, | |
}, | |
{ | |
'total': 7, | |
'range': 10, | |
'orphan': 4, | |
'have_orphan': False, | |
'nb_pages': 1, | |
}, | |
] | |
for data in TEST_DATA: | |
orphaned = data['total'] - data['range'] * math.floor(data['total']/data['range']) # NOQA: E501 | |
print('{} {}'.format( | |
orphaned, | |
0 < orphaned <= data['orphan'] | |
)) | |
assert (0 < orphaned <= data['orphan']) == data['have_orphan'] | |
if 0 < orphaned <= data['orphan']: | |
assert math.floor(data['total']/data['range']) == data['nb_pages'] | |
else: | |
assert math.ceil(data['total']/data['range']) == data['nb_pages'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment