Skip to content

Commit

Permalink
Added Quantity tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed Dec 1, 2022
1 parent e718cf7 commit 936c516
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions specutils/tests/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 936c516

Please sign in to comment.