-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oscillator): #35 parse initial condition for sho
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tests/test_models/test_harmonic_oscillators/test_initial_conditions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import math | ||
|
||
import pytest | ||
|
||
from hamilflow.models.harmonic_oscillator.initial_conditions import parse_ic_for_sho | ||
|
||
|
||
@pytest.fixture() | ||
def omega() -> float: | ||
return 2 * math.pi | ||
|
||
|
||
class TestParseICForSHO: | ||
@pytest.mark.parametrize( | ||
("input", "expected"), | ||
[ | ||
( | ||
dict(x0=1.0, v0=1.0, phi=7.0), | ||
dict(x0=1.0, v0=1.0, phi=7 % (2 * math.pi)), | ||
), | ||
(dict(x0=1.0, t0=1.0), dict(x0=1.0, v0=0.0, phi=0.0)), | ||
( | ||
dict(E=1.0, t0=1.0), | ||
dict(x0=math.sqrt(2.0) / (2 * math.pi), v0=0.0, phi=0.0), | ||
), | ||
], | ||
) | ||
def test_output( | ||
self, omega: float, input: dict[str, float], expected: dict[str, float] | ||
) -> None: | ||
assert parse_ic_for_sho(omega, **input) == expected | ||
|
||
def test_raise(self, omega: float) -> None: | ||
with pytest.raises(ValueError): | ||
parse_ic_for_sho(omega, **dict(x0=1.0, E=2.0)) |