|
1 | 1 | import pytest |
2 | 2 | import numpy as np |
| 3 | +from diffpy.snmf.containers import ComponentSignal |
3 | 4 | from diffpy.snmf.subroutines import objective_function, get_stretched_component, reconstruct_data, get_residual_matrix, \ |
4 | | - update_weights_matrix, initialize_arrays, lift_data, initialize_components |
| 5 | + update_weights_matrix, initialize_arrays, lift_data, initialize_components, construct_stretching_matrix |
5 | 6 |
|
6 | 7 | to = [ |
7 | 8 | ([[[1, 2], [3, 4]], [[5, 6], [7, 8]], 1e11, [[1, 2], [3, 4]], [[1, 2], [3, 4]], 1], 2.574e14), |
@@ -161,3 +162,27 @@ def test_initialize_components(tcc): |
161 | 162 | assert len(actual) == tcc[0] |
162 | 163 | assert len(actual[0].weights) == tcc[1] |
163 | 164 | assert (actual[0].grid == np.array(tcc[2])).all() |
| 165 | + |
| 166 | +tcso =[([ComponentSignal([0,.5,1,1.5],20,0)],1,20), |
| 167 | + ([ComponentSignal([0,.5,1,1.5],20,0)],4,20), |
| 168 | + # ([ComponentSignal([0,.5,1,1.5],20,0)],0,20), # Raises an exception |
| 169 | + # ([ComponentSignal([0,.5,1,1.5],20,0)],-2,20), # Raises an exception |
| 170 | + # ([ComponentSignal([0,.5,1,1.5],20,0)],1,0), # Raises an Exception |
| 171 | + # ([ComponentSignal([0,.5,1,1.5],20,0)],1,-3), # Raises an exception |
| 172 | + ([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,1.5],20,1)],2,20), |
| 173 | + ([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,21.5],20,1)],2,20), |
| 174 | + ([ComponentSignal([0,1,1.5],20,0),ComponentSignal([0,.5,1,21.5],20,1)],2,20), |
| 175 | + # ([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,1.5],20,1)],1,-3), # Negative signal length. Raises an exception |
| 176 | + #([],1,20), # Empty components. Raises an Exception |
| 177 | + #([],-1,20), # Empty components with negative number of components. Raises an exception |
| 178 | + #([],0,20), # Empty components with zero number of components. Raises an exception |
| 179 | + #([],1,0), # Empty components with zero signal length. Raises an exception. |
| 180 | + #([],-1,-2), # Empty components with negative number of components and signal length Raises an exception. |
| 181 | + |
| 182 | +] |
| 183 | +@pytest.mark.parametrize('tcso',tcso) |
| 184 | +def test_construct_stretching_matrix(tcso): |
| 185 | + actual = construct_stretching_matrix(tcso[0],tcso[1],tcso[2]) |
| 186 | + for component in tcso[0]: |
| 187 | + np.testing.assert_allclose(actual[component.id,:], component.stretching_factors) |
| 188 | + #assert actual[component.id, :] == component.stretching_factors |
0 commit comments