Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Oct 31, 2023
1 parent ed6e510 commit 9010c4d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
41 changes: 41 additions & 0 deletions glue/viewers/histogram/tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy as np
from numpy.testing import assert_allclose

from glue.viewers.common.viewer import Viewer
from glue.viewers.histogram.state import HistogramViewerState
from glue.core.application_base import Application
Expand Down Expand Up @@ -57,3 +60,41 @@ def test_incompatible_datasets():
viewer.state.x_att = data2.id['y']

viewer.state.hist_n_bin = 20


def test_reset_limits():

data1 = Data(x=np.arange(1000), label='data')

app = Application()
app.data_collection.append(data1)

viewer = app.new_data_viewer(TestHistogramViewer)
viewer.add_data(data1)

viewer.state.reset_limits()

assert_allclose(viewer.state.x_min, 0)
assert_allclose(viewer.state.x_max, 999)

viewer.state.x_limits_percentile = 90

viewer.state.reset_limits()

assert_allclose(viewer.state.x_min, 49.95)
assert_allclose(viewer.state.x_max, 949.05)

assert_allclose(viewer.state.hist_x_min, 49.95)
assert_allclose(viewer.state.hist_x_max, 949.05)

viewer.state.update_bins_on_reset_limits = False

viewer.state.x_limits_percentile = 80

viewer.state.reset_limits()

assert_allclose(viewer.state.x_min, 99.9)
assert_allclose(viewer.state.x_max, 899.1)

assert_allclose(viewer.state.hist_x_min, 49.95)
assert_allclose(viewer.state.hist_x_max, 949.05)
Empty file.
43 changes: 43 additions & 0 deletions glue/viewers/scatter/tests/test_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import numpy as np
from numpy.testing import assert_allclose

from glue.viewers.common.viewer import Viewer
from glue.viewers.scatter.state import ScatterViewerState
from glue.core.application_base import Application
from glue.core.data import Data


class TestScatterViewer(Viewer):
_state_cls = ScatterViewerState


def test_reset_limits():

data1 = Data(x=np.arange(1000), y=np.arange(1000) + 1000, label='data')

app = Application()
app.data_collection.append(data1)

viewer = app.new_data_viewer(TestScatterViewer)
viewer.add_data(data1)

viewer.state.reset_limits()

# Note that there is a margin included which is why the limits are not 0 to 999

assert_allclose(viewer.state.x_min, -39.96)
assert_allclose(viewer.state.x_max, 1038.96)

assert_allclose(viewer.state.y_min, 1000 - 39.96)
assert_allclose(viewer.state.y_max, 1000 + 1038.96)

viewer.state.x_limits_percentile = 90
viewer.state.y_limits_percentile = 80

viewer.state.reset_limits()

assert_allclose(viewer.state.x_min, 13.986)
assert_allclose(viewer.state.x_max, 985.014)

assert_allclose(viewer.state.y_min, 1000 + 67.932)
assert_allclose(viewer.state.y_max, 1000 + 931.068)

0 comments on commit 9010c4d

Please sign in to comment.