diff --git a/tests/unit/tools/simulate/test_generate_synthetic_imzml.py b/tests/unit/tools/simulate/test_generate_synthetic_imzml.py index 2d6a472..7bdc4cc 100644 --- a/tests/unit/tools/simulate/test_generate_synthetic_imzml.py +++ b/tests/unit/tools/simulate/test_generate_synthetic_imzml.py @@ -58,5 +58,45 @@ def test_get_shifted_target_masses(mock_rng, generate_synthetic_imzml): mock_rng.normal.assert_called_once_with(scale=0.001, size=(3,)) +def test_generate_centroided_spectrum_output_shape(generate_synthetic_imzml, mocker): + target_masses = np.array([1000.0, 1500.0, 2000.0]) + target_intensities = np.array([100.0, 200.0, 150.0]) + + mock_generate_isotopic_peaks = mocker.patch.object( + generate_synthetic_imzml, "_generate_isotopic_peaks", return_value=(target_masses, target_intensities) + ) + mock_generate_noise_peaks = mocker.patch.object( + generate_synthetic_imzml, + "_generate_noise_peaks", + return_value=(np.array([900.0, 1200.0]), np.array([50.0, 75.0])), + ) + + mz_arr, int_arr = generate_synthetic_imzml.generate_centroided_spectrum(target_masses, target_intensities) + + assert mz_arr.shape == int_arr.shape + assert len(mz_arr) == 5 + + mock_generate_noise_peaks.assert_called_once_with(n=1600, target_mz=target_masses, target_min_distance_mz=0.5) + mock_generate_isotopic_peaks.assert_called_once_with(mz_arr=target_masses, int_arr=target_intensities, n_isotopes=3) + + +def test_generate_centroided_spectrum_sorting(generate_synthetic_imzml, mocker): + target_masses = np.array([1500.0, 1000.0, 2000.0]) + target_intensities = np.array([200.0, 100.0, 150.0]) + + mocker.patch.object( + generate_synthetic_imzml, "_generate_isotopic_peaks", return_value=(target_masses, target_intensities) + ) + mocker.patch.object( + generate_synthetic_imzml, + "_generate_noise_peaks", + return_value=(np.array([900.0, 1200.0]), np.array([50.0, 75.0])), + ) + + mz_arr, int_arr = generate_synthetic_imzml.generate_centroided_spectrum(target_masses, target_intensities) + + assert np.all(np.diff(mz_arr) > 0) + + if __name__ == "__main__": pytest.main([__file__])