-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create test_particle_in_field.py (#9)
* Create test_particle_in_field.py * Create basic working test * Add ChargedParticle test
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
output/ | ||
__pycache__/ | ||
.DS_Store | ||
.coverage |
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,40 @@ | ||
"""Tests the EMWave and ChargedParticle PhysicsModules""" | ||
|
||
import pytest | ||
from turbopy import Simulation | ||
from particle_in_field import EMWave, ChargedParticle | ||
|
||
wave_data = {"amplitude": 10, "omega": 18} | ||
particle_data = {"position": 25, "pusher": "ForwardEuler"} | ||
|
||
|
||
@pytest.fixture(name="sim_example") | ||
def fixture(): | ||
""""Creates a Simulation object to be used as the owner of an | ||
EMWave object and a ChargedParticle PhysicsModule for testing""" | ||
input_data = {"Grid": {"N": 10, "min": 20, "max": 30}, | ||
"PhysicsModules": {"EMWave": wave_data, | ||
"ChargedParticle": particle_data}, | ||
"Tools": {"ForwardEuler": {}}, | ||
"Clock": {"start_time": 0, "end_time": 1, "num_steps": 2}} | ||
sim = Simulation(input_data) | ||
sim.prepare_simulation() | ||
return sim | ||
|
||
|
||
def test_emwave(sim_example): | ||
"""Tests the EMWave PhysicsModule""" | ||
em_example = EMWave(sim_example, wave_data) | ||
assert isinstance(em_example, EMWave) | ||
assert em_example.c == 2.998e8 | ||
assert em_example.E0 == wave_data["amplitude"] | ||
assert em_example.omega == wave_data["omega"] | ||
assert em_example.k == wave_data["omega"] / 2.998e8 | ||
|
||
|
||
def test_chargedparticle(sim_example): | ||
"""Tests the ChargedParticle PhysicsModule""" | ||
charged_example = ChargedParticle(sim_example, particle_data) | ||
assert isinstance(charged_example, ChargedParticle) | ||
assert charged_example.E is None | ||
assert charged_example.x == particle_data["position"] |