|
1 | 1 | import numpy as np |
| 2 | +import pytest |
2 | 3 |
|
3 | 4 | from SpectrumCore import Spectrum |
4 | 5 |
|
5 | 6 |
|
6 | | -def test_instantiate(): |
7 | | - data = np.array([ |
8 | | - [5000., 0.4], |
9 | | - [5100., 0.6], |
10 | | - [5200., 0.5], |
11 | | - [5300., 0.4], |
12 | | - [5400., 0.3], |
13 | | - ]) |
| 7 | +def test_initialization(simple_data): |
| 8 | + spec = Spectrum(simple_data) |
| 9 | + assert spec is not None |
14 | 10 |
|
15 | | - spec = Spectrum(data) |
16 | | - # spec.normalize() |
17 | | - print(spec) |
| 11 | + |
| 12 | +def test_empty_initialization(): |
| 13 | + with pytest.raises(TypeError): |
| 14 | + Spectrum() |
| 15 | + |
| 16 | + |
| 17 | +def test_slicing(simple_data, spectrum): |
| 18 | + assert np.all(spectrum[1:3].data == simple_data[1:3]) |
| 19 | + |
| 20 | + |
| 21 | +def test_length(simple_data, spectrum): |
| 22 | + assert len(spectrum) == len(simple_data) |
| 23 | + |
| 24 | + |
| 25 | +def test_properties(simple_data_error, spectrum_error): |
| 26 | + assert spectrum_error.wave_start == simple_data_error[0, 0] |
| 27 | + assert spectrum_error.wave_end == simple_data_error[-1, 0] |
| 28 | + assert np.all(spectrum_error.wave == simple_data_error[:, 0]) |
| 29 | + assert np.all(spectrum_error.flux == simple_data_error[:, 1]) |
| 30 | + assert np.all(spectrum_error.error == simple_data_error[:, 2]) |
| 31 | + |
| 32 | + |
| 33 | +def test_normalize_flux(spectrum): |
| 34 | + spectrum.normalize_flux() |
| 35 | + assert spectrum.flux.max() == 1. |
| 36 | + |
| 37 | + |
| 38 | +def test_normalize_wave(spectrum): |
| 39 | + spectrum.normalize_wave() |
| 40 | + assert spectrum.wave_start == 0. |
| 41 | + assert spectrum.wave_end == 1. |
| 42 | + |
| 43 | + |
| 44 | +def test_add_flux(spectrum): |
| 45 | + old_flux = spectrum.flux.copy() |
| 46 | + added_flux = np.ones(len(spectrum)) |
| 47 | + spectrum.add_flux(added_flux) |
| 48 | + |
| 49 | + assert np.all(spectrum.flux == old_flux + added_flux) |
0 commit comments