Skip to content

Commit

Permalink
refactor: Clean up pulse test files by adding missing imports and ren…
Browse files Browse the repository at this point in the history
…aming test files for clarity
  • Loading branch information
Akinori Machino committed Dec 30, 2024
1 parent 7415c6d commit e9ac9b4
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 64 deletions.
1 change: 1 addition & 0 deletions tests/pulse/test_blank.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import Blank, Pulse

dt = Blank.SAMPLING_PERIOD
Expand Down
1 change: 1 addition & 0 deletions tests/pulse/test_drag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import Drag, Pulse

dt = Pulse.SAMPLING_PERIOD
Expand Down
1 change: 1 addition & 0 deletions tests/pulse/test_flat_top.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import FlatTop, Pulse

dt = Pulse.SAMPLING_PERIOD
Expand Down
44 changes: 0 additions & 44 deletions tests/pulse/test_gauss.py

This file was deleted.

23 changes: 12 additions & 11 deletions tests/pulse/test_drag_gauss.py → tests/pulse/test_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import numpy as np
import pytest
from qubex.pulse import DragGauss, Pulse

from qubex.pulse import Gaussian, Pulse

dt = Pulse.SAMPLING_PERIOD


def test_inheritance():
"""DragGauss should inherit from Pulse."""
assert issubclass(DragGauss, Pulse)
"""Gaussian should inherit from Pulse."""
assert issubclass(Gaussian, Pulse)


def test_empty_init():
"""DragGauss should raise a TypeError if no duration is provided."""
"""Gaussian should raise a TypeError if no duration is provided."""
with pytest.raises(TypeError):
DragGauss() # type: ignore
Gaussian() # type: ignore


def test_init():
"""DragGauss should be initialized with valid parameters."""
pulse = DragGauss(duration=5 * dt, amplitude=1, sigma=2 * dt, beta=1)
"""Gaussian should be initialized with valid parameters."""
pulse = Gaussian(duration=5 * dt, amplitude=1, sigma=2 * dt, beta=1)
assert pulse.duration == 5 * dt
assert pulse.values == pytest.approx(
[
Expand All @@ -32,13 +33,13 @@ def test_init():


def test_zero_duration():
"""DragGauss should be initialized with zero duration."""
pulse = DragGauss(duration=0, amplitude=1, sigma=1, beta=1)
"""Gaussian should be initialized with zero duration."""
pulse = Gaussian(duration=0, amplitude=1, sigma=1, beta=1)
assert pulse.duration == 0
assert (pulse.values == np.array([], dtype=np.complex128)).all()


def test_invalid_parameter():
"""DragGauss should raise a ValueError if sigma is zero."""
"""Gaussian should raise a ValueError if sigma is zero."""
with pytest.raises(ValueError):
DragGauss(duration=5 * dt, amplitude=1, sigma=0, beta=1)
Gaussian(duration=5 * dt, amplitude=1, sigma=0, beta=1)
1 change: 1 addition & 0 deletions tests/pulse/test_phase_shift.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import PhaseShift, Pulse, PulseSequence

dt = PulseSequence.SAMPLING_PERIOD
Expand Down
1 change: 1 addition & 0 deletions tests/pulse/test_pulse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import Pulse, Waveform

dt = Pulse.SAMPLING_PERIOD
Expand Down
1 change: 1 addition & 0 deletions tests/pulse/test_pulse_sequence.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import Pulse, PulseSequence, Waveform

dt = PulseSequence.SAMPLING_PERIOD
Expand Down
19 changes: 10 additions & 9 deletions tests/pulse/test_drag_cos.py → tests/pulse/test_raised_cosine.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import numpy as np
import pytest
from qubex.pulse import DragCos, Pulse

from qubex.pulse import Pulse, RaisedCosine

dt = Pulse.SAMPLING_PERIOD


def test_inheritance():
"""DragCos should inherit from Pulse."""
assert issubclass(DragCos, Pulse)
"""RaisedCosine should inherit from Pulse."""
assert issubclass(RaisedCosine, Pulse)


def test_empty_init():
"""DragCos should raise a TypeError if no duration is provided."""
"""RaisedCosine should raise a TypeError if no duration is provided."""
with pytest.raises(TypeError):
DragCos() # type: ignore
RaisedCosine() # type: ignore


def test_init():
"""DragCos should be initialized with valid parameters."""
pulse = DragCos(duration=5 * dt, amplitude=1, beta=1)
"""RaisedCosine should be initialized with valid parameters."""
pulse = RaisedCosine(duration=5 * dt, amplitude=1, beta=1)
assert pulse.duration == 5 * dt
assert pulse.values == pytest.approx(
[
Expand All @@ -32,7 +33,7 @@ def test_init():


def test_zero_duration():
"""DragCos should be initialized with zero duration."""
pulse = DragCos(duration=0, amplitude=1, beta=1)
"""RaisedCosine should be initialized with zero duration."""
pulse = RaisedCosine(duration=0, amplitude=1, beta=1)
assert pulse.duration == 0
assert (pulse.values == np.array([], dtype=np.complex128)).all()
1 change: 1 addition & 0 deletions tests/pulse/test_rect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from qubex.pulse import Pulse, Rect

dt = Pulse.SAMPLING_PERIOD
Expand Down

0 comments on commit e9ac9b4

Please sign in to comment.