Skip to content

Commit 98429c7

Browse files
committed
Add test
1 parent 5276af9 commit 98429c7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/time_of_flight/resample_tests.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,3 +444,28 @@ def test_masks_are_applied(self):
444444
# Rebin applies masks
445445
assert 'quality' not in baseline.masks
446446
assert result.sum().value < baseline.sum().value
447+
448+
def test_uses_coord_name_as_new_dimension_name(self):
449+
"""Test with a dimension name different from the coordinate name."""
450+
# Create data array with dimension name 'd' but coordinate named 'tof'
451+
tof = sc.array(dims=['d'], values=[1, 2, 3, 2, 3, 4])
452+
data = sc.array(dims=['d'], values=[10, 20, 15, 25, 35])
453+
da = sc.DataArray(data=data, coords={'tof': tof})
454+
455+
# The dimension name 'd' is different from the coordinate name 'tof'
456+
assert da.coords['tof'].dims[0] == 'd'
457+
assert 'tof' not in da.dims
458+
459+
result = resample.rebin_strictly_increasing(da, 'tof')
460+
461+
# Check that the dimension has been renamed to match the coordinate
462+
assert 'tof' in result.dims
463+
assert result.coords['tof'].dims[0] == 'tof'
464+
465+
# Check that rebinning worked correctly
466+
expected_tof = sc.array(dims=['tof'], values=[1.0, 2.0, 3.0, 4.0])
467+
assert sc.identical(result.coords['tof'], expected_tof)
468+
469+
# Check the data values are properly rebinned and combined
470+
expected_data = sc.array(dims=['tof'], values=[10.0, 20.0 + 25.0, 35.0])
471+
assert_identical(result.data, expected_data)

0 commit comments

Comments
 (0)