Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/cs xyz input surface factory #34

Merged
merged 12 commits into from
Jan 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add unit tests for OffsetRadialAperture class methods
HarrisonKramer committed Jan 11, 2025
commit 58e5ede63865e3008d5097b8a190c351a7080ef9
59 changes: 59 additions & 0 deletions tests/test_physical_apertures.py
Original file line number Diff line number Diff line change
@@ -42,3 +42,62 @@ def test_from_dict(self):
assert aperture.r_max == 5
assert aperture.r_min == 2
assert isinstance(aperture, physical_apertures.RadialAperture)


class TestOffsetRadialAperture:
def test_clip(self):
aperture = physical_apertures.OffsetRadialAperture(
r_max=5, r_min=2, offset_x=1, offset_y=1
)
rays = RealRays([0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5],
[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1])
aperture.clip(rays)
assert np.all(rays.i == [0, 0, 0, 1, 1, 0])

def test_scale(self):
aperture = physical_apertures.OffsetRadialAperture(
r_max=5, r_min=2, offset_x=1, offset_y=1
)
aperture.scale(2)
assert aperture.r_max == 10
assert aperture.r_min == 4
assert aperture.offset_x == 2
assert aperture.offset_y == 2

aperture = physical_apertures.OffsetRadialAperture(
r_max=5, r_min=2, offset_x=1, offset_y=1
)
aperture.scale(0.5)
assert aperture.r_max == 2.5
assert aperture.r_min == 1
assert aperture.offset_x == 0.5
assert aperture.offset_y == 0.5

def test_to_dict(self):
aperture = physical_apertures.OffsetRadialAperture(
r_max=5, r_min=2, offset_x=1, offset_y=1
)
assert aperture.to_dict() == {
'type': 'OffsetRadialAperture',
'r_max': 5,
'r_min': 2,
'offset_x': 1,
'offset_y': 1
}

def test_from_dict(self):
data = {
'type': 'OffsetRadialAperture',
'r_max': 5,
'r_min': 2,
'offset_x': 1,
'offset_y': 1
}
aperture = physical_apertures.OffsetRadialAperture.from_dict(data)
assert aperture.r_max == 5
assert aperture.r_min == 2
assert aperture.offset_x == 1
assert aperture.offset_y == 1
assert isinstance(aperture, physical_apertures.OffsetRadialAperture)