Skip to content

Commit 5da6118

Browse files
committed
Test more single-section cases
1 parent 0281ed9 commit 5da6118

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/time_of_flight/resample_tests.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,50 @@ def test_with_single_increasing_section(self):
315315
# For a single increasing section, should return just that section
316316
assert sc.identical(result, da)
317317

318+
def test_with_single_section_minimum_length(self):
319+
"""Test with a single section of the minimum length (2 points)."""
320+
tof = sc.array(dims=['tof'], values=[1, 2])
321+
data = sc.array(dims=['tof'], values=[10])
322+
da = sc.DataArray(data=data, coords={'tof': tof})
323+
324+
result = resample.rebin_strictly_increasing(da, 'tof')
325+
326+
# Should return the original section without rebinning
327+
assert sc.identical(result, da)
328+
329+
def test_with_single_section_integer_coords(self):
330+
"""Test with a single section with integer coordinates."""
331+
tof = sc.array(dims=['tof'], values=[1, 2, 3, 4], dtype=np.int32)
332+
data = sc.array(dims=['tof'], values=[10, 20, 30])
333+
da = sc.DataArray(data=data, coords={'tof': tof})
334+
335+
result = resample.rebin_strictly_increasing(da, 'tof')
336+
337+
# Should return the original section, with converted coords
338+
assert sc.identical(result, da)
339+
# Check that we're maintaining the same values even if the dtype changed
340+
assert sc.allclose(result.coords['tof'], da.coords['tof'])
341+
342+
def test_with_single_section_with_masks_and_extra_coords(self):
343+
"""Test with a single section that has masks and attributes."""
344+
tof = sc.array(dims=['tof'], values=[1, 2, 3, 4, 5])
345+
data = sc.array(dims=['tof'], values=[10, 20, 30, 40])
346+
da = sc.DataArray(data=data, coords={'tof': tof})
347+
348+
# Add mask and attribute
349+
mask = sc.array(dims=['tof'], values=[False, True, False, False])
350+
da.masks['quality'] = mask
351+
da.coords['test_attr'] = sc.scalar(42)
352+
353+
result = resample.rebin_strictly_increasing(da, 'tof')
354+
355+
# Should preserve the original data with masks and attributes
356+
assert sc.identical(result, da)
357+
assert 'quality' in result.masks
358+
assert sc.identical(result.masks['quality'], mask)
359+
assert 'test_attr' in result.coords
360+
assert sc.identical(result.coords['test_attr'], sc.scalar(42))
361+
318362
def test_with_three_increasing_sections(self):
319363
tof = sc.array(dims=['tof'], values=[1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5])
320364
data = sc.array(dims=['tof'], values=[5, 10, 6, 12, 18, 8, 14, 21, 28, 35])

0 commit comments

Comments
 (0)