diff --git a/specutils/tests/test_arithmetic.py b/specutils/tests/test_arithmetic.py index c8c416fbd..fe40944dc 100644 --- a/specutils/tests/test_arithmetic.py +++ b/specutils/tests/test_arithmetic.py @@ -86,9 +86,38 @@ def test_math_with_plain_number(self): self.spec * np.ones(self.spec.flux.shape) def test_math_with_quantity(self): - # TODO: Like plain number, but also see Jy * Jy becomes Jy**2, Jy + nJy - # TODO: Array Quantity now errors - pass + q = 1 * u.uJy # 1000 nJy + + spec_added_fwd = self.spec + q + assert_quantity_allclose(spec_added_fwd.flux, 1001 * u.nJy) + + # Quantity has its own __add__ + with pytest.raises(ValueError, match='Value not scalar compatible'): + q + self.spec + + spec_subbed_fwd = self.spec - q + assert_quantity_allclose(spec_subbed_fwd.flux, -999 * u.nJy) + + # Quantity has its own __sub__ + with pytest.raises(ValueError, match='Value not scalar compatible'): + q - self.spec + + spec_mul_fwd = self.spec * q + assert_quantity_allclose(spec_mul_fwd.flux, 1000 * (u.nJy * u.nJy)) + + # Quantity has its own __mul__ + spec_mul_bak = q * self.spec + assert isinstance(spec_mul_bak, u.Quantity) # Becomes Quantity + + spec_div = self.spec / q + assert_quantity_allclose(spec_div.flux, 0.001) + + # Quantity has its own __truediv__ + with pytest.raises(TypeError, match='unsupported operand'): + q / self.spec + + with pytest.raises(ValueError, match='Quantity must be scalar'): + self.spec * (self.spec.flux) def test_math_with_ndcube(self): from astropy.wcs import WCS