Skip to content

Commit 99cbc55

Browse files
committed
construct_stretching_matrix
Made exception condition more robust, changed for loop iterable, specified tests raising expected exception
1 parent f6c43a8 commit 99cbc55

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

diffpy/snmf/subroutines.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def construct_stretching_matrix(components, number_of_components, number_of_sign
7373
Has dimensions `component_signal` x `number_of_signals`
7474
7575
"""
76-
if number_of_components == 0:
76+
if (number_of_components <= 0) or (len(components)) == 0:
7777
raise ValueError(f"Number of components = {number_of_components}. Number_of_components must be >= 1.")
78-
if number_of_signals == 0:
78+
if number_of_signals <= 0:
7979
raise ValueError(f"Number of signals = {number_of_signals}. Number_of_signals must be >= 1.")
8080
stretching_factor_matrix = np.zeros((number_of_components, number_of_signals))
81-
for c in components:
82-
stretching_factor_matrix[c.id, :] = c.stretching_factors
81+
for i, component in enumerate(components):
82+
stretching_factor_matrix[i, :] = component.stretching_factors
8383
return stretching_factor_matrix
8484

8585

diffpy/snmf/tests/test_subroutines.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,19 @@ def test_initialize_components(tcc):
165165

166166
tcso =[([ComponentSignal([0,.5,1,1.5],20,0)],1,20),
167167
([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
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
172172
([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,1.5],20,1)],2,20),
173173
([ComponentSignal([0,.5,1,1.5],20,0),ComponentSignal([0,.5,1,21.5],20,1)],2,20),
174174
([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),
176-
([],1,20),
177-
([],-1,20),
178-
([],0,20), # Raises an exception
179-
([],1,0), #Raises an exception
180-
([],-1,-2),
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.
181181

182182
]
183183
@pytest.mark.parametrize('tcso',tcso)

0 commit comments

Comments
 (0)