@@ -715,47 +715,57 @@ def test_copy_object(do_minimal):
715715@pytest .mark .parametrize (
716716 "starting_all_arrays, scalar_to_add, expected_all_arrays" ,
717717 [
718- # Test scalar addition to xarray values (q, tth, d ) and expect no change to yarray values
719- ( # C1: Add integer of 5, expect xarray to increase by by 5
718+ # Test scalar addition to yarray values (intensity ) and expect no change to xarrays (q, tth, d)
719+ ( # C1: Add integer of 5, expect yarray to increase by by 5
720720 np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [2.0 , 1.0 , 60.0 , 6.28318531 ]]),
721721 5 ,
722- np .array ([[1 .0 , 5 .51763809 , 35 .0 , 17 .13818192 ], [2 .0 , 6 .0 , 65 .0 , 11 .28318531 ]]),
722+ np .array ([[6 .0 , 0 .51763809 , 30 .0 , 12 .13818192 ], [7 .0 , 1 .0 , 60 .0 , 6 .28318531 ]]),
723723 ),
724- ( # C2: Add float of 5.1, expect xarray to be added by 5.1
724+ ( # C2: Add float of 5.1, expect yarray to be added by 5.1
725725 np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [2.0 , 1.0 , 60.0 , 6.28318531 ]]),
726726 5.1 ,
727- np .array ([[1.0 , 5.61763809 , 35.1 , 17.23818192 ], [2.0 , 6.1 , 65.1 , 11.38318531 ]]),
727+ np .array ([[6.1 , 0.51763809 , 30.0 , 12.13818192 ], [7.1 , 1.0 , 60.0 , 6.28318531 ]]),
728728 ),
729729 ],
730730)
731731def test_addition_operator_by_scalar (starting_all_arrays , scalar_to_add , expected_all_arrays , do_minimal_tth ):
732732 do = do_minimal_tth
733733 assert np .allclose (do .all_arrays , starting_all_arrays )
734- do_sum_RHS = do + scalar_to_add
735- do_sum_LHS = scalar_to_add + do
736- assert np . allclose ( do_sum_RHS . all_arrays , expected_all_arrays )
737- assert np .allclose (do_sum_LHS .all_arrays , expected_all_arrays )
734+ do_scalar_right_sum = do + scalar_to_add
735+ assert np . allclose ( do_scalar_right_sum . all_arrays , expected_all_arrays )
736+ do_scalar_left_sum = scalar_to_add + do
737+ assert np .allclose (do_scalar_left_sum .all_arrays , expected_all_arrays )
738738
739739
740740@pytest .mark .parametrize (
741- "LHS_all_arrays, RHS_all_arrays, expected_all_arrays_sum" ,
741+ "do_1_all_arrays, "
742+ "do_2_all_arrays, "
743+ "expected_do_1_all_arrays_with_y_summed, "
744+ "expected_do_2_all_arrays_with_y_summed" ,
742745 [
743746 # Test addition of two DO objects, expect combined xarray values (q, tth, d) and no change to yarray
744- ( # C1: Add two DO objects with identical xarray values , expect sum of xarray values
747+ ( # C1: Add two DO objects, expect sum of yarray values
745748 (np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [2.0 , 1.0 , 60.0 , 6.28318531 ]]),),
746- (np .array ([[1.0 , 0.51763809 , 30.0 , 12.13818192 ], [2.0 , 1.0 , 60.0 , 6.28318531 ]]),),
747- np .array ([[1.0 , 1.03527618 , 60.0 , 24.27636384 ], [2.0 , 2.0 , 120.0 , 12.56637061 ]]),
749+ (np .array ([[1.0 , 6.28318531 , 100.70777771 , 1 ], [2.0 , 3.14159265 , 45.28748053 , 2.0 ]]),),
750+ (np .array ([[2.0 , 0.51763809 , 30.0 , 12.13818192 ], [4.0 , 1.0 , 60.0 , 6.28318531 ]]),),
751+ (np .array ([[2.0 , 6.28318531 , 100.70777771 , 1 ], [4.0 , 3.14159265 , 45.28748053 , 2.0 ]]),),
748752 ),
749753 ],
750754)
751- def test_addition_operator_by_another_do (LHS_all_arrays , RHS_all_arrays , expected_all_arrays_sum , do_minimal_tth ):
752- assert np .allclose (do_minimal_tth .all_arrays , LHS_all_arrays )
753- do_LHS = do_minimal_tth
754- do_RHS = do_minimal_tth
755- do_sum = do_LHS + do_RHS
756- assert np .allclose (do_LHS .all_arrays , LHS_all_arrays )
757- assert np .allclose (do_RHS .all_arrays , RHS_all_arrays )
758- assert np .allclose (do_sum .all_arrays , expected_all_arrays_sum )
755+ def test_addition_operator_by_another_do (
756+ do_1_all_arrays ,
757+ do_2_all_arrays ,
758+ expected_do_1_all_arrays_with_y_summed ,
759+ expected_do_2_all_arrays_with_y_summed ,
760+ do_minimal_tth ,
761+ do_minimal_d ,
762+ ):
763+ do_1 = do_minimal_tth
764+ assert np .allclose (do_1 .all_arrays , do_1_all_arrays )
765+ do_2 = do_minimal_d
766+ assert np .allclose (do_2 .all_arrays , do_2_all_arrays )
767+ assert np .allclose ((do_1 + do_2 ).all_arrays , expected_do_1_all_arrays_with_y_summed )
768+ assert np .allclose ((do_2 + do_1 ).all_arrays , expected_do_2_all_arrays_with_y_summed )
759769
760770
761771def test_addition_operator_invalid_type (do_minimal_tth , invalid_add_type_error_msg ):
@@ -767,9 +777,11 @@ def test_addition_operator_invalid_type(do_minimal_tth, invalid_add_type_error_m
767777 "string_value" + do
768778
769779
770- def test_addition_operator_invalid_xarray_length (do_minimal , do_minimal_tth , x_grid_size_mismatch_error_msg ):
780+ def test_addition_operator_invalid_yarray_length (do_minimal , do_minimal_tth , y_grid_size_mismatch_error_msg ):
771781 # Combine two DO objects, one with empty xarrays (do_minimal) and the other with non-empty xarrays
772- do_LHS = do_minimal
773- do_RHS = do_minimal_tth
774- with pytest .raises (ValueError , match = re .escape (x_grid_size_mismatch_error_msg )):
775- do_LHS + do_RHS
782+ do_1 = do_minimal
783+ do_2 = do_minimal_tth
784+ assert len (do_1 .all_arrays [:, 0 ]) == 0
785+ assert len (do_2 .all_arrays [:, 0 ]) == 2
786+ with pytest .raises (ValueError , match = re .escape (y_grid_size_mismatch_error_msg )):
787+ do_1 + do_2
0 commit comments