Skip to content

Commit

Permalink
Modified `optika.materials._tests.test_materials.AbstractTestAbstract…
Browse files Browse the repository at this point in the history
…Material.TestRayDependentMethods` to use `optika.rays._tests.test_ray_vectors.rays`
  • Loading branch information
byrdie committed Sep 9, 2023
1 parent 9a16179 commit 55d18ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
11 changes: 2 additions & 9 deletions optika/materials/_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import abc
import dataclasses
import numpy as np
import astropy.units as u
import named_arrays as na
import optika.mixins

Expand Down Expand Up @@ -112,22 +113,14 @@ def attenuation(
self,
rays: optika.rays.RayVectorArray,
) -> na.ScalarLike:
return 0
return 0 / u.mm

def transmissivity(
self,
rays: optika.rays.RayVectorArray,
) -> na.ScalarLike:
return 1

def refract_rays(
self,
rays: optika.rays.AbstractRayVectorArray,
sag: optika.sags.AbstractSag,
rulings: None | optika.rulings.AbstractRulings,
) -> optika.rays.RayVectorArray:
return rays.explicit


@dataclasses.dataclass(eq=False, repr=False)
class Mirror(
Expand Down
20 changes: 6 additions & 14 deletions optika/materials/_tests/test_materials.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import pytest
import numpy as np
import astropy.units as u
import named_arrays as na
import optika
import optika._tests.test_transforms
import optika.rays._tests.test_ray_vectors


class AbstractTestAbstractMaterial(
optika._tests.test_transforms.AbstractTestTransformable,
):
@pytest.mark.parametrize(
argnames="rays",
argvalues=[
optika.rays.RayVectorArray(
wavelength=500 * u.nm,
position=na.Cartesian3dVectorArray() * u.mm,
direction=na.Cartesian3dVectorArray(0, 0, 1),
intensity=100,
),
],
)
@pytest.mark.parametrize("rays", optika.rays._tests.test_ray_vectors.rays)
class TestRayDependentMethods:
def test_index_refraction(
self,
Expand All @@ -36,7 +28,7 @@ def test_attenuation(
):
result = a.attenuation(rays)
assert isinstance(na.as_named_array(result), na.AbstractScalar)
assert na.unit_normalized(result).is_equivalent(u.dimensionless_unscaled)
assert na.unit_normalized(result).is_equivalent(1 / u.mm)

def test_transmissivity(
self,
Expand Down Expand Up @@ -72,8 +64,8 @@ def test_refract_rays(
rulings=rulings,
)
assert isinstance(result, optika.rays.AbstractRayVectorArray)
assert result.index_refraction == a.index_refraction(rays)
assert result.attenuation == a.attenuation(rays)
assert np.all(result.index_refraction == a.index_refraction(rays))
assert np.all(result.attenuation == a.attenuation(rays))


@pytest.mark.parametrize("a", [optika.materials.Vacuum()])
Expand Down

0 comments on commit 55d18ff

Please sign in to comment.