77directory = path .dirname (path .realpath (__file__ ))
88
99
10- def test__has ():
10+ def test__has__linear_obj_with_regularization__returns_true ():
1111 reg = aa .m .MockRegularization ()
1212 linear_obj = aa .m .MockLinearObj (regularization = reg )
1313 inversion = aa .m .MockInversion (linear_obj_list = [linear_obj ])
1414
1515 assert inversion .has (cls = aa .AbstractRegularization ) is True
1616
17+
18+ def test__has__linear_obj_without_regularization__returns_false ():
1719 linear_obj = aa .m .MockLinearObj (regularization = None )
1820 inversion = aa .m .MockInversion (linear_obj_list = [linear_obj ])
1921
2022 assert inversion .has (cls = aa .AbstractRegularization ) is False
2123
2224
23- def test__total_regularizations ():
25+ def test__total_regularizations__one_regularized_one_unregularized__returns_one ():
2426 reg = aa .m .MockRegularization ()
2527
2628 linear_obj_0 = aa .m .MockLinearObj (regularization = reg )
@@ -30,16 +32,26 @@ def test__total_regularizations():
3032
3133 assert inversion .total_regularizations == 1
3234
35+
36+ def test__total_regularizations__both_regularized__returns_two ():
37+ reg = aa .m .MockRegularization ()
38+
39+ linear_obj_0 = aa .m .MockLinearObj (regularization = reg )
40+
3341 inversion = aa .m .MockInversion (linear_obj_list = [linear_obj_0 , linear_obj_0 ])
3442
3543 assert inversion .total_regularizations == 2
3644
45+
46+ def test__total_regularizations__none_regularized__returns_zero ():
47+ linear_obj_1 = aa .m .MockLinearObj (regularization = None )
48+
3749 inversion = aa .m .MockInversion (linear_obj_list = [linear_obj_1 , linear_obj_1 ])
3850
3951 assert inversion .total_regularizations == 0
4052
4153
42- def test__index_range_list_from ():
54+ def test__param_range_list_from__linear_obj_and_mapper__correct_ranges_per_class ():
4355 inversion = aa .m .MockInversion (
4456 linear_obj_list = [
4557 aa .m .MockLinearObj (parameters = 2 , regularization = None ),
@@ -51,7 +63,7 @@ def test__index_range_list_from():
5163 assert inversion .param_range_list_from (cls = aa .Mapper ) == [[2 , 3 ]]
5264
5365
54- def test__no_regularization_index_list ():
66+ def test__no_regularization_index_list__all_unregularized__returns_all_parameter_indices ():
5567 inversion = aa .m .MockInversion (
5668 linear_obj_list = [
5769 aa .m .MockLinearObj (parameters = 2 , regularization = None ),
@@ -61,6 +73,8 @@ def test__no_regularization_index_list():
6173
6274 assert inversion .no_regularization_index_list == [0 , 1 , 2 ]
6375
76+
77+ def test__no_regularization_index_list__mixed_regularized_and_unregularized__returns_only_unregularized_indices ():
6478 inversion = aa .m .MockInversion (
6579 linear_obj_list = [
6680 aa .m .MockMapper (parameters = 10 , regularization = aa .m .MockRegularization ()),
@@ -73,7 +87,7 @@ def test__no_regularization_index_list():
7387 assert inversion .no_regularization_index_list == [10 , 11 , 12 , 33 , 34 , 35 , 36 ]
7488
7589
76- def test__mapping_matrix ():
90+ def test__mapping_matrix__two_mappers__concatenates_mapping_matrices_horizontally ():
7791 mapper_0 = aa .m .MockMapper (mapping_matrix = np .ones ((2 , 2 )))
7892 mapper_1 = aa .m .MockMapper (mapping_matrix = 2.0 * np .ones ((2 , 3 )))
7993
@@ -215,7 +229,7 @@ def test__curvature_matrix_via_sparse_operator__includes_source_interpolation__i
215229 )
216230
217231
218- def test__curvature_reg_matrix_reduced ():
232+ def test__curvature_reg_matrix_reduced__regularized_and_unregularized__removes_unregularized_rows_cols ():
219233 curvature_reg_matrix = np .array ([[1.0 , 2.0 , 3.0 ], [4.0 , 5.0 , 6.0 ], [7.0 , 8.0 , 9.0 ]])
220234
221235 linear_obj_list = [
@@ -232,7 +246,7 @@ def test__curvature_reg_matrix_reduced():
232246 ).all ()
233247
234248
235- def test__regularization_matrix ():
249+ def test__regularization_matrix__two_regularized_mappers__assembles_block_diagonal_matrix ():
236250 reg_0 = aa .m .MockRegularization (regularization_matrix = np .ones ((2 , 2 )))
237251 reg_1 = aa .m .MockRegularization (regularization_matrix = 2.0 * np .ones ((3 , 3 )))
238252
@@ -256,7 +270,7 @@ def test__regularization_matrix():
256270 assert inversion .regularization_matrix == pytest .approx (regularization_matrix )
257271
258272
259- def test__reconstruction_reduced ():
273+ def test__reconstruction_reduced__regularized_and_unregularized__returns_only_regularized_parameters ():
260274 linear_obj_list = [
261275 aa .m .MockMapper (parameters = 2 , regularization = aa .m .MockRegularization ()),
262276 aa .m .MockLinearObj (parameters = 1 , regularization = None ),
@@ -269,7 +283,7 @@ def test__reconstruction_reduced():
269283 assert (inversion .reconstruction_reduced == np .array ([1.0 , 2.0 ])).all ()
270284
271285
272- def test__reconstruction_dict ():
286+ def test__reconstruction_dict__single_linear_obj_and_mapper__splits_reconstruction_correctly ():
273287 reconstruction = np .array ([0.0 , 1.0 , 1.0 , 1.0 ])
274288
275289 linear_obj = aa .m .MockLinearObj (parameters = 1 )
@@ -282,6 +296,8 @@ def test__reconstruction_dict():
282296 assert (inversion .reconstruction_dict [linear_obj ] == np .zeros (1 )).all ()
283297 assert (inversion .reconstruction_dict [mapper ] == np .ones (3 )).all ()
284298
299+
300+ def test__reconstruction_dict__multiple_linear_objs_and_mappers__splits_reconstruction_correctly ():
285301 reconstruction = np .array ([0.0 , 1.0 , 1.0 , 2.0 , 2.0 , 2.0 ])
286302
287303 linear_obj = aa .m .MockLinearObj (parameters = 1 )
@@ -297,7 +313,7 @@ def test__reconstruction_dict():
297313 assert (inversion .reconstruction_dict [mapper_1 ] == 2.0 * np .ones (3 )).all ()
298314
299315
300- def test__mapped_reconstructed_data_dict ():
316+ def test__mapped_reconstructed_data_dict__single_linear_obj__returns_correct_data_and_sum ():
301317 linear_obj_0 = aa .m .MockLinearObj ()
302318
303319 mapped_reconstructed_data_dict = {linear_obj_0 : np .ones (3 )}
@@ -312,6 +328,9 @@ def test__mapped_reconstructed_data_dict():
312328 assert (inversion .mapped_reconstructed_data_dict [linear_obj_0 ] == np .ones (3 )).all ()
313329 assert (inversion .mapped_reconstructed_data == np .ones (3 )).all ()
314330
331+
332+ def test__mapped_reconstructed_data_dict__two_linear_objs__sums_contributions_correctly ():
333+ linear_obj_0 = aa .m .MockLinearObj ()
315334 linear_obj_1 = aa .m .MockLinearObj ()
316335
317336 mapped_reconstructed_data_dict = {
@@ -333,7 +352,7 @@ def test__mapped_reconstructed_data_dict():
333352 assert (inversion .mapped_reconstructed_data == 3.0 * np .ones (2 )).all ()
334353
335354
336- def test__mapped_reconstructed_operated_data_dict ():
355+ def test__mapped_reconstructed_operated_data_dict__single_linear_obj__returns_correct_data_and_sum ():
337356 linear_obj_0 = aa .m .MockLinearObj ()
338357
339358 mapped_reconstructed_operated_data_dict = {linear_obj_0 : np .ones (3 )}
@@ -350,6 +369,9 @@ def test__mapped_reconstructed_operated_data_dict():
350369 ).all ()
351370 assert (inversion .mapped_reconstructed_operated_data == np .ones (3 )).all ()
352371
372+
373+ def test__mapped_reconstructed_operated_data_dict__two_linear_objs__sums_contributions_correctly ():
374+ linear_obj_0 = aa .m .MockLinearObj ()
353375 linear_obj_1 = aa .m .MockLinearObj ()
354376
355377 mapped_reconstructed_operated_data_dict = {
@@ -374,7 +396,7 @@ def test__mapped_reconstructed_operated_data_dict():
374396 assert (inversion .mapped_reconstructed_operated_data == 3.0 * np .ones (2 )).all ()
375397
376398
377- def test__mapped_reconstructed_operated_data ():
399+ def test__mapped_reconstructed_operated_data__single_linear_obj__returns_correct_operated_data ():
378400 linear_obj_0 = aa .m .MockLinearObj ()
379401
380402 mapped_reconstructed_operated_data_dict = {linear_obj_0 : np .ones (3 )}
@@ -391,6 +413,9 @@ def test__mapped_reconstructed_operated_data():
391413 ).all ()
392414 assert (inversion .mapped_reconstructed_operated_data == np .ones (3 )).all ()
393415
416+
417+ def test__mapped_reconstructed_operated_data__two_linear_objs__sums_operated_data_correctly ():
418+ linear_obj_0 = aa .m .MockLinearObj ()
394419 linear_obj_1 = aa .m .MockLinearObj ()
395420
396421 mapped_reconstructed_operated_data_dict = {
@@ -415,7 +440,7 @@ def test__mapped_reconstructed_operated_data():
415440 assert (inversion .mapped_reconstructed_operated_data == 3.0 * np .ones (2 )).all ()
416441
417442
418- def test__data_subtracted_dict ():
443+ def test__data_subtracted_dict__single_linear_obj__subtracts_other_contributions_from_data ():
419444 linear_obj_0 = aa .m .MockLinearObj ()
420445
421446 mapped_reconstructed_operated_data_dict = {linear_obj_0 : np .ones (3 )}
@@ -429,6 +454,9 @@ def test__data_subtracted_dict():
429454
430455 assert (inversion .data_subtracted_dict [linear_obj_0 ] == 3.0 * np .ones (3 )).all ()
431456
457+
458+ def test__data_subtracted_dict__two_linear_objs__subtracts_other_contributions_from_data ():
459+ linear_obj_0 = aa .m .MockLinearObj ()
432460 linear_obj_1 = aa .m .MockLinearObj ()
433461
434462 mapped_reconstructed_operated_data_dict = {
@@ -447,7 +475,7 @@ def test__data_subtracted_dict():
447475 assert (inversion .data_subtracted_dict [linear_obj_1 ] == 2.0 * np .ones (3 )).all ()
448476
449477
450- def test__regularization_term ():
478+ def test__regularization_term__identity_matrix__computes_sum_of_squared_reconstruction ():
451479 reconstruction = np .array ([1.0 , 1.0 , 1.0 ])
452480
453481 regularization_matrix = np .array (
@@ -478,6 +506,8 @@ def test__regularization_term():
478506
479507 assert inversion .regularization_term == 3.0
480508
509+
510+ def test__regularization_term__tridiagonal_matrix__computes_weighted_regularization_term ():
481511 reconstruction = np .array ([2.0 , 3.0 , 5.0 ])
482512
483513 regularization_matrix = np .array (
@@ -509,7 +539,7 @@ def test__regularization_term():
509539 assert inversion .regularization_term == 34.0
510540
511541
512- def test__determinant_of_positive_definite_matrix_via_cholesky ():
542+ def test__determinant_of_positive_definite_matrix_via_cholesky__identity_matrix__matches_numpy_log_det ():
513543 matrix = np .array ([[1.0 , 0.0 , 0.0 ], [0.0 , 1.0 , 0.0 ], [0.0 , 0.0 , 1.0 ]])
514544
515545 inversion = aa .m .MockInversion (
@@ -523,6 +553,8 @@ def test__determinant_of_positive_definite_matrix_via_cholesky():
523553 inversion .log_det_curvature_reg_matrix_term , 1e-4
524554 )
525555
556+
557+ def test__determinant_of_positive_definite_matrix_via_cholesky__tridiagonal_matrix__matches_numpy_log_det ():
526558 matrix = np .array ([[2.0 , - 1.0 , 0.0 ], [- 1.0 , 2.0 , - 1.0 ], [0.0 , - 1.0 , 2.0 ]])
527559
528560 inversion = aa .m .MockInversion (
@@ -537,7 +569,7 @@ def test__determinant_of_positive_definite_matrix_via_cholesky():
537569 )
538570
539571
540- def test__reconstruction_noise_map ():
572+ def test__reconstruction_noise_map__asymmetric_curvature_reg_matrix__correct_diagonal_noise_values ():
541573 curvature_reg_matrix = np .array ([[1.0 , 1.0 , 1.0 ], [1.0 , 2.0 , 1.0 ], [1.0 , 1.0 , 3.0 ]])
542574
543575 inversion = aa .m .MockInversion (curvature_reg_matrix = curvature_reg_matrix )
@@ -550,7 +582,7 @@ def test__reconstruction_noise_map():
550582 )
551583
552584
553- def test__max_pixel_list_from_and_centre ():
585+ def test__max_pixel_list_from_and_centre__returns_top_pixels_and_brightest_centre ():
554586
555587 source_plane_mesh_grid = aa .Grid2DIrregular (
556588 [[1.0 , 2.0 ], [3.0 , 4.0 ], [5.0 , 6.0 ], [5.0 , 0.0 ]]
@@ -581,7 +613,7 @@ def test__max_pixel_list_from_and_centre():
581613 assert inversion .max_pixel_centre ().in_list == [(5.0 , 6.0 )]
582614
583615
584- def test__max_pixel_list_from__filter_neighbors ():
616+ def test__max_pixel_list_from__filter_neighbors__excludes_adjacent_pixels_from_top_list ():
585617 source_plane_mesh_grid = aa .Grid2DIrregular (
586618 [
587619 [1.0 , 1.0 ],
0 commit comments