From a4dfd7fc744e34b5ee7b6e0320c7be19c0a90b35 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 16 May 2020 17:23:05 +0200 Subject: [PATCH] missing tests --- python/tests/test_Table.py | 15 ++++++++++----- python/tests/test_grid_filters.py | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/python/tests/test_Table.py b/python/tests/test_Table.py index cfcdd8813..ac7444808 100644 --- a/python/tests/test_Table.py +++ b/python/tests/test_Table.py @@ -18,7 +18,7 @@ def reference_dir(reference_dir_base): return os.path.join(reference_dir_base,'Table') class TestTable: - + def test_get_scalar(self,default): d = default.get('s') assert np.allclose(d,1.0) and d.shape[1:] == (1,) @@ -29,12 +29,12 @@ class TestTable: def test_get_tensor(self,default): d = default.get('F') - assert np.allclose(d,1.0) and d.shape[1:] == (3,3) + assert np.allclose(d,1.0) and d.shape[1:] == (3,3) def test_get_component(self,default): d = default.get('5_F') assert np.allclose(d,1.0) and d.shape[1:] == (1,) - + def test_write_read_str(self,default,tmpdir): default.to_ASCII(str(tmpdir.join('default.txt'))) new = Table.from_ASCII(str(tmpdir.join('default.txt'))) @@ -69,15 +69,20 @@ class TestTable: def test_read_strange(self,reference_dir,fname): with open(os.path.join(reference_dir,fname)) as f: Table.from_ASCII(f) - + def test_set(self,default): default.set('F',np.zeros((5,3,3)),'set to zero') d=default.get('F') assert np.allclose(d,0.0) and d.shape[1:] == (3,3) + def test_set_component(self,default): + default.set('1_F',np.zeros((5)),'set to zero') + d=default.get('F') + assert np.allclose(d[...,0,0],0.0) and d.shape[1:] == (3,3) + def test_labels(self,default): assert default.labels == ['F','v','s'] - + def test_add(self,default): d = np.random.random((5,9)) default.add('nine',d,'random data') diff --git a/python/tests/test_grid_filters.py b/python/tests/test_grid_filters.py index ab60c0446..8a343e26b 100644 --- a/python/tests/test_grid_filters.py +++ b/python/tests/test_grid_filters.py @@ -42,12 +42,25 @@ class TestGridFilters: assert np.allclose(grid_filters.node_displacement_fluct(size,F), grid_filters.cell_2_node(grid_filters.cell_displacement_fluct(size,F))) - def test_interpolation_nonperiodic(self): + def test_interpolation_to_node(self): size = np.random.random(3) grid = np.random.randint(8,32,(3)) F = np.random.random(tuple(grid)+(3,3)) - assert np.allclose(grid_filters.node_coord(size,F) [1:-1,1:-1,1:-1],grid_filters.cell_2_node( - grid_filters.cell_coord(size,F))[1:-1,1:-1,1:-1]) + assert np.allclose(grid_filters.node_coord(size,F) [1:-1,1:-1,1:-1], + grid_filters.cell_2_node(grid_filters.cell_coord(size,F))[1:-1,1:-1,1:-1]) + + def test_interpolation_to_cell(self): + grid = np.random.randint(1,30,(3)) + + node_coord_x = np.linspace(0,np.pi*2,num=grid[0]+1) + node_field_x = np.cos(node_coord_x) + node_field = np.broadcast_to(node_field_x.reshape(-1,1,1),grid+1) + + cell_coord_x = node_coord_x[:-1]+node_coord_x[1]*.5 + cell_field_x = np.interp(cell_coord_x,node_coord_x,node_field_x,period=np.pi*2.) + cell_field = np.broadcast_to(cell_field_x.reshape(-1,1,1),grid) + + assert np.allclose(cell_field,grid_filters.node_2_cell(node_field)) @pytest.mark.parametrize('mode',['cell','node']) def test_coord0_origin(self,mode):