|
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), |
@@ -162,6 +163,25 @@ def test_initialize_components(tcc): |
162 | 163 | assert len(actual[0].weights) == tcc[1] |
163 | 164 | assert (actual[0].grid == np.array(tcc[2])).all() |
164 | 165 |
|
165 | | -tcso =[] |
166 | | -def test_construct_stretching_matrix(): |
167 | | - assert False |
| 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), |
| 169 | + ([ComponentSignal([0,.5,1,1.5],20,0)],-2,20), |
| 170 | + ([ComponentSignal([0,.5,1,1.5],20,0)],1,0), |
| 171 | + ([ComponentSignal([0,.5,1,1.5],20,0)],1,-3), |
| 172 | + ([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,1.5],20,1)],1,20), |
| 173 | + ([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,21.5],20,1)],1,20), |
| 174 | + ([ComponentSignal([0,1,1.5],20,0),ComponentSignal([0,.5,1,21.5],20,1)],1,20), |
| 175 | + ([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,1.5],20,1)],1,-3), |
| 176 | + ([],1,20), |
| 177 | + ([],-1,20), |
| 178 | + ([],0,20), |
| 179 | + ([],1,0), |
| 180 | + ([],-1,-2), |
| 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 | + assert actual[component.id, :] == component.stretching_factors |
0 commit comments