From 553a896e36cd3bdee094164d6df0494426ca0898 Mon Sep 17 00:00:00 2001 From: Karamaz0V1 Date: Tue, 16 Feb 2021 16:36:40 +0100 Subject: [PATCH] Add test on fit_bbox --- idefix/utils.py | 8 ++++---- test/test_utils.py | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/idefix/utils.py b/idefix/utils.py index 701d0f8..0ac00c2 100644 --- a/idefix/utils.py +++ b/idefix/utils.py @@ -87,10 +87,10 @@ def fit_bbox(data, decimals=0): -------- bbox : Returns a raw bounding box on the data. """ - bbox = bbox(data) + raw_bbox = bbox(data) - nbbox = np.round(bbox, decimals) - nbbox[0,2] = np.floor(bbox * 10 ** decimals)[0,2] / 10 ** decimals - nbbox[1,2] = np.ceil(bbox * 10 ** decimals)[1,2] / 10 ** decimals + nbbox = np.round(raw_bbox, decimals) + nbbox[0,2] = np.floor(raw_bbox * 10 ** decimals)[0,2] / 10 ** decimals + nbbox[1,2] = np.ceil(raw_bbox * 10 ** decimals)[1,2] / 10 ** decimals return nbbox diff --git a/test/test_utils.py b/test/test_utils.py index 566c53f..0eca61f 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -27,6 +27,11 @@ def test_bbox(fix_data): res = np.array([fix_data.min(axis=0), fix_data.max(axis=0)]) assert (utils.bbox(fix_data) == res).all() +def test_fit_bbox(fix_data): + res = np.array([[0, 0, 0], + [1, 1, 1]]) + assert (utils.fit_bbox(fix_data) == res).all() + def test_read(datadir): with open(datadir.join('first.txt')) as f: assert f.read() == 'hullo\n'