import unittest import numpy as np from damaris.data.DamarisFFT import DamarisFFT class TestDamarisFFT(unittest.TestCase): @staticmethod def make_fft(): fft = DamarisFFT() fft.sampling_rate = 100.0 fft.x = np.arange(10, dtype="float32") / 100.0 fft.y = [np.arange(10, dtype="float32")] fft.xlabel = "Time / s" return fft def test_clip_without_arguments_is_placeholder(self): """clip() without arguments returns self unchanged (placeholder use).""" fft = self.make_fft() self.assertIs(fft.clip(), fft) self.assertEqual(len(fft.x), 10) np.testing.assert_array_equal(fft.y[0], np.arange(10, dtype="float32")) def test_clip_swaps_reversed_bounds(self): fft = self.make_fft() fft.clip(start=0.05, stop=0.01) expected_x = (np.arange(10, dtype="float32") / 100.0)[1:5] np.testing.assert_array_equal(fft.x, expected_x) np.testing.assert_array_equal(fft.y[0], np.arange(1, 5, dtype="float32")) def test_clip_single_bound(self): fft = self.make_fft() fft.clip(start=0.02) self.assertEqual(len(fft.x), 7) self.assertEqual(len(fft.y[0]), 7) def test_clip_too_close_raises(self): fft = self.make_fft() self.assertRaises(ValueError, fft.clip, 0.021, 0.029) if __name__ == "__main__": unittest.main()