Skip to content

Commit

Permalink
add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Aug 15, 2024
1 parent 7f35ffd commit 1759d61
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/unit/tools/simulate/test_generate_synthetic_imzml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__])

0 comments on commit 1759d61

Please sign in to comment.