From 8bba88f75fbebe60830b629d3ba204890400b748 Mon Sep 17 00:00:00 2001 From: Gareth Simons Date: Mon, 24 May 2021 09:21:48 +0100 Subject: [PATCH] sorts out prog bar edge cases --- cityseer/algos/checks.py | 8 +++----- tests/algos/test_checks.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cityseer/algos/checks.py b/cityseer/algos/checks.py index cefe25a8..8a2a8d4d 100644 --- a/cityseer/algos/checks.py +++ b/cityseer/algos/checks.py @@ -32,13 +32,11 @@ def progress_bar(current: int, total: int, steps: int = 20): https://github.com/krishnanlab/PecanPy/commit/9c6ca6f5c6341e84aa080b2936cd59d9d8a37b24 TODO: set cache to True once resolved ''' - if steps == 0: - return - step_size = int(total / steps) - if step_size == 0: + if steps == 0 or current == 0 or total < 2 * steps: return + step_size = int(total / steps) # round down if current % step_size == 0: - print('Processed non-sequential checkpoint', round(current / step_size) + 1, 'of', steps + 1) + print('Processed non-sequential checkpoint', int(current / step_size), 'of', steps) @njit(cache=True) diff --git a/tests/algos/test_checks.py b/tests/algos/test_checks.py index 03b6d300..0132f453 100644 --- a/tests/algos/test_checks.py +++ b/tests/algos/test_checks.py @@ -8,8 +8,8 @@ def test_progress_bar(): - for n in [1, 10, 20, 100]: - for i in range(n): + for n in [1, 11, 27, 101, 271, 5521]: + for i in range(n + 1): checks.progress_bar(i, n)