Skip to content

Commit

Permalink
Added unit tests for redim method
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 8, 2016
1 parent f2b74a3 commit b9aad12
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/testdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def test_dataset_sort_vdim_hm(self):
kdims=['x'], vdims=['y'])
self.assertEqual(dataset.sort('y'), dataset_sorted)


def test_dataset_redim_hm_kdim(self):
redimmed = self.dataset_hm.redim(x='Time')
self.assertEqual(redimmed.dimension_values('Time'),
self.dataset_hm.dimension_values('x'))

def test_dataset_redim_hm_vdim(self):
redimmed = self.dataset_hm.redim(y='Value')
self.assertEqual(redimmed.dimension_values('Value'),
self.dataset_hm.dimension_values('y'))

def test_dataset_sample_hm(self):
samples = self.dataset_hm.sample([0, 5, 10]).dimension_values('y')
self.assertEqual(samples, np.array([0, 10, 20]))
Expand Down
21 changes: 20 additions & 1 deletion tests/testdimensions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Test cases for Dimension and Dimensioned object behaviour.
"""
from holoviews.core import Dimensioned
from holoviews.core import Dimensioned, Dimension
from holoviews.element.comparison import ComparisonTestCase


Expand All @@ -18,3 +18,22 @@ def test_dimensioned_constant_label(self):
view.label = 'another label'
raise AssertionError("Label should be a constant parameter.")
except TypeError: pass

def test_dimensionsed_redim_string(self):
dimensioned = Dimensioned('Arbitrary Data', kdims=['x'])
redimensioned = dimensioned.clone(kdims=['Test'])
self.assertEqual(redimensioned, dimensioned.redim(x='Test'))

def test_dimensionsed_redim_dimension(self):
dimensioned = Dimensioned('Arbitrary Data', kdims=['x'])
redimensioned = dimensioned.clone(kdims=['Test'])
self.assertEqual(redimensioned, dimensioned.redim(x=Dimension('Test')))

def test_dimensionsed_redim_dict(self):
dimensioned = Dimensioned('Arbitrary Data', kdims=['x'])
redimensioned = dimensioned.clone(kdims=['Test'])
self.assertEqual(redimensioned, dimensioned.redim(x={'name': 'Test'}))

def test_dimensionsed_redim_dict_range(self):
redimensioned = Dimensioned('Arbitrary Data', kdims=['x']).redim(x={'range': (0, 10)})
self.assertEqual(redimensioned.kdims[0].range, (0, 10))
21 changes: 21 additions & 0 deletions tests/testndmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def test_idxmapping_reindex(self):

self.assertEqual([d.name for d in reduced_ndmap.kdims], reduced_dims)

def test_idxmapping_redim(self):
data = [((0, 0.5), 'a'), ((1, 0.5), 'b')]
ndmap = MultiDimensionalMapping(data, kdims=[self.dim1, self.dim2])
redimmed = ndmap.redim(intdim='Integer')
self.assertEqual(redimmed.kdims, [Dimension('Integer'), Dimension('floatdim')])

def test_idxmapping_add_dimension(self):
ndmap = MultiDimensionalMapping(self.init_items_1D_list, kdims=[self.dim1])
ndmap2d = ndmap.add_dimension(self.dim2, 0, 0.5)
Expand Down Expand Up @@ -136,6 +142,21 @@ def setUp(self):
self.columns = Dataset(np.column_stack([self.xs, self.y_ints]),
kdims=['x'], vdims=['y'])

def test_holomap_redim(self):
hmap = HoloMap({i: Dataset({'x':self.xs, 'y': self.ys * i},
kdims=['x'], vdims=['y'])
for i in range(10)}, kdims=['z'])
redimmed = hmap.redim(x='Time')
self.assertEqual(redimmed.dimensions('all', True),
['z', 'Time', 'y'])

def test_holomap_redim_nested(self):
hmap = HoloMap({i: Dataset({'x':self.xs, 'y': self.ys * i},
kdims=['x'], vdims=['y'])
for i in range(10)}, kdims=['z'])
redimmed = hmap.redim(x='Time', z='Magnitude')
self.assertEqual(redimmed.dimensions('all', True),
['Magnitude', 'Time', 'y'])

def test_columns_collapse_heterogeneous(self):
collapsed = HoloMap({i: Dataset({'x':self.xs, 'y': self.ys * i},
Expand Down

0 comments on commit b9aad12

Please sign in to comment.